I’m creating a plugin that needs to be configured before using. I’ve created a standar EditorWindow with the configuration parameters, that works correctly, but it would be nice to create a settings windows that shows in the Inspector, like the settings windows of Unity3D itself; for example, a window like the one that shows up when you click in Edit/Project Settings/Editor menu item (attached screenshot)!
[20906-unity3d+inspector+sshot.png|20906]
To get an inspector window like those of the Unity Editor, you will have to make your settings-object a ScriptableObject, then make a custom inspector for that class.
I feel these code snippets will convey more than several paragraphs of explanation:
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(Settings))]
public class SettingEditor : Editor {
private Settings _target;
[MenuItem("testt/testtt")]
public static void Getter(){
/*
** You would naturally get the existing Settings rather
** than create a new one. E.g. using
** Resources.FindObjectsOfTypeAll or
** a manager that maintains a reference
*/
Selection.activeObject = ScriptableObject.CreateInstance<Settings>();
}
void OnEnable(){
_target = (Settings)target;
}
public override void OnInspectorGUI ()
{
_target.settingsValue = EditorGUILayout.IntField("Setting 1",_target.settingsValue);
}
}
using UnityEngine;
public class Settings : ScriptableObject {
public int settingsValue;
}
// Add menu item named "My Window" to the Window menu
[MenuItem("Window/My Window")]
public static void ShowWindow()
{
//Show existing window instance. If one doesn't exist, make one.
EditorWindow.GetWindow(typeof(MyWindow));
}
This will put your window in Window>My Window, and you can define what is in your window using OnGUI()