You need to have Unity versions 2018.2b or 2017.4:
You need to create a default project and add a new C# script.
The script I used is named EditorWindowTest.
This is the source code of this script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | using System.Collections; using System.Collections.Generic; using UnityEngine; // you need to add the UnityEditor using UnityEditor; public class EditorWindowTest : EditorWindow { // massage to show private const string help_nameobj = "Enter the name of object to observe!"; // zero point for vector position private Vector3 location = Vector3.zero; // var name for my object private string observedName = ""; // add menu Tool - Test_Editor [MenuItem("Tools/Test_Editor")] // Use this for initialization public static void CreateMyEditorCode() { // create editor window EditorWindow.GetWindow<EditorWindowTest>(); } public void OnGUI() { // this part will use a observedName = EditorGUILayout.TextField("Name", observedName); // find object GameObject foundObject = GameObject.Find(observedName); // if foundObject get location if (foundObject) { foundObject.transform.position = EditorGUILayout.Vector3Field("Location", foundObject.transform.position); } else { // show a message EditorGUILayout.HelpBox(help_nameobj, MessageType.Info); } // use location into window editor location = EditorGUILayout.Vector3Field("Location", location); // test the button if (GUILayout.Button("Show debug log text")) { // show into debug the text: Worked Debug.Log("Worked!"); } } } |
This custom editor in Unity can be used for many issues.
Here is the result of my code: