Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by Adventure-Forge-Studio · Nov 08, 2017 at 11:11 AM · editoreditor-scriptingeditorwindoweditorguieditorguilayout

Editor Int sliders affecting each other

Hi.

I'm working on a custom editor window where I can easily edit equipment that is going to be in our game. I'm currently stuck on creating a slider to adjust the maximum upgrade level for an object. I'm using the EditorGuiLayout.IntSlider to adjust the Int level value and by adjusting this level I am adding or removing Objectfields from the editor window. When done I hit my add equipment button and it is added to a List<> and also displayed further down in the window so that you can adjust and of the parameters. This is where my problems comes in. I create another IntSlider in on each of the areas that show the equipment to readjust its level, the problem is that the first IntSlider, where you would initially create an equipment, is affecting the ones below, and vice versa, and in turn adjusting the parameters. My backup plan is to simply go for buttons to add and remove, but I would really like is to be more dynamic.

This is the first slider part:

 EditorGUILayout.BeginHorizontal();
         EditorGUILayout.LabelField("Max Upgraded Level(int): ");
         nME_MaxLevel = EditorGUILayout.IntSlider(nME_MaxLevel, edit_Min_Level, edit_Max_Level);
         EditorGUILayout.EndHorizontal();

 EditorGUILayout.BeginVertical(GUI.skin.box, GUILayout.MaxWidth(800));
         GUILayout.TextArea("Equiptment Geometry");        
         for (int i = 0; i < nME_MaxLevel; i++)
         {
             EditorGUILayout.BeginHorizontal();
             if (nME_MaxLevel > nME_Geometry.Count)
             {
                 nME_Geometry.Add(new GameObject());
                 DestroyImmediate(nME_Geometry [ nME_Geometry.Count - 1 ]);
             }
 
             else if (nME_MaxLevel < nME_Geometry.Count)
             {
                 nME_Geometry.RemoveAt(nME_Geometry.Count-1);
             }
 
             if (nME_MaxLevel == nME_Geometry.Count)
             {
                 nME_Geometry [ i ] = (GameObject)EditorGUILayout.ObjectField(nME_Geometry [ i ], typeof(GameObject), true);
             }
             nME_Geometry.TrimExcess();
             EditorGUILayout.EndHorizontal();
         }
         EditorGUILayout.EndVertical();
 

Then I have this code in a for loop to go through the List<> of equipments:

 EditorGUILayout.BeginHorizontal();
             EditorGUILayout.LabelField("Max Upgraded Level(int): ");
             MinMaxLevel localMinMaxLevel = new MinMaxLevel();
             ssCtrl_Local.mEquiptmentBA[i].maxLevel = EditorGUILayout.IntSlider(ssCtrl_Local.mEquiptmentBA [ i ].maxLevel, localMinMaxLevel.minLevel, localMinMaxLevel.maxLevel);
 
             EditorGUILayout.EndHorizontal();
 for (int y = 0; y < ssCtrl_Local.mEquiptmentBA [ i ].maxLevel; y++)
             {
                 EditorGUILayout.BeginHorizontal();
 
                 if (ssCtrl_Local.mEquiptmentBA [ i ].maxLevel == ssCtrl_Local.mEquiptmentBA [ i ].equiptmentGeometry.Count)
                 {
                     ssCtrl_Local.mEquiptmentBA [ i ].equiptmentGeometry [ y ] = (GameObject)EditorGUILayout.ObjectField(ssCtrl_Local.mEquiptmentBA [ i ].equiptmentGeometry [ y ], typeof(GameObject), true);
                 }
 
                 if (ssCtrl_Local.mEquiptmentBA [ i ].maxLevel > ssCtrl_Local.mEquiptmentBA [ i ].equiptmentGeometry.Count)
                 {
                     ssCtrl_Local.mEquiptmentBA [ i ].equiptmentGeometry.Add(new GameObject());
                     DestroyImmediate(ssCtrl_Local.mEquiptmentBA [ i ].equiptmentGeometry [ ssCtrl_Local.mEquiptmentBA [ i ].equiptmentGeometry.Count - 1 ]);
                 }
 
                 else if (ssCtrl_Local.mEquiptmentBA [ i ].maxLevel < ssCtrl_Local.mEquiptmentBA [ i ].equiptmentGeometry.Count)
                 {
                     ssCtrl_Local.mEquiptmentBA [ i ].equiptmentGeometry.RemoveAt(ssCtrl_Local.mEquiptmentBA [ i ].equiptmentGeometry.Count - 1);
                 }                
                 ssCtrl_Local.mEquiptmentBA [ i ].equiptmentGeometry.TrimExcess();
                 EditorGUILayout.EndHorizontal();
             }
             EditorGUILayout.EndVertical();
 
             if (GUILayout.Button("Remove Equiptment Type"))
             {
                 ssCtrl_Local.mEquiptmentBA.RemoveAt(i);
                 ssCtrl_Local.mEquiptmentBA.TrimExcess();
             }
             EditorGUILayout.EndVertical();
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 Adventure-Forge-Studio · Nov 09, 2017 at 10:25 AM 0
Share

UPDATE: After some more testing I found that after adding new equipment to my List my custom editor still affects the values in the list. Example: I set up an equipment that should have 3 different level geometries, so I add 3 to the list of geometries for that equipment, add some resource requirements and hit the button to add it to the list. It gets added fine. Then when I want to add another equipment, this time with only 2 geometries, so I add just 2 geometries to the gameobject list. This results in the geometry list of the first equipment losing 1 slot in its geometry list. Why!?

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

150 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 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 display a scriptable object in a custom editor ? 1 Answer

EditorGUILayout.EnumPopup shows always the same selected option but works as programmed 1 Answer

GUI.Window. Wanting to allow clickthrough 0 Answers

How to create an Editor for Imported Objects imported from a ScriptedImporter? 1 Answer

How to change the text of EditorGUILayout.TextField 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