public override IsoSwitches getIsoSwitches() { if (instance == null) { instance = Resources.Load<IsoSwitches> ("IsoSwitches"); if(instance == null){ if (Application.isEditor) { #if UNITY_EDITOR System.Reflection.MethodInfo mi = Type.GetType ("IsoSwitchesMenu").GetMethod ("createSwitches"); instance = mi.Invoke(null, null) as IsoSwitches; #endif } else { //To prevent crashing Debug.LogWarning("Iso switches not found in /Resources. Runtime instance created. Consider to create the Asset."); instance = ScriptableObject.CreateInstance<IsoSwitches> (); } } } return instance; }
public override void OnInspectorGUI() { isoSwitches = target as IsoSwitches; GUIStyle style = new GUIStyle(); style.padding = new RectOffset(5,5,5,5); isoSwitches = target as IsoSwitches; EditorGUILayout.HelpBox("List of switches that represent the state of the game.", MessageType.None); ISwitch[] switches = isoSwitches.getList (); if(switches != null){ int i = 0; scrollposition = EditorGUILayout.BeginScrollView(scrollposition, GUILayout.ExpandHeight(true)); foreach(ISwitch isw in switches){ EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("ID: ", GUILayout.Width(27)); isw.id = EditorGUILayout.TextField(isw.id); isw.State = ParamEditor.editorFor("Initial State: ", isw.State); GUIContent btt = new GUIContent("Remove"); Rect btr = GUILayoutUtility.GetRect(btt, style); if(GUI.Button(btr,btt)){ isoSwitches.removeSwitch(isw); }; EditorGUILayout.EndHorizontal(); i++; } EditorGUILayout.EndScrollView(); } EditorGUILayout.BeginHorizontal(); GUIContent bttext = new GUIContent("Add Switch"); Rect btrect = GUILayoutUtility.GetRect(bttext, style); if(GUI.Button(btrect,bttext)){ isoSwitches.addSwitch(); }; EditorGUILayout.EndHorizontal(); }