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 John-LZG · Feb 19, 2014 at 12:31 AM · custom-inspectorcustom-editor

Draw PropertyDrawers in PropertyDrawers?

I have a Profile Class which right now has no custom editor. it holds a List. SkillGroup holds List and some stuff. Skill has some stuff (ints, enums)

Now I followed these tutorials to build a custom inspector for my skill, easy. Then by making my skillgroup into a monobehaviour, I was able to make a CustomEditor for it and had it draw the list of skills using their PropertyDrawer. Great. Now, SkillGroup shouldn't be a monobehaviour, and I want the customEditor to be for Profile, drawing all the skillgroups and skills and whatnot. So I'm trying to make a SkillGroup CustomDrawer, but I can't seem to draw the skill customDrawers. Here's what I got.

 [CustomPropertyDrawer(typeof(SkillGroup))]
 public class SkillGroupDrawer : PropertyDrawer
 {
     public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
     {
         int lines = property.FindPropertyRelative("Skills").arraySize;
         return 16f + 18f + 18f + (18f * lines);
     }
 
     public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
     {
         int indent = EditorGUI.indentLevel;
         label = EditorGUI.BeginProperty(position, label, property);//tells the label this is a property, so stuff should have proper content menu
         position.height = 16f;
         //name
         EditorGUI.PropertyField(position, property.FindPropertyRelative("Name"), GUIContent.none);
         //skill label
         position.y += position.height;
         SerializedProperty list = property.FindPropertyRelative("Skills");
         EditorGUI.PropertyField(position, list);//Draws foldout, array name
         //size label
         position.y += position.height;
         SerializedProperty size = list.FindPropertyRelative("Array.size");//shows "special relative path" for Array.size, stores property        
         EditorGUI.PropertyField(position, size);//draw size field as serializesProperty
         //items
         EditorGUI.indentLevel++;
         for (int i = 0; i<list.arraySize; i++)//foreach item in list.array
         {
             position.y += position.height;
             //THIS NEXT LINE SHOULD DRAW THE PROPERTYDRAWER!
             EditorGUI.PropertyField(position, list.GetArrayElementAtIndex(i));//draw the item in the array
         }
         EditorGUI.indentLevel--;
         EditorGUI.EndProperty();
         EditorGUI.indentLevel = indent;//reset indent
     }
 }

end result should be:

  • ProfileEditor

  • profileName

  • add'l profile info

  • SkillGroups

    • skillGroupDrawer

    • GroupName

    • Skills
      • size

      • skillDrawer

      • skilldrawer

      • skilldrawer

    • skillGroupDrawer

    • GroupName

    • Skills
      • size

      • skillDrawer

      • skilldrawer

      • skilldrawer

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

18 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

Related Questions

Custom Editor: Weird reset when clicking Play 1 Answer

Editor randomly unparents game object after InstantiatePrefab() & SetParent() in OnInspectorGUI() 0 Answers

Cloud recognition in Vuforia 0 Answers

Create Spells through classes in custom editor? 1 Answer

Initializing 2D array via inspector 3 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