public override void OnInspectorGUI() { var e = Event.current; var states = UPMEditorUtil.GetAllStates(motor); motor.DefaultState = (State)EditorGUILayout.ObjectField("Default State", motor.DefaultState, typeof(State), false); motor.CollisionMask = UPMEditor.LayerMaskField("Collision Mask", motor.CollisionMask); var notEmpty = states.Count > 0; EditorGUILayout.PrefixLabel((notEmpty ? states.Count.ToString() : "No") + " states found"); if (notEmpty) { var toRemove = new List <State>(); foreach (var state in states) { EditorGUILayout.BeginHorizontal(); state.name = EditorGUILayout.TextField(state.name); if (GUILayout.Button("Delete")) { toRemove.Add(state); } EditorGUILayout.EndHorizontal(); } foreach (var state in toRemove) { UPMEditorUtil.DeleteInstance(motor, state); AssetDatabase.SaveAssets(); } } if (!GUILayout.Button(UPMEditor.AddStateContent)) { return; } var rect = new Rect(e.mousePosition, stateSelector.GetWindowSize()); PopupWindow.Show(rect, stateSelector); }
public override void OnGUI(Rect rect) { var data = UPMAssemblyUtil.KnownPossibleStates; for (var i = 0; i < data.Count; i++) { var s = data[i]; var pos = rect.GetLine((uint)i, EditorGUIUtility.singleLineHeight); GUI.enabled = s.Valid; var type = s.Type; if (!GUI.Button(pos, type.Name)) { continue; } var instance = (State)ScriptableObject.CreateInstance(type); instance.name = type.Name; AssetDatabase.AddObjectToAsset(instance, motor); AssetDatabase.SaveAssets(); UPMEditorUtil.NotifyNewInstance(motor, instance); } }