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
0
Question by frogtamer · Nov 01, 2013 at 09:23 PM · inspectorclassescustom

Custom inspector: uniformly display all instances of a custom class

I had the hardest time summarizing my question, so apologies for the vague title.

Basically I've created a custom class and I'd like to display all instances of it in the inspector. I can do this manually for each instance of the class, but doing so would be painfully redundant...

More specifically, my custom class contains some of the following code:

public class Base {

  [System.Serializable]
  public class Parameter {
       public string uiName;
       public string uiDescription;
       public float val;

       public Parameter (string _uiName, string _uiDescription, float _val) {
            uiName = _uiName;
            uiDescription = _uiDescription;
            val = _val;
       }
  }

  public Parameter parameter = new Parameter("Name", "This is a description", 10f);

}

And in my custom inspector:

Base b = (Base)target;
GUIContent parameter = new GUIContent(b.parameter.name, b.parameter.description);
b.parameter.value = EditorGUILayout.FloatField(parameter, b.parameter.value);

Comment
Add comment · Show 1
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 Jamora · Nov 01, 2013 at 10:07 PM 0
Share

Is there a particular reason you need a custom inspector? Unity automatically shows any public Serializable class (the parameter variable) as a foldout in the inspector. That is, assu$$anonymous$$g Base is a $$anonymous$$onoBehaviour class...

2 Replies

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

Answer by frogtamer · Nov 01, 2013 at 11:37 PM

Ok after some more research it looks like PropertyDrawers accomplish what I want to do. I did have to move the Parameter class out of the Base class though.

 using UnityEngine;
 using UnityEditor;
 
 [CustomPropertyDrawer(typeof(Parameter))]
 public class ParameterDrawer : PropertyDrawer {
 
     public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) {
         
         EditorGUI.BeginProperty (position, label, property);
         
         // Label
         label.text = property.FindPropertyRelative("uiName").stringValue;
         label.tooltip = property.FindPropertyRelative("uiDescription").stringValue;
         position = EditorGUI.PrefixLabel (position, GUIUtility.GetControlID (FocusType.Passive), label);
         
         // Draw fields
         Rect valRect = new Rect (position.x, position.y, 50, position.height);
         EditorGUI.PropertyField (valRect, property.FindPropertyRelative("val"), GUIContent.none);
         
         EditorGUI.EndProperty ();
         
     }
     
 }
 
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
0

Answer by mbivol10 · Dec 10, 2013 at 03:54 PM

http://answers.unity3d.com/questions/592860/how-do-i-equip-items-into-a-playerprefab-of-a-guib.html

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

17 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

Related Questions

How can I create a list of preset class/objects to be used in the editor 1 Answer

How do you get the default inspector to draw for Prefabs ? 2 Answers

Can a GameObject's full inspector be drawn in a custom Editor Window ? 1 Answer

Editor GUI: Object preview icon 2 Answers

Questions Regarding Images in Custom Inspector/Editor 1 Answer


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