Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved [Editor scripting] Display button on Scene

Discussion in 'Scripting' started by InnerCoder, Mar 22, 2022.

  1. InnerCoder

    InnerCoder

    Joined:
    Nov 16, 2020
    Posts:
    15
    Hello,

    I work with two scenes named A and B. When I'm working on B and only B (when the scene is loaded by double-clicking the asset, or when Unity starts with this scene opened...), I want a UI button to be displayed on the scene view (as the coordinates helper is displayed).

    I can display the button... but I have to click on a component that has a Custom Editor or to click on a menu. I don't want to have to click something; I want the button already displayed, and displayed anytime I'm working on scene B.

    upload_2022-3-22_17-43-46.png

    Is it possible to do such a thing?

    My Unity version is 2020.3.15f2.

    Here is an example of a Custom editor for a component script.

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEditor;
    6.  
    7. [CustomEditor(typeof(MyScript))]
    8. public class MyScriptEditor : Editor
    9. {
    10.     private void OnSceneGUI()
    11.     {
    12.         Handles.BeginGUI();
    13.         GUILayout.Button("I'm the button", GUILayout.Width(200));
    14.         Handles.EndGUI();
    15.     }
    16. }
    17.  
    Thank you for your help
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,762
    ProBuilder does it but they do require their ProBuilder window to be open for this feature to work.

    Download it from the Package Mangler and check it out... all the source is included.
     
    Last edited: Mar 23, 2022
    InnerCoder likes this.
  3. InnerCoder

    InnerCoder

    Joined:
    Nov 16, 2020
    Posts:
    15
    Kurt-Dekker likes this.