- Home /
Updating editor GUI on button press
I'm trying to create a layout for an editor aimed to make Element lists in the inspector more user friendly. Right now I'm building a column of ObjectFields from an ArrayList, but I'd like to add/remove items from the ArrayList through the press of a button. My biggest concern right now is updating the editor. I can easily edit the ArrayList, but I can't update the amount of ObjectFields in the inspector. I'm at loss here really.
Here's as far as I've gotten.
public override void OnInspectorGUI()
{
JEWaveManager waveManager = target as JEWaveManager;
ArrayList arr = new ArrayList();
arr.Add ("Element");
arr.Add ("Element");
Vector2 scrollPos = new Vector2 (0.0F, 0.0F);
/*GUILayout.BeginScrollView(scrollPos, GUILayout.Width (100), GUILayout.Height(100));*/
GUILayout.BeginVertical ();
Object source = null;
foreach (string s in arr)
EditorGUILayout.ObjectField(s, source, typeof(Object), true);
if (GUILayout.Button("New Item"))
{
arr.Add ("Element");
Repaint ();
}
GUILayout.EndVertical ();
/*GUILayout.EndScrollView ();*/
}
Answer by R3DRAW STUDIOS · Sep 02, 2014 at 05:04 AM
instead of doing this extra crap. i suggest you get the unity 4.6 beta all you gotta do is drag a button in and add a code it will automatically do on click.
i suggest you watch this: https://www.youtube.com/watch?v=rsZM3q74Q2k
Unity 4.6 Beta Download: http://unity3d.com/unity/beta/4.6
Answer by TheBikupan · Sep 02, 2014 at 10:46 AM
To be extra clear I'm working with the Editor GUI, so this is of no use in this case :) Just trying to make my inspector items more dynamic, being able to add/remove and rearrange fields on the go. My only issue being updating the editor to accomodate for the changes - I've tried Repaint(); but it's not helped me so far, maybe I'm using it incorrectly though.