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 Srki94 · Oct 15, 2014 at 04:11 AM · for-loopeditorguifoldout

Foldout loop structure problems

Greetings community !

I wrote code that draws tons of foldouts, depending on Data file information it reads. Once user clicks and expands an foldout I draw even more controls that read even more data ! That works perfectly!

Problem comes in nature of my for loop and the way you check is an foldout expanded.

Let's take a look, shall we ? :)

 for (var xy : int =0; xy <=2; xy++){
 
 if (i >= l_Array.Length){
 break;
 }
         
             t_ListFoldouts[xy] = EditorGUILayout.Foldout(t_ListFoldouts[xy], l_Array[i]);
             
             if (t_ListFoldouts[xy]){
                     
                 l_Array[i] = EditorGUILayout.TextField("Sub Entry1 :", l_Array[i]);
                 i++;
                          
                  l_Array[i] = EditorGUILayout.TextField("Sub Entry 2", l_Array[i]);
                  i++;
                      
                  l_Array[i] = EditorGUILayout.TextField("Sub Entry 3", l_Array[i]);
                  var tmpInt : int = parseInt(l_Array[i]);
                  i++;
                  
                          for (var c = 0; c <= tmpInt-1; c++){
                                  l_Array[i] = EditorGUILayout.TextField("Sub Entry 4", l_Array[i]);
                                  i++;
                                      
                                  l_Array[i] = EditorGUILayout.TextField("Sub Entry 5", l_Array[i]);
                                  i++;
                                      
                              }
                 
                  
             }
             
             
                 
     
 }

So where is the problem ?

Anything bellow this IF statement :

 if (t_ListFoldouts[xy]){
 // Code
 }

... logically only gets executed if bool is true. In order for bool to be true, user has to expand Foldout.

That doesn't fit my needs as I write ID of entry in foldout and because of that code all foldouts are the same until user expands each one of them.

Solution to this is to expand all foldouts, but that's not what I'm after, I want to keep ability to expand them by wish.

Is there some way around this ?

Regards.

Comment
Add comment · Show 2
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 Bunny83 · Oct 15, 2014 at 05:07 AM 1
Share

Uhm, this is pure chaos... Is it possible that your "`l_Array`" is a flattened array of some sort? This doesn't make much sense, especially that you use parts of the array to describe how much has to follow. Such a layout can very easily corrupt all your data. Is it possible to describe more what exactly you want to do and what kind of "data" this l_Array actually contains? Is that data in any special format? I guess you read those strings from a file?

Have you realized that when you collapse the foldout you're no longer increasing your "i" value. To get the same i for the next foldout you would need to increase i manually by the same amount it would have been increased when the foldout was visible.

Also have you realized that when the user edits this "Sub Entry 3" you change how many following lines are displayed within the same foldout. That would shift all data the comes next. Again this doesn't make any sense, so please explain what's the point of all this.

avatar image Srki94 · Oct 15, 2014 at 05:42 AM 0
Share

Hi Bunny83, thanks for sparing some time.

  1. l_Array is strictly formated array of Strings. I read data from storage to it, I format that data. Data is always in same format because I also write strictly in that format to file.

There is no fear of corruption there.

Yes, I'm aware that code wont run if foldout is not expanded. That is exactly what I'm trying to change.

Finally, - yes I'm aware that user can change that field, he wont be able to, this information will most likely be read-only, even though it's not the case in code. I'm aware of what this code does and how it does it.

What I'm trying to achieve is this :

I have formated storage file that has data in this order :

int - An ID value

String - Simple string value

int - int value that declares how many additional sub items there are

String - an string value of first sub item

int - an int value of first sub item

I'm reading this data into i_Array of Strings. I format this data additionally to make sure there wont be any problems with converting it later.

And finally, I'm trying to show this data in editor using foldout.

An example of how foldout should look :

^ Foldout - first ID int value

sub foldout 1 - ID int value again

sub foldout 2 - String

sub foldout 3 - int (the one that decides how many sub items are there)

sub foldout 4 - String

sub foldout 5 - int

Where values 4 and 5 are repeating as many times as entry 3 tells them to. Again code is working properly and is showing data correctly, it's fixed environment chance to get any kind of mistake is for storage file to get corrupted.

Problem is obviously in that if statement. If nothing expands that foldout, boolean wont ever trigger IF statement and piece of my code wont work.

So what I need here is only a way to show this hierarchy properly and I can't at the moment because we have to check if boolean is active in order to show sub-items... which requires IF statement which is causing problems.

I hope that I was a bit more clear this time, I'm not good with explaining problems. alt text

On picture you can see window "in action", where repeat 1 and 2 entries are repeating as many times as sub entry 3 tells them to.

Edit : Fixed formating, it's really weird here on Q&A.

screenshot_2.png (6.5 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Srki94 · Oct 15, 2014 at 03:59 PM

Have you realized that when you collapse the foldout you're no longer increasing your "i" value. To get the same i for the next foldout you would need to increase i manually by the same amount it would have been increased when the foldout was visible.

This indeed solved the issue. In IF statement I added else and manually increased i in the same way I increase it when user expands foldout, thus resulting in correct data display.

I will wait for Bunny83 to convert his comment to answer so that I can tag it as answer.

Thanks :)

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

29 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

Related Questions

EditorGUI.Foldout consumes click so GUI.Button doesnt work when inside of foldout region. 1 Answer

EditorGUI.ObjectField placed right below EditorGUI.Foldout? 1 Answer

How can PropertyDrawer with fouldouts to draw at the appropriate height? 3 Answers

Initialising List array for use in a custom Editor 1 Answer

EditorGUI.Foldout -- Cannot interact with contents! 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