Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by RickyAh · Jan 21, 2014 at 01:32 PM · inspectoreditor-scripting

How to create an inspector settings window?

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)! editor settings windows as shown in the Inspector

Any idea how to implement this?

unity3d inspector sshot.png (18.1 kB)
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image OperationDogBird · Jan 21, 2014 at 01:42 PM 0
Share

It is a general Editor Window. The labels use EditorStyles.boldLabel, a 2 popups and an input text field.

avatar image RickyAh · Jan 21, 2014 at 01:53 PM 0
Share

And how can you dock it into the Inspector? I mean, the inspector itself is a dockable window which changes contents depending on the selected item, ok. So how can I mimic the behavior of any of the Project Settings menu items? When I click any of those items, the inspector gets focused and shows the controls needed to configure each specific item.

avatar image OperationDogBird · Jan 21, 2014 at 01:57 PM 0
Share

The normal object inspector changes based on selection. This is done using a custom Editor (not window) for that object type. If you want to update your window on selection change, there is a built in message, plus other messages to handle basic window events. Editor Windows do not get mouse events, an Editor will.

avatar image RickyAh · Jan 21, 2014 at 02:02 PM 0
Share

Thanks @OperationDogBird, I'll dive in the documentation of Custom Editors then.

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Jamora · Jan 21, 2014 at 02:32 PM

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;
 }
 
 
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
-1

Answer by MakinStuffLookGood · Jan 21, 2014 at 01:38 PM

You'll probably want to refer to this page from the docs: http://docs.unity3d.com/Documentation/Components/editor-EditorWindows.html

Specifically this snippet here:

 // 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()

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RickyAh · Jan 21, 2014 at 01:49 PM 0
Share

Thanks, I've already created a window, but is a dockable Unity3D window. I'm looking how to create an inspector window or how to embed a EditorWindow so it shows in the inspector.

avatar image
-1

Answer by OperationDogBird · Jan 21, 2014 at 01:54 PM

 using UnityEditor;
 using UnityEngine;

 public class Settings : EditorWindow
 {
     private int selected = 0;
     private string[] opts = new string[] { "Option1", "Option2" };
     private static Settings settings = null;

     void OnGUI()
     {
         GUILayout.Label("Version Control", EditorStyles.boldLabel,GUILayout.MinWidth(100));

         GUILayout.BeginHorizontal();
         GUILayout.Label("Mode", EditorStyles.boldLabel, GUILayout.MinWidth(100));
         selected = EditorGUILayout.Popup(selected, opts);
         GUILayout.EndHorizontal();
     }

     [MenuItem("Edit/My Tool/Settings")]
     static void GetWindow()
     {
         settings = GetWindow<Settings>();
     }
 }

This will create a window with a label and a popup menu. The window is dock-able, so it is exactly like any other window in unitys editor.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

SerializedProperty and character arrays 0 Answers

Change the target of inspector from script 0 Answers

Create inspector drop-down button based on the content of a list in editor mode 1 Answer

how to write edit time only logic ? 0 Answers

Editor scripting: Object reference not set to an instance of an object 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges