Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 AnC_CN · Sep 20, 2017 at 02:22 PM · unity 5listunityeditorserializedproperty

ReorderableList always show all element. How to hide some element ?

UnityEditorInternal.ReorderableList this is useful in Editor to display Array. But i have a problem when want to display element a part of SerializedProperty(isArray). Sometime, i have a large list,but i need to edit the a part of list (may be only several element), so i do not to display all element of the list. I try to look up API and other infomation,but i don't get solution to the problem. so, i test to use remove should not to display element and DoLayoutList() again. then add remove data agins,you know if i remove from SerializedProperty the data will lose. the result is fine. the Code like below:

 List<string> cache = new List<string>();
     //get not display element to cache.
     for (int i = 10; i < mySerializedProperty.arraySize; ++i)
     {
         cache.Add(mySerializedProperty.GetArrayElementAtIndex(i).stringValue);
     }
     //remove not display element from SerializedProperty array
     for (int i = 10; i < mySerializedProperty.arraySize; ++i)
     {
         mySerializedProperty.DeleteArrayElementAtIndex(i);
     }
     //Refresh
     _injectionTypeReorderableList.DoLayoutList();
     //Add SerializedProperty array size and assign from cache to SerializedProperty array element.
     for (int i = 0; i < cache.Count; ++i)
     {
         mySerializedProperty.arraySize++;
         mySerializedProperty.GetArrayElementAtIndex(mySerializedProperty.arraySize - 1).stringValue = cache[i];
     }

However,as you can see, this way not good, it need remove and add again.if i have large element need to hide and show when at the right time, this way will be nightmare. the ReorderableList have other good way to handle this problem ?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AnC_CN · Sep 21, 2017 at 06:46 PM

I find answer with mix reflection and SerializedProperty First need separate display list and actual SerializedProperty. Then, you need to create display list copy from SerializedProperty(is array ). Because the reason of :

1.add to cache list

2.remove from SerializedProperty(is array ).

3.refresh

4.add data from cache list to SerializedProperty(is array ).

this way will remove data from array(at step 2) and add data( at step 4) one more time. So we need to create display list copy from SerializedProperty(is array ) only to display. the display list remove and add not affect SerializedProperty(is array ).only change value will be save.

In general,have 3 ways,1. like above; 2. directly use actual class type; 3. by reflection

when created display list: revalue ReorderableList. the code like below:

  protected void RefreshReorderableList()
     {
         HashSet<int> hideElement = new HashSet<int>() { 1, 2, 3, 4 };
         List<SerializedProperty> displayList = new List<SerializedProperty>();
         for (int i = 0; i < hideElement.Count; ++i)
         {
             if (hideElement.Contains(i))
                 continue;
             displayList.Add(_luaInjectionDataList.GetArrayElementAtIndex(i));
         }
         //Now we had a display list and the list add and remove not affect source SerializedProperty.
             _reorderableList.list = displayList;
             _reorderableList.DoLayoutList();
         }
 
     }

And now Step below:

1.create display list

2.refresh

Because display list not affect source serializedProperty, And display list element is ref of serializedProperty element, so the change of element content in display list will be save too.

However, this is trouble too. That is you need to define custom Add,Remove delegate and so on, for correct change source serializedProperty when display list remove,add. I think may be have another way.

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

140 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 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 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 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 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 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 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

Unity Editor SerializedProperty how to assign to array with larger data directly. 1 Answer

A node in a childnode? 1 Answer

when i build run for IOS then it shows error 0 Answers

PlayerPrefs not saving on Windows Devices but saving on Unity Editor and Android. 0 Answers

Hide GUI objects when going to the scene 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