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();
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!?
Your answer
Follow this Question
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