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 /
This question was closed Jul 30, 2013 at 02:59 PM by Immanuel-Scholz for the following reason:

Duplicate Question of http://answers.unity3d.com/questions/389986/expandable-property-with-propertydrawer.html

avatar image
3
Question by Immanuel-Scholz · Jul 30, 2013 at 02:35 PM · editorpropertydrawer

Statefull PropertyDrawer

Is there a way to have an PropertyDrawer in Unity 4.2 that has an serialized state?

For example, I try to make a custom PropertyDrawer that contains a simple Foldout. My first approach of just storing a member variable in the PropertyDrawer failed for two reasons: First the same drawer instance is shared between all drawers of the inspector (means, if I unfold one property, ALL are unfolded). And second, the bool is not persisted and reset on every assembly reload.

Example code:

 [Serializable]
 class Example
 {
     public string bla;
     public string blub;
 }
 [CustomPropertyDrawer(typeof(Example))]
 public class Example : PropertyDrawer
 {
     bool foldout;
     public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
     {
         position.height = 16;
         if (foldout = EditorGUI.Foldout(position, foldout, new GUIContent(property.FindPropertyRelative("bla").stringValue)))
         {
             position.y += 16;
             EditorGUI.LabelField(position, new GUIContent(property.FindPropertyRelative("blub").stringValue));
         }
     }
     public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
     { return foldout ? 32 : 16; }
 }

Of course, I could put the "bool foldout" into the class Example, but I rather like to separate Editor-GUI stuff from my game data.

Is there any way of having a PropertyDrawer that holds some meta information without putting this information in the inspected type itself?

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

  • Sort: 

Follow this Question

Answers Answers and Comments

15 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

Related Questions

Using DuplicateCommand and DeleteCommand with Properties 0 Answers

Select a readonly value from dropdown using PropertyDrawers 0 Answers

Creating a PropertyDrawer for a fixed size int array 1 Answer

(Solution) - Can't use GUILayout stuff in PropertyDrawer.OnGUI? 2 Answers

SerializedProperty with children class fields 2 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