[Unity3d] Custom Editor Menu and Window Sample
(Following file must be in "Editor" folder under the "Assets" folder)
using UnityEditor;
using UnityEngine;
public class MyWindow : EditorWindow
{
string myString = "Hello World";
bool groupEnabled;
bool myBool = true;
float myFloat = 1.23f;
GameObject myGameObject;
// Add menu item named "My Window" to the Window menu
[MenuItem("CustomWindow/My Window")]
public static void ShowWindow()
{
//Show existing window instance. If one doesn't exist, make one.
EditorWindow.GetWindow(typeof(MyWindow));
}
void OnGUI()
{
GUILayout.Label("Base Settings", EditorStyles.boldLabel);
myString = EditorGUILayout.TextField("Text Field", myString);
groupEnabled = EditorGUILayout.BeginToggleGroup("Optional Settings", groupEnabled);
myBool = EditorGUILayout.Toggle("Toggle", myBool);
myFloat = EditorGUILayout.Slider("Slider", myFloat, -3, 3);
EditorGUILayout.EndToggleGroup();
GUILayout.Label("This is Label", new GUILayoutOption[0]);
myGameObject = (GameObject)EditorGUILayout.ObjectField("Target", myGameObject, typeof(GameObject), true, new GUILayoutOption[0]);
}
}