private bool DoHeader() { bool foldOut = EditorPrefs.GetBool("FsmVariables", true); Rect rect = GUILayoutUtility.GetRect(new GUIContent("Variables"), FsmEditorStyles.variableHeader, GUILayout.ExpandWidth(true)); rect.x -= 1; rect.width += 2; Rect rect2 = new Rect(rect.width - 10, rect.y + 2, 25, 25); EventType eventType = FsmEditorUtility.ReserveEvent(rect2); if (GUI.Button(rect, "Variables" + (foldOut?"":"[Click to expand]"), FsmEditorStyles.variableHeader)) { if (Event.current.button == 0) { EditorPrefs.SetBool("FsmVariables", !foldOut); } } FsmEditorUtility.ReleaseEvent(eventType); bool isEnabled = GUI.enabled; GUI.enabled = FsmEditor.Active != null; if (GUI.Button(rect2, FsmEditorStyles.toolbarPlus, FsmEditorStyles.label)) { FsmGUIUtility.SubclassMenu <FsmVariable>(CreateVariable); Event.current.Use(); } GUI.enabled = isEnabled; return(foldOut); }
public static void CreateStateMachine() { FsmEditor.ShowWindow(); StateMachine stateMachine = AssetCreator.CreateAsset <StateMachine> (true); if (stateMachine == null) { return; } stateMachine.color = (int)NodeColor.Blue; stateMachine.Name = stateMachine.name; FsmGameObject gameObject = ScriptableObject.CreateInstance <FsmGameObject> (); gameObject.Name = "Owner"; gameObject.hideFlags = HideFlags.HideInHierarchy; gameObject.IsHidden = true; gameObject.IsShared = true; stateMachine.Variables = ArrayUtility.Add <FsmVariable> (stateMachine.Variables, gameObject); AssetDatabase.AddObjectToAsset(gameObject, stateMachine); AssetDatabase.SaveAssets(); AnyState state = FsmEditorUtility.AddNode <AnyState> (FsmEditor.Center, stateMachine); state.color = (int)NodeColor.Aqua; state.Name = "Any State"; FsmEditor.SelectStateMachine(stateMachine); }
private void NodeContextMenu(){ if (currentEvent.type != EventType.MouseDown || currentEvent.button != 1 || currentEvent.clickCount != 1){ return; } Node node=MouseOverNode(); if (node == null) { return; } GenericMenu nodeMenu = new GenericMenu (); nodeMenu.AddItem (FsmContent.makeTransition, false, delegate() { fromNode=node; }); if(!node.IsStartNode && !(node is AnyState)){ nodeMenu.AddItem (FsmContent.setAsDefault, false, delegate() { FsmEditorUtility.SetDefaultNode(node,FsmEditor.Active); }); }else{ nodeMenu.AddDisabledItem(FsmContent.setAsDefault); } if (node.GetType () == typeof(State)) { State state = node as State; nodeMenu.AddItem (FsmContent.sequence, state.IsSequence, delegate() { state.IsSequence=!state.IsSequence; }); } if (node.GetType () != typeof(AnyState)) { nodeMenu.AddItem (FsmContent.copy, false, delegate() { Pasteboard.Copy (selection); }); nodeMenu.AddItem (FsmContent.delete, false, delegate() { if (selection.Contains (node)) { foreach (Node mNode in selection) { if(!(mNode is AnyState)){ FsmEditorUtility.DeleteNode (mNode); } } selection.Clear (); UpdateUnitySelection (); } else { FsmEditorUtility.DeleteNode (node); } EditorUtility.SetDirty (FsmEditor.Active); }); } else { nodeMenu.AddDisabledItem(FsmContent.copy); nodeMenu.AddDisabledItem(FsmContent.delete); } nodeMenu.ShowAsContext (); Event.current.Use (); }
public static void DestroyImmediate(ScriptableObject obj) { if (obj == null) { return; } FsmEditorUtility.DeleteChilds(obj); UnityEngine.Object.DestroyImmediate(obj, true); AssetDatabase.SaveAssets(); }
private void OnTransitionContextClick(int index) { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Remove"), false, delegate() { FsmEditorUtility.DestroyImmediate(node.Transitions[index]); node.Transitions = ArrayUtility.Remove(node.Transitions, transitions [index]); this.ResetTransitionList(); }); menu.ShowAsContext(); }
public static void DeleteNode(Node node) { FsmEditorUtility.DestroyImmediate(node); node.Parent.Nodes = ArrayUtility.Remove <Node> (node.Parent.Nodes, node); foreach (Transition transition in node.InTransitions) { FsmEditorUtility.DestroyImmediate(transition); transition.FromNode.Transitions = ArrayUtility.Remove(transition.FromNode.Transitions, transition); } ErrorChecker.CheckForErrors(); }
public override void OnGUI(SerializedProperty property, GUIContent label) { SerializedProperty componentProperty = property.serializedObject.FindProperty("component"); SerializedProperty propProperty = property.serializedObject.FindProperty("property"); SerializedProperty parameterProperty = property.serializedObject.FindProperty("parameter"); GUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(componentProperty); ComponentHint(componentProperty, propProperty); GUILayout.EndHorizontal(); if (!string.IsNullOrEmpty(componentProperty.stringValue)) { Type componentType = TypeUtility.GetType(componentProperty.stringValue); if (componentType != null) { GUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(propProperty); PropertyHint(propProperty, componentType); GUILayout.EndHorizontal(); if (!string.IsNullOrEmpty(propProperty.stringValue)) { Type variableType = FsmUtility.GetVariableType(TypeUtility.GetMemberType(componentType, propProperty.stringValue)); Debug.Log(variableType); if (variableType != null) { fieldInfo = property.serializedObject.targetObject.GetType().GetField("parameter"); if (parameterProperty.objectReferenceValue == null || parameterProperty.objectReferenceValue.GetType() != variableType) { FsmEditorUtility.DestroyImmediate(parameterProperty.objectReferenceValue as FsmVariable); FsmVariable variable = ScriptableObject.CreateInstance(variableType) as FsmVariable; variable.hideFlags = HideFlags.HideInHierarchy; if (EditorUtility.IsPersistent(parameterProperty.serializedObject.targetObject)) { AssetDatabase.AddObjectToAsset(variable, property.serializedObject.targetObject); AssetDatabase.SaveAssets(); } variable.IsShared = fieldInfo.HasAttribute(typeof(SharedAttribute)) || EditorUtility.IsPersistent(variable) && fieldInfo.HasAttribute(typeof(SharedPersistentAttribute)) || variable is FsmArray; parameterProperty.serializedObject.Update(); parameterProperty.objectReferenceValue = variable; parameterProperty.serializedObject.ApplyModifiedProperties(); } base.OnGUI(parameterProperty, new GUIContent("Parameter")); } } } } }
protected override void OnGUI() { mainToolbar.OnGUI(); EventType eventType = FsmEditorUtility.ReserveEvent(variableEditorRect, fsmSelectionRect, preferencesRect); ZoomableArea.Begin(new Rect(0f, 0f, scaledCanvasSize.width, scaledCanvasSize.height + 21), scale, IsDocked); Begin(); shortcutEditor.HandleKeyEvents(); if (FsmEditor.Active != null) { DoNodes(); } else { ZoomableArea.End(); } AcceptDragAndDrop(); End(); FsmEditorUtility.ReleaseEvent(eventType); PreferencesEditor.DoGUI(preferencesRect); shortcutEditor.DoGUI(shortcutRect); DoFsmSelection(fsmSelectionRect); variableEditor.DoGUI(variableEditorRect); if (centerView) { CenterView(); centerView = false; } if (FsmEditor.Active != null) { GUI.Label(new Rect(5, 20, 300, 200), FsmEditor.Active.comment, FsmEditorStyles.instructionLabel); } else { GUI.Label(new Rect(5, 20, 300, 200), "Right click to create a state machine.", FsmEditorStyles.instructionLabel); } Event ev = Event.current; if (SelectedNodes.Count == 1 && ev.rawType == EventType.KeyDown && ev.keyCode == KeyCode.Delete && FsmEditor.SelectedTransition != null && EditorUtility.DisplayDialog("Delete selected transition?", FsmEditor.SelectedTransition.FromNode.Name + " -> " + FsmEditor.SelectedTransition.ToNode.Name + "\r\n\r\nYou cannot undo this action.", "Delete", "Cancel")) { Node node = SelectedTransition.FromNode; node.Transitions = ArrayUtility.Remove(node.Transitions, FsmEditor.SelectedTransition); FsmEditorUtility.DestroyImmediate(FsmEditor.SelectedTransition); ErrorChecker.CheckForErrors(); EditorUtility.SetDirty(node); } }
private void SelectGameObject() { if (GUILayout.Button(FsmEditor.ActiveGameObject != null?FsmEditor.ActiveGameObject.name:"[None Selected]", EditorStyles.toolbarDropDown, GUILayout.Width(100))) { GenericMenu toolsMenu = new GenericMenu(); List <ICodeBehaviour> behaviours = FsmEditorUtility.FindInScene <ICodeBehaviour>(); foreach (ICodeBehaviour behaviour in behaviours) { GameObject mGameObject = behaviour.gameObject; toolsMenu.AddItem(new GUIContent(behaviour.name), false, delegate() { FsmEditor.SelectGameObject(mGameObject); }); } toolsMenu.ShowAsContext(); } }
private void SelectStateMachine() { GUIContent content = new GUIContent(FsmEditor.Active != null?FsmEditor.Active.Name:"[None Selected]"); float width = EditorStyles.toolbarDropDown.CalcSize(content).x; width = Mathf.Clamp(width, 100f, width); if (GUILayout.Button(content, EditorStyles.toolbarDropDown, GUILayout.Width(width))) { GenericMenu toolsMenu = new GenericMenu(); if (FsmEditor.ActiveGameObject != null) { foreach (ICodeBehaviour behaviour in FsmEditor.ActiveGameObject.GetComponents <ICodeBehaviour>()) { SelectStateMachineMenu(behaviour.stateMachine, ref toolsMenu); } } else if (FsmEditor.Active != null) { SelectStateMachineMenu(FsmEditor.Active.Root, ref toolsMenu); } toolsMenu.AddItem(new GUIContent("[Create New]"), false, delegate() { StateMachine stateMachine = AssetCreator.CreateAsset <StateMachine> (true); if (stateMachine != null) { stateMachine.Name = stateMachine.name; AnyState state = FsmEditorUtility.AddNode <AnyState> (FsmEditor.Center, stateMachine); state.color = (int)NodeColor.Aqua; state.Name = "Any State"; FsmGameObject gameObject = ScriptableObject.CreateInstance <FsmGameObject> (); gameObject.Name = "Owner"; gameObject.hideFlags = HideFlags.HideInHierarchy; gameObject.IsHidden = true; gameObject.IsShared = true; stateMachine.Variables = ArrayUtility.Add <FsmVariable> (stateMachine.Variables, gameObject); AssetDatabase.AddObjectToAsset(gameObject, stateMachine); AssetDatabase.SaveAssets(); FsmEditor.SelectStateMachine(stateMachine); } }); toolsMenu.ShowAsContext(); } }
public bool DoListHeader() { bool foldOut = EditorPrefs.GetBool(title, false); Rect rect = GUILayoutUtility.GetRect(new GUIContent(title), FsmEditorStyles.variableHeader, GUILayout.ExpandWidth(true)); rect.x -= 1; rect.width += 2; Rect rect2 = new Rect(rect.width - 10, rect.y + 2, 25, 25); EventType eventType = FsmEditorUtility.ReserveEvent(rect2); if (GUI.Button(rect, title, FsmEditorStyles.variableHeader)) { if (Event.current.button == 0) { EditorPrefs.SetBool(title, !foldOut); } if (Event.current.button == 1 && onHeaderClick != null) { onHeaderClick(); } } FsmEditorUtility.ReleaseEvent(eventType); if (displayAdd && GUI.Button(rect2, FsmEditorStyles.toolbarPlus, FsmEditorStyles.label) && onAddCallback != null) { onAddCallback(); if (onSelectCallback != null) { onSelectCallback(items.Count); } } if (onDrawHeaderContent != null) { onDrawHeaderContent(rect); } return(foldOut); }
private void DoEvents(Event ev, bool isMouse) { if (Validate("showHelp", KeyCode.F1, isMouse)) { PreferencesEditor.ToggleBool(Preference.ShowShortcuts); ev.Use(); } if (Validate("centerView", KeyCode.Tab, isMouse)) { FsmEditor.instance.CenterView(); } if (Validate("selectAll", KeyCode.F2, isMouse)) { FsmEditor.instance.ToggleSelection(); ev.Use(); } if (Validate("createState", KeyCode.F3, isMouse) && FsmEditor.instance != null) { FsmEditorUtility.AddNode <State>(ev.mousePosition, FsmEditor.Active); if (FsmEditor.instance != null) { FsmEditor.instance.Repaint(); } ev.Use(); } if (Validate("actionBrowser", KeyCode.F4, isMouse)) { ActionBrowser.ShowWindow(); ev.Use(); } if (Validate("conditionBrowser", KeyCode.F5, isMouse)) { ConditionBrowser.ShowWindow(); ev.Use(); } }
public void OnInspectorGUI() { int index = node.Transitions.ToList().FindIndex(x => x == FsmEditor.SelectedTransition); if (index != transitionList.index && index != -1) { transitionList.index = index; } transitionList.DoLayoutList(); GUILayout.Space(10f); conditionList.DoLayoutList(); Event ev = Event.current; if (ev.rawType == EventType.KeyDown && ev.keyCode == KeyCode.Delete && FsmEditor.SelectedTransition != null && EditorUtility.DisplayDialog("Delete selected transition?", FsmEditor.SelectedTransition.FromNode.Name + " -> " + FsmEditor.SelectedTransition.ToNode.Name + "\r\n\r\nYou cannot undo this action.", "Delete", "Cancel")) { node.Transitions = ArrayUtility.Remove(node.Transitions, FsmEditor.SelectedTransition); FsmEditorUtility.DestroyImmediate(FsmEditor.SelectedTransition); ErrorChecker.CheckForErrors(); EditorUtility.SetDirty(node); } }
public override void CreateVariable(SerializedProperty property) { FsmVariable variable = property.objectReferenceValue as FsmVariable; if (parameterTypeNames == null) { parameterTypeNames = TypeUtility.GetSubTypeNames(typeof(FsmVariable)); parameterTypeNames = ArrayUtility.Insert <string> (parameterTypeNames, "None", 0); } int index = parameterTypeNames.ToList().FindIndex(x => x == (variable != null?variable.GetType().ToString().Split('.').Last():"")); index = Mathf.Clamp(index, 0, int.MaxValue); index = EditorGUILayout.Popup("Parameter Type", index, parameterTypeNames); string typeName = parameterTypeNames [index]; string variableTypeName = (variable == null ? "None" : variable.GetType().Name); if (typeName != variableTypeName) { FsmEditorUtility.DestroyImmediate(property.objectReferenceValue as FsmVariable); if (typeName != "None") { variable = ScriptableObject.CreateInstance(TypeUtility.GetTypeByName(typeName)[0]) as FsmVariable; variable.hideFlags = HideFlags.HideInHierarchy; if (EditorUtility.IsPersistent(property.serializedObject.targetObject)) { AssetDatabase.AddObjectToAsset(variable, property.serializedObject.targetObject); AssetDatabase.SaveAssets(); } variable.IsShared = fieldInfo.HasAttribute(typeof(SharedAttribute)) || EditorUtility.IsPersistent(variable) && fieldInfo.HasAttribute(typeof(SharedPersistentAttribute)) || variable is FsmArray || !variable.GetType().GetProperty("Value").PropertyType.IsSerializable; property.serializedObject.Update(); property.objectReferenceValue = variable; property.serializedObject.ApplyModifiedProperties(); } ErrorChecker.CheckForErrors(); } }
protected override void OnGUI () { mainToolbar.OnGUI (); EventType eventType = FsmEditorUtility.ReserveEvent (variableEditorRect,fsmSelectionRect, preferencesRect); Begin (); shortcutEditor.HandleKeyEvents (); if(FsmEditor.Active != null) DoNodes (); End (); FsmEditorUtility.ReleaseEvent (eventType); PreferencesEditor.DoGUI (preferencesRect); shortcutEditor.DoGUI (shortcutRect); DoFsmSelection (fsmSelectionRect); variableEditor.DoGUI (variableEditorRect); if (centerView) { CenterView(); centerView=false; } if (FsmEditor.Active != null) { GUI.Label (new Rect (5, 20, 300, 200), FsmEditor.Active.comment, FsmEditorStyles.instructionLabel); } }
public static T AddNode <T>(Vector2 position, StateMachine parent) { if (parent == null) { Debug.LogWarning("Can't add node to parent state machine, because the parent state machine is null!"); return(default(T)); } Node node = (Node)ScriptableObject.CreateInstance(typeof(T)); node.hideFlags = HideFlags.HideInHierarchy; node.Name = FsmEditorUtility.GenerateUniqueNodeName <T> (parent.Root); node.Parent = parent; parent.Nodes = ArrayUtility.Add <Node> (parent.Nodes, node); node.position = new Rect(position.x, position.y, FsmEditorStyles.StateWidth, FsmEditorStyles.StateHeight); UpdateNodeColor(node); if (EditorUtility.IsPersistent(parent)) { AssetDatabase.AddObjectToAsset(node, parent); } if (node.GetType() == typeof(StateMachine)) { node.position.width = FsmEditorStyles.StateMachineWidth; node.position.height = FsmEditorStyles.StateMachineHeight; AnyState state = FsmEditorUtility.AddNode <AnyState> (FsmEditor.Center, (StateMachine)node); UpdateNodeColor(state); state.Name = "Any State"; } AssetDatabase.SaveAssets(); return((T)(object)node); }
private void ResetActionList() { this.actions = this.state.Actions; this.actionList = new ReorderableList(this.actions, "Action", true, true) { drawElementCallback = new ReorderableList.ElementCallbackDelegate(this.OnActionElement), onReorderCallback = new ReorderableList.ReorderCallbackDelegate(this.OnReorderList), onAddCallback = new ReorderableList.AddCallbackDelegate(delegate(){ FsmGUIUtility.SubclassMenu <StateAction> (CreateAction); }), onContextClick = new ReorderableList.ContextCallbackDelegate(delegate(int index){ FsmGUIUtility.ExecutableContextMenu(actions[index], state).ShowAsContext(); }), onHeaderClick = new ReorderableList.OnHeaderClick(delegate(){ GenericMenu menu = new GenericMenu(); if (actions.Length > 0) { menu.AddItem(new GUIContent("Copy"), false, delegate { copy = new List <StateAction>(actions); copyState = state; }); } else { menu.AddDisabledItem(new GUIContent("Copy")); } if (copy == null) { copy = new List <StateAction>(); } copy.RemoveAll(x => x == null); if (copy.Count > 0) { menu.AddItem(new GUIContent("Paste After"), false, delegate() { for (int i = 0; i < copy.Count; i++) { ExecutableNode dest = FsmUtility.Copy(copy[i]); state.Actions = ArrayUtility.Add <StateAction>(state.Actions, (StateAction)dest); FsmEditorUtility.ParentChilds(state); NodeInspector.Dirty(); } }); menu.AddItem(new GUIContent("Paste Before"), false, delegate() { for (int i = 0; i < copy.Count; i++) { ExecutableNode dest = FsmUtility.Copy(copy[i]); state.Actions = ArrayUtility.Insert <StateAction>(state.Actions, (StateAction)dest, 0); FsmEditorUtility.ParentChilds(state); NodeInspector.Dirty(); } }); if (copyState != state) { menu.AddItem(new GUIContent("Replace"), false, delegate() { for (int i = 0; i < state.Actions.Length; i++) { FsmEditorUtility.DestroyImmediate(state.Actions[i]); } state.Actions = new StateAction[0]; ResetActionList(); for (int i = 0; i < copy.Count; i++) { ExecutableNode dest = FsmUtility.Copy(copy[i]); state.Actions = ArrayUtility.Add <StateAction>(state.Actions, (StateAction)dest); FsmEditorUtility.ParentChilds(state); NodeInspector.Dirty(); } }); } else { menu.AddDisabledItem(new GUIContent("Replace")); } } else { menu.AddDisabledItem(new GUIContent("Paste After")); menu.AddDisabledItem(new GUIContent("Paste Before")); menu.AddDisabledItem(new GUIContent("Replace")); } menu.ShowAsContext(); }), }; this.host.Repaint(); if (FsmEditor.instance != null) { FsmEditor.instance.Repaint(); } }
private void DrawVariables() { scroll = GUILayout.BeginScrollView(scroll); Dictionary <string, List <FsmVariable> > groupParameters = GetGroupVariables(); EditorGUIUtility.labelWidth = 110; foreach (var kvp in groupParameters) { bool foldout = EditorPrefs.GetBool(kvp.Key, false); bool state = EditorGUILayout.Foldout(foldout, kvp.Key); if (state != foldout) { EditorPrefs.SetBool(kvp.Key, state); } if (foldout) { for (int i = 0; i < groupParameters[kvp.Key].Count; i++) { FsmVariable parameter = groupParameters[kvp.Key][i]; if (parameter != null) { SerializedObject paramObject = new SerializedObject(parameter); SerializedProperty prop = paramObject.FindProperty("value"); GUILayout.BeginHorizontal(); GUILayout.Space(16f); string name = paramObject.FindProperty("name").stringValue; if (parameter is FsmGameObject) { GUI.changed = false; FsmGameObject mParam = parameter as FsmGameObject; if (string.IsNullOrEmpty(mParam.ScenePath)) { mParam.Value = (GameObject)EditorGUILayout.ObjectField(name, mParam.Value, typeof(UnityEngine.GameObject), true); } else { GUILayout.Label(name, GUILayout.Width(106)); GUILayout.Label(mParam.ScenePath, FsmEditorStyles.wrappedLabelLeft); GUILayout.FlexibleSpace(); } if (GUI.changed) { if (!EditorUtility.IsPersistent(mParam.Value) && mParam.Value is GameObject) { string currentOpenScene = string.Empty; #if UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2 currentOpenScene = EditorApplication.currentScene; #else currentOpenScene = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().name; #endif if (string.IsNullOrEmpty(currentOpenScene)) { EditorUtility.DisplayDialog("Save Scene!", "You need to save the scene before setting the GameObject.", "Ok"); mParam.Value = null; } else { #if UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2 mParam.ScenePath = mParam.Value.name + "(" + EditorApplication.currentScene + ")"; #else mParam.ScenePath = mParam.Value.name + "(" + UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().path + ")"; #endif SetGlobalGameObject mSet = mParam.Value.GetComponent <SetGlobalGameObject>(); if (mSet == null) { mSet = mParam.Value.AddComponent <SetGlobalGameObject>(); } mSet.variableName = mParam.Name; } } EditorUtility.SetDirty(mParam); } } else { paramObject.Update(); if (prop != null) { EditorGUILayout.PropertyField(prop, new GUIContent(name), true); } paramObject.ApplyModifiedProperties(); } if (GUILayout.Button("down", EditorStyles.toolbarButton, GUILayout.Width(35))) { if (i < groupParameters[kvp.Key].Count) { int indexToMove = Array.FindIndex(globalVariables.Variables, x => x.Name == parameter.Name); globalVariables.Variables.Move(indexToMove, 0); EditorUtility.SetDirty(globalVariables); } } if (GUILayout.Button("up", EditorStyles.toolbarButton, GUILayout.Width(20))) { if (i > 0) { int indexToMove = Array.FindIndex(globalVariables.Variables, x => x.Name == parameter.Name); globalVariables.Variables.Move(indexToMove, 1); EditorUtility.SetDirty(globalVariables); } } if (GUILayout.Button(parameter.Group, EditorStyles.toolbarDropDown, GUILayout.Width(54))) { GenericMenu menu = new GenericMenu(); foreach (FsmVariable p in globalVariables.Variables) { string group = p.Group; FsmVariable mParam = parameter; menu.AddItem(new GUIContent(group), mParam.Group == group, delegate() { mParam.Group = group; }); } menu.ShowAsContext(); } if (GUILayout.Button(EditorGUIUtility.FindTexture("Toolbar Minus"), "label", GUILayout.Width(20))) { if (parameter is FsmGameObject) { string scenePath = (parameter as FsmGameObject).ScenePath; scenePath = scenePath.Substring(scenePath.IndexOf("(") + 1); scenePath = scenePath.Substring(0, scenePath.IndexOf(")")); #if UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2 if (EditorApplication.currentScene != scenePath.Split('/').Last()) { EditorApplication.SaveScene(); EditorApplication.OpenScene(scenePath); } #else UnityEditor.SceneManagement.EditorSceneManager.SaveOpenScenes(); UnityEngine.SceneManagement.Scene scene = UnityEditor.SceneManagement.EditorSceneManager.OpenScene(scenePath); UnityEditor.SceneManagement.EditorSceneManager.SetActiveScene(scene); #endif List <SetGlobalGameObject> gos = FindObjectsOfType <SetGlobalGameObject>().ToList(); SetGlobalGameObject go = gos.Find(x => x.variableName == parameter.Name); if (go != null) { DestroyImmediate(go); } } globalVariables.Variables = ArrayUtility.Remove(globalVariables.Variables, parameter); FsmEditorUtility.DestroyImmediate(parameter);; EditorUtility.SetDirty(globalVariables); #if UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2 EditorApplication.SaveScene(); #else UnityEditor.SceneManagement.EditorSceneManager.SaveOpenScenes(); #endif } GUILayout.EndHorizontal(); } } } } GUILayout.EndScrollView(); }
private void DestroyActive() { FsmEditorUtility.DestroyImmediate(active); }
public static void Paste(Vector2 position, StateMachine stateMachine) { List <Node> copiedNodes = new List <Node> (); Vector2 center = GetCenter(nodes); for (int i = 0; i < nodes.Count; i++) { Node origNode = nodes[i]; List <FsmVariable> sharedVariables = new List <FsmVariable>(); GetSharedVariables(origNode, ref sharedVariables); if (sharedVariables.Count > 0) { string variableNames = string.Empty; sharedVariables.Select(x => x.Name).ToList().ForEach(y => variableNames = (variableNames + (string.IsNullOrEmpty(variableNames)?"":",") + y)); if (EditorUtility.DisplayDialog("Paste Variables", "Copied states have reference to shared variables, do you want to paste those variables? (" + variableNames + ")", "Yes", "No")) { for (int j = 0; j < sharedVariables.Count; j++) { FsmVariable variable = sharedVariables[j]; stateMachine.SetVariable(variable.Name, variable.GetValue()); } } } Node mNode = (Node)FsmUtility.Copy(origNode); mNode.Parent = stateMachine; mNode.hideFlags = HideFlags.HideInHierarchy; if (mNode.IsStartNode && stateMachine.GetStartNode() != null) { mNode.IsStartNode = false; } //mNode.Name = FsmEditorUtility.GenerateUniqueNodeName(mNode.GetType(),stateMachine); stateMachine.Nodes = ArrayUtility.Add <Node> (stateMachine.Nodes, mNode); mNode.position = new Rect(-(center.x - origNode.position.x) + position.x, -(center.y - origNode.position.y) + position.y, FsmEditorStyles.StateWidth, FsmEditorStyles.StateHeight); if (mNode.GetType() == typeof(StateMachine)) { mNode.position.width = FsmEditorStyles.StateMachineWidth; mNode.position.height = FsmEditorStyles.StateMachineHeight; } FsmEditorUtility.UpdateNodeColor(mNode); copiedNodes.Add(mNode); } for (int i = 0; i < copiedNodes.Count; i++) { Node mNode = copiedNodes [i]; if (mNode is AnyState) { bool mOverride = EditorUtility.DisplayDialog("Override AnyState", "AnyState can only exist once per state machine. Do you want to override it?", "Yes", "No"); AnyState anyState = stateMachine.Nodes.ToList().Find(x => x.GetType() == typeof(AnyState) && (mOverride && x != mNode || !mOverride && x == mNode)) as AnyState; stateMachine.Nodes = ArrayUtility.Remove(stateMachine.Nodes, anyState); FsmEditorUtility.DestroyImmediate(anyState); FsmEditor.SelectedNodes.Clear(); } } for (int i = 0; i < copiedNodes.Count; i++) { Node mNode = copiedNodes[i]; foreach (Transition transition in mNode.Transitions) { Node toNode = copiedNodes.Find(x => x.Name == transition.ToNode.Name) ?? stateMachine.Nodes.ToList().Find(x => x.Name == transition.ToNode.Name); if (toNode != null) { transition.ToNode = toNode; } else { FsmEditorUtility.DestroyImmediate(transition); mNode.Transitions = ArrayUtility.Remove(mNode.Transitions, transition); } } } for (int i = 0; i < copiedNodes.Count; i++) { Node mNode = stateMachine.Nodes.ToList().Find(x => x.Name == copiedNodes[i].Name && x != copiedNodes[i]); if (mNode != null) { copiedNodes[i].Name = FsmEditorUtility.GenerateUniqueNodeName(copiedNodes[i].GetType(), stateMachine); } } FsmEditorUtility.ParentChilds(stateMachine); nodes.Clear(); EditorUtility.SetDirty(stateMachine); ErrorChecker.CheckForErrors(); }
private void ResetConditionList() { if (transition == null) { return; } this.conditions = this.transition.Conditions; this.conditionList = new ReorderableList(this.conditions, "Condition", true, true) { drawElementCallback = new ReorderableList.ElementCallbackDelegate(this.OnConditionElement), onReorderCallback = new ReorderableList.ReorderCallbackDelegate(this.OnReorderConditionList), onAddCallback = new ReorderableList.AddCallbackDelegate(delegate(){ FsmGUIUtility.SubclassMenu <Condition> (CreateCondition); }), onContextClick = new ReorderableList.ContextCallbackDelegate(delegate(int index){ FsmGUIUtility.ExecutableContextMenu(conditions[index], node).ShowAsContext(); }), onHeaderClick = new ReorderableList.OnHeaderClick(delegate(){ GenericMenu menu = new GenericMenu(); if (conditions.Length > 0) { menu.AddItem(new GUIContent("Copy"), false, delegate { copy = transition; }); } else { menu.AddDisabledItem(new GUIContent("Copy")); } if (copy != null && copy.Conditions.Length > 0) { menu.AddItem(new GUIContent("Paste After"), false, delegate() { for (int i = 0; i < copy.Conditions.Length; i++) { ExecutableNode dest = FsmUtility.Copy(copy.Conditions[i]); transition.Conditions = ArrayUtility.Add <Condition>(transition.Conditions, (Condition)dest); FsmEditorUtility.ParentChilds(transition); NodeInspector.Dirty(); } }); menu.AddItem(new GUIContent("Paste Before"), false, delegate() { for (int i = 0; i < copy.Conditions.Length; i++) { ExecutableNode dest = FsmUtility.Copy(copy.Conditions[i]); transition.Conditions = ArrayUtility.Insert <Condition>(transition.Conditions, (Condition)dest, 0); FsmEditorUtility.ParentChilds(transition); NodeInspector.Dirty(); } }); if (copy != transition) { menu.AddItem(new GUIContent("Replace"), false, delegate() { for (int i = 0; i < transition.Conditions.Length; i++) { FsmEditorUtility.DestroyImmediate(transition.Conditions[i]); } transition.Conditions = new Condition[0]; ResetConditionList(); for (int i = 0; i < copy.Conditions.Length; i++) { ExecutableNode dest = FsmUtility.Copy(copy.Conditions[i]); transition.Conditions = ArrayUtility.Add <Condition>(transition.Conditions, (Condition)dest); FsmEditorUtility.ParentChilds(transition); NodeInspector.Dirty(); } }); } else { menu.AddDisabledItem(new GUIContent("Replace")); } } else { menu.AddDisabledItem(new GUIContent("Paste After")); menu.AddDisabledItem(new GUIContent("Paste Before")); menu.AddDisabledItem(new GUIContent("Replace")); } menu.ShowAsContext(); }), }; this.host.Repaint(); if (FsmEditor.instance != null) { FsmEditor.instance.Repaint(); } }
private void NodeContextMenu () { if (currentEvent.type != EventType.MouseDown || currentEvent.button != 1 || currentEvent.clickCount != 1) { return; } Node node = MouseOverNode (); if (node == null) { return; } GenericMenu nodeMenu = new GenericMenu (); if (Application.isPlaying && this.active != null && this.active.Owner != null && node != this.active.Owner.ActiveNode) { nodeMenu.AddItem (new GUIContent ("Execute"), false, delegate { this.active.Owner.SetNode (node); }); } nodeMenu.AddItem (FsmContent.makeTransition, false, delegate() { fromNode = node; }); if (!node.IsStartNode && !(node is AnyState)) { nodeMenu.AddItem (FsmContent.setAsDefault, false, delegate() { FsmEditorUtility.SetDefaultNode (node, FsmEditor.Active); }); } else { nodeMenu.AddDisabledItem (FsmContent.setAsDefault); } if (node.GetType () == typeof(State)) { State state = node as State; nodeMenu.AddItem (FsmContent.sequence, state.IsSequence, delegate() { state.IsSequence = !state.IsSequence; }); } if (node.GetType () != typeof(AnyState)) { nodeMenu.AddItem (FsmContent.moveToSubStateMachine, false, delegate() { StateMachine stateMachine = FsmEditorUtility.AddNode<StateMachine> (mousePosition, FsmEditor.Active); Pasteboard.Copy (selection); Pasteboard.Paste (mousePosition, stateMachine); foreach (Node mNode in selection) { if (!(mNode is AnyState)) { FsmEditorUtility.DeleteNode (mNode); } } selection.Clear (); UpdateUnitySelection (); EditorUtility.SetDirty (FsmEditor.Active); }); if (FsmEditor.Active.Parent != null) { nodeMenu.AddItem (FsmContent.moveToParentStateMachine, false, delegate() { Pasteboard.Copy (selection); Pasteboard.Paste (mousePosition, FsmEditor.Active.Parent); foreach (Node mNode in selection) { if (!(mNode is AnyState)) { FsmEditorUtility.DeleteNode (mNode); } } selection.Clear (); UpdateUnitySelection (); EditorUtility.SetDirty (FsmEditor.Active); }); } else { nodeMenu.AddDisabledItem (FsmContent.moveToParentStateMachine); } nodeMenu.AddItem (FsmContent.copy, false, delegate() { Pasteboard.Copy (selection); }); nodeMenu.AddItem (FsmContent.delete, false, delegate() { if (selection.Contains (node)) { foreach (Node mNode in selection) { if (!(mNode is AnyState)) { FsmEditorUtility.DeleteNode (mNode); } } selection.Clear (); UpdateUnitySelection (); } else { FsmEditorUtility.DeleteNode (node); } EditorUtility.SetDirty (FsmEditor.Active); }); } else { nodeMenu.AddDisabledItem (FsmContent.copy); nodeMenu.AddDisabledItem (FsmContent.delete); } nodeMenu.ShowAsContext (); Event.current.Use (); }
public static GenericMenu ExecutableContextMenu(ExecutableNode executable, Node node) { GenericMenu menu = new GenericMenu(); if (executable == null) { return(menu); } menu.AddItem(new GUIContent("Enable"), executable.IsEnabled, delegate() { executable.IsEnabled = !executable.IsEnabled; }); menu.AddSeparator(""); menu.AddItem(new GUIContent("Find Script"), false, delegate() { MonoScript[] monoScriptArray = (MonoScript[])Resources.FindObjectsOfTypeAll(typeof(MonoScript)); Selection.activeObject = monoScriptArray.ToList().Find(x => x.GetClass() == executable.GetType()); }); menu.AddItem(new GUIContent("Edit Script"), false, delegate() { MonoScript[] monoScriptArray = (MonoScript[])Resources.FindObjectsOfTypeAll(typeof(MonoScript)); Selection.activeObject = monoScriptArray.ToList().Find(x => x.GetClass() == executable.GetType()); AssetDatabase.OpenAsset(Selection.activeObject); }); menu.AddSeparator(""); bool moveDown = false; int currentIndex = -1; if (executable.GetType().IsSubclassOf(typeof(StateAction))) { State state = node as State; currentIndex = Array.IndexOf(state.Actions, executable); moveDown = currentIndex + 1 < state.Actions.Length; } else { currentIndex = Array.IndexOf(FsmEditor.SelectedTransition.Conditions, executable); moveDown = currentIndex + 1 < FsmEditor.SelectedTransition.Conditions.Length; } if (currentIndex - 1 >= 0) { menu.AddItem(new GUIContent("Move Up"), false, delegate() { if (executable.GetType().IsSubclassOf(typeof(StateAction))) { State state = node as State; state.Actions = ArrayUtility.MoveItem(state.Actions, currentIndex, currentIndex - 1); } else { FsmEditor.SelectedTransition.Conditions = ArrayUtility.MoveItem(FsmEditor.SelectedTransition.Conditions, currentIndex, currentIndex - 1); } NodeInspector.Dirty(); }); } else { menu.AddDisabledItem(new GUIContent("Move Up")); } if (moveDown) { menu.AddItem(new GUIContent("Move Down"), false, delegate() { if (executable.GetType().IsSubclassOf(typeof(StateAction))) { State state = node as State; state.Actions = ArrayUtility.MoveItem(state.Actions, currentIndex, currentIndex + 1); } else { FsmEditor.SelectedTransition.Conditions = ArrayUtility.MoveItem(FsmEditor.SelectedTransition.Conditions, currentIndex, currentIndex + 1); } NodeInspector.Dirty(); }); } else { menu.AddDisabledItem(new GUIContent("Move Down")); } menu.AddSeparator(""); menu.AddItem(new GUIContent("Copy"), false, delegate() { executableCopy = executable; }); if (executableCopy != null) { menu.AddItem(new GUIContent("Paste After"), false, delegate() { ExecutableNode dest = FsmUtility.Copy(executableCopy); if (dest.GetType().IsSubclassOf(typeof(StateAction))) { State state = node as State; state.Actions = ArrayUtility.Insert <StateAction>(state.Actions, (StateAction)dest, currentIndex + 1); } else { FsmEditor.SelectedTransition.Conditions = ArrayUtility.Insert <Condition>(FsmEditor.SelectedTransition.Conditions, (Condition)dest, currentIndex + 1); } FsmEditorUtility.ParentChilds(node); NodeInspector.Dirty(); }); menu.AddItem(new GUIContent("Paste Before"), false, delegate() { ExecutableNode dest = FsmUtility.Copy(executableCopy); if (dest.GetType().IsSubclassOf(typeof(StateAction))) { State state = node as State; state.Actions = ArrayUtility.Insert <StateAction>(state.Actions, (StateAction)dest, currentIndex); } else { FsmEditor.SelectedTransition.Conditions = ArrayUtility.Insert <Condition>(FsmEditor.SelectedTransition.Conditions, (Condition)dest, currentIndex); } FsmEditorUtility.ParentChilds(node); NodeInspector.Dirty(); }); menu.AddItem(new GUIContent("Replace"), false, delegate() { ExecutableNode dest = FsmUtility.Copy(executableCopy); if (dest.GetType().IsSubclassOf(typeof(StateAction))) { State state = node as State; FsmEditorUtility.DestroyImmediate(state.Actions[currentIndex]); state.Actions = ArrayUtility.RemoveAt <StateAction>(state.Actions, currentIndex); state.Actions = ArrayUtility.Insert <StateAction>(state.Actions, (StateAction)dest, currentIndex); } else { FsmEditorUtility.DestroyImmediate(FsmEditor.SelectedTransition.Conditions[currentIndex]); FsmEditor.SelectedTransition.Conditions = ArrayUtility.RemoveAt <Condition>(FsmEditor.SelectedTransition.Conditions, currentIndex); FsmEditor.SelectedTransition.Conditions = ArrayUtility.Insert <Condition>(FsmEditor.SelectedTransition.Conditions, (Condition)dest, currentIndex); } FsmEditorUtility.ParentChilds(node); NodeInspector.Dirty(); }); } else { menu.AddDisabledItem(new GUIContent("Paste After")); menu.AddDisabledItem(new GUIContent("Paste Before")); menu.AddDisabledItem(new GUIContent("Replace")); } menu.AddSeparator(""); menu.AddItem(new GUIContent("Remove"), false, delegate() { if (executable.GetType().IsSubclassOf(typeof(StateAction))) { State state = node as State; state.Actions = ArrayUtility.Remove <StateAction> (state.Actions, (StateAction)executable); } else { FsmEditor.SelectedTransition.Conditions = ArrayUtility.Remove <Condition>(FsmEditor.SelectedTransition.Conditions, (Condition)executable); } FsmEditorUtility.DestroyImmediate(executable); NodeInspector.Dirty(); }); return(menu); }
private void ResetActionList() { SerializedObject obj = new SerializedObject(state); SerializedProperty elements = obj.FindProperty("actions"); actionList = new ReorderableObjectList(obj, elements); actionList.drawHeaderCallback = delegate(Rect rect) { EditorGUI.LabelField(rect, "Actions"); }; actionList.onAddCallback = delegate(ReorderableObjectList list) { FsmGUIUtility.SubclassMenu <StateAction> (delegate(Type type){ StateAction action = (StateAction)ScriptableObject.CreateInstance(type); action.name = type.GetCategory() + "." + type.Name; action.hideFlags = HideFlags.HideInHierarchy; state.Actions = ArrayUtility.Add <StateAction> (state.Actions, action); if (EditorUtility.IsPersistent(state)) { AssetDatabase.AddObjectToAsset(action, state); AssetDatabase.SaveAssets(); } list.index = list.count; EditorUtility.SetDirty(state); }); }; actionList.drawElementCallback = delegate(int index, bool selected) { StateAction action = state.Actions [index]; bool enabled = action.IsEnabled; if (selected) { GUIStyle selectBackground = new GUIStyle("MeTransitionSelectHead") { stretchHeight = false, }; selectBackground.overflow = new RectOffset(-1, -2, -2, 2); GUILayout.BeginVertical(selectBackground); } action.IsOpen = GUIDrawer.ObjectTitlebar(action, action.IsOpen, ref enabled, FsmGUIUtility.ExecutableContextMenu(action, state)); if (selected) { GUILayout.EndVertical(); } action.IsEnabled = enabled; if (action.IsOpen) { GUIDrawer.OnGUI(action); } }; actionList.onRemoveCallback = delegate(ReorderableObjectList list) { StateAction action = state.Actions[list.index]; state.Actions = ArrayUtility.Remove <StateAction> (state.Actions, action); FsmEditorUtility.DestroyImmediate(action); list.index = list.index - 1; ErrorChecker.CheckForErrors(); EditorUtility.SetDirty(state); }; actionList.onContextClick = delegate(int index) { FsmGUIUtility.ExecutableContextMenu(state.Actions [index], state).ShowAsContext(); }; actionList.onHeaderContextClick = delegate() { GenericMenu menu = new GenericMenu(); if (state.Actions.Length > 0) { menu.AddItem(new GUIContent("Copy"), false, delegate { copy = new List <StateAction>(state.Actions); copyState = state; }); } else { menu.AddDisabledItem(new GUIContent("Copy")); } if (copy == null) { copy = new List <StateAction>(); } copy.RemoveAll(x => x == null); if (copy.Count > 0) { menu.AddItem(new GUIContent("Paste After"), false, delegate() { for (int i = 0; i < copy.Count; i++) { ExecutableNode dest = FsmUtility.Copy(copy[i]); state.Actions = ArrayUtility.Add <StateAction>(state.Actions, (StateAction)dest); FsmEditorUtility.ParentChilds(state); EditorUtility.SetDirty(state); // NodeInspector.Dirty(); ErrorChecker.CheckForErrors(); } }); menu.AddItem(new GUIContent("Paste Before"), false, delegate() { for (int i = 0; i < copy.Count; i++) { ExecutableNode dest = FsmUtility.Copy(copy[i]); state.Actions = ArrayUtility.Insert <StateAction>(state.Actions, (StateAction)dest, 0); FsmEditorUtility.ParentChilds(state); EditorUtility.SetDirty(state); // NodeInspector.Dirty(); ErrorChecker.CheckForErrors(); } }); if (copyState != state) { menu.AddItem(new GUIContent("Replace"), false, delegate() { for (int i = 0; i < state.Actions.Length; i++) { FsmEditorUtility.DestroyImmediate(state.Actions[i]); } state.Actions = new StateAction[0]; ResetActionList(); for (int i = 0; i < copy.Count; i++) { ExecutableNode dest = FsmUtility.Copy(copy[i]); state.Actions = ArrayUtility.Add <StateAction>(state.Actions, (StateAction)dest); FsmEditorUtility.ParentChilds(state); EditorUtility.SetDirty(state); // NodeInspector.Dirty(); ErrorChecker.CheckForErrors(); } }); } else { menu.AddDisabledItem(new GUIContent("Replace")); } } else { menu.AddDisabledItem(new GUIContent("Paste After")); menu.AddDisabledItem(new GUIContent("Paste Before")); menu.AddDisabledItem(new GUIContent("Replace")); } menu.ShowAsContext(); }; this.host.Repaint(); if (FsmEditor.instance != null) { FsmEditor.instance.Repaint(); } }
protected override void CanvasContextMenu () { if (currentEvent.type != EventType.MouseDown || currentEvent.button != 1 || currentEvent.clickCount != 1 || FsmEditor.Active == null){ return; } GenericMenu canvasMenu = new GenericMenu (); canvasMenu.AddItem (FsmContent.createState, false, delegate() { State state= FsmEditorUtility.AddNode<State>(mousePosition,FsmEditor.Active); state.IsStartNode=FsmEditor.Active.GetStartNode() == null; FsmEditorUtility.UpdateNodeColor(state); }); canvasMenu.AddItem (FsmContent.createSubFsm, false, delegate() { StateMachine stateMachine=FsmEditorUtility.AddNode<StateMachine>(mousePosition,FsmEditor.Active); stateMachine.IsStartNode=FsmEditor.Active.GetStartNode() == null; FsmEditorUtility.UpdateNodeColor(stateMachine); }); canvasMenu.AddItem (FsmContent.copy, false, delegate() { Pasteboard.Copy(new List<Node>(){FsmEditor.Active}); }); if (Pasteboard.CanPaste ()) { canvasMenu.AddItem (FsmContent.paste, false, delegate() { Pasteboard.Paste(mousePosition,FsmEditor.Active); }); } canvasMenu.AddSeparator (""); if (Selection.activeGameObject != null) { canvasMenu.AddItem (FsmContent.addToSelection, false, delegate() { foreach(GameObject go in Selection.gameObjects){ ICodeBehaviour behaviour = go.AddComponent<ICodeBehaviour>(); behaviour.stateMachine = FsmEditor.Active.Root; EditorUtility.SetDirty(behaviour); } SelectGameObject(Selection.activeGameObject); }); canvasMenu.AddItem (FsmContent.bindToGameObject, false, delegate() { foreach(GameObject go in Selection.gameObjects){ ICodeBehaviour behaviour = go.AddComponent<ICodeBehaviour>(); behaviour.stateMachine = (StateMachine)FsmUtility.Copy(FsmEditor.Active.Root);//FsmEditor.Active.Root; EditorUtility.SetDirty(behaviour); } SelectGameObject(Selection.activeGameObject); }); } else { canvasMenu.AddDisabledItem(FsmContent.addToSelection); canvasMenu.AddDisabledItem(FsmContent.bindToGameObject); } if (FsmEditor.Active.Root != null && !EditorUtility.IsPersistent(FsmEditor.Active.Root)) { canvasMenu.AddItem (FsmContent.saveAsAsset, false, delegate() { string mPath = EditorUtility.SaveFilePanelInProject ( "Save StateMachine as Asset", "New StateMachine.asset", "asset", ""); if(mPath != null){ StateMachine stateMachine=(StateMachine)FsmUtility.Copy(FsmEditor.Active.Root); AssetDatabase.CreateAsset(stateMachine,mPath); AssetDatabase.SaveAssets(); FsmEditorUtility.ParentChilds(stateMachine); } }); } else { canvasMenu.AddDisabledItem(FsmContent.saveAsAsset); } canvasMenu.ShowAsContext (); }
public void ResetTransitionList() { SerializedObject obj = new SerializedObject(node); SerializedProperty elements = obj.FindProperty("transitions"); transitionList = new ReorderableObjectList(obj, elements); transitionList.drawHeaderCallback = delegate(Rect rect) { EditorGUI.LabelField(rect, "Transitions"); EditorGUI.LabelField(new Rect(rect.width - 25, rect.y, 50, 20), "Mute"); }; transitionList.onSelectCallback = delegate(int index) { if (node.Transitions.Length > 0) { FsmEditor.SelectTransition(this.node.Transitions[index]); this.ResetConditionList(); } }; transitionList.onRemoveCallback = delegate(ReorderableObjectList list) { Transition transition = node.Transitions[list.index]; node.Transitions = ArrayUtility.Remove(node.Transitions, transition); FsmEditorUtility.DestroyImmediate(transition); list.index = Mathf.Clamp(list.index - 1, 0, list.count - 1); ErrorChecker.CheckForErrors(); EditorUtility.SetDirty(node); }; transitionList.drawElementCallback = delegate(int index, bool selected) { Transition transition = node.Transitions [index]; if (selected) { GUIStyle selectBackground = new GUIStyle("MeTransitionSelectHead") { stretchHeight = false, }; selectBackground.overflow = new RectOffset(-1, -2, -2, 2); GUILayout.BeginVertical(selectBackground); } GUILayout.BeginHorizontal(); for (int i = 0; i < transition.Conditions.Length; i++) { Condition condition = transition.Conditions[i]; if (ErrorChecker.HasErrors(condition)) { GUILayout.Label(FsmEditorStyles.errorIcon); break; } } GUILayout.Label(transition.FromNode.Name + " -> " + transition.ToNode.Name, selected?EditorStyles.whiteLabel:EditorStyles.label); GUILayout.FlexibleSpace(); transition.Mute = GUILayout.Toggle(transition.Mute, GUIContent.none, GUILayout.Width(15)); GUILayout.Space(22f); GUILayout.EndHorizontal(); if (selected) { GUILayout.EndVertical(); } }; transitionList.onReorderCallback = delegate(ReorderableObjectList list) { FsmEditor.SelectTransition(this.node.Transitions[list.index]); this.ResetConditionList(); }; transitionList.onContextClick = delegate(int index) { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Remove"), false, delegate() { Transition transition = node.Transitions[index]; node.Transitions = ArrayUtility.Remove(node.Transitions, transition); FsmEditorUtility.DestroyImmediate(transition); transitionList.index = Mathf.Clamp((index == transitionList.index?index - 1:(index < transitionList.index?transitionList.index - 1:transitionList.index)), 0, node.Transitions.Length - 1); ErrorChecker.CheckForErrors(); EditorUtility.SetDirty(node); }); menu.ShowAsContext(); }; this.ResetConditionList(); this.host.Repaint(); if (FsmEditor.instance != null) { FsmEditor.instance.Repaint(); } }
private void DrawVariables() { scroll = GUILayout.BeginScrollView(scroll); Dictionary <string, List <FsmVariable> > groupParameters = GetGroupVariables(); EditorGUIUtility.labelWidth = 110; foreach (var kvp in groupParameters) { bool foldout = EditorPrefs.GetBool(kvp.Key, false); bool state = EditorGUILayout.Foldout(foldout, kvp.Key); if (state != foldout) { EditorPrefs.SetBool(kvp.Key, state); } if (foldout) { for (int i = 0; i < groupParameters[kvp.Key].Count; i++) { FsmVariable parameter = groupParameters[kvp.Key][i]; if (parameter != null) { SerializedObject paramObject = new SerializedObject(parameter); SerializedProperty prop = paramObject.FindProperty("value"); GUILayout.BeginHorizontal(); GUILayout.Space(16f); string name = paramObject.FindProperty("name").stringValue; if (parameter is FsmGameObject) { GUI.changed = false; FsmGameObject mParam = parameter as FsmGameObject; if (string.IsNullOrEmpty(mParam.ScenePath)) { mParam.Value = (GameObject)EditorGUILayout.ObjectField(name, mParam.Value, typeof(UnityEngine.GameObject), true); } else { GUILayout.Label(name, GUILayout.Width(106)); GUILayout.Label(mParam.ScenePath, FsmEditorStyles.wrappedLabelLeft); GUILayout.FlexibleSpace(); } if (GUI.changed) { if (!EditorUtility.IsPersistent(mParam.Value) && mParam.Value is GameObject) { mParam.ScenePath = mParam.Value.name + "(" + EditorApplication.currentScene + ")"; SetGlobalGameObject mSet = mParam.Value.GetComponent <SetGlobalGameObject>(); if (mSet == null) { mSet = mParam.Value.AddComponent <SetGlobalGameObject>(); } mSet.variableName = mParam.Name; } EditorUtility.SetDirty(mParam); } } else { paramObject.Update(); if (prop != null) { EditorGUILayout.PropertyField(prop, new GUIContent(name), true); } paramObject.ApplyModifiedProperties(); } if (GUILayout.Button("down", EditorStyles.toolbarButton, GUILayout.Width(35))) { if (i < groupParameters[kvp.Key].Count) { int indexToMove = Array.FindIndex(globalVariables.Variables, x => x.Name == parameter.Name); globalVariables.Variables.Move(indexToMove, 0); EditorUtility.SetDirty(globalVariables); } } if (GUILayout.Button("up", EditorStyles.toolbarButton, GUILayout.Width(20))) { if (i > 0) { int indexToMove = Array.FindIndex(globalVariables.Variables, x => x.Name == parameter.Name); globalVariables.Variables.Move(indexToMove, 1); EditorUtility.SetDirty(globalVariables); } } if (GUILayout.Button(parameter.Group, EditorStyles.toolbarDropDown, GUILayout.Width(54))) { GenericMenu menu = new GenericMenu(); foreach (FsmVariable p in globalVariables.Variables) { string group = p.Group; FsmVariable mParam = parameter; menu.AddItem(new GUIContent(group), mParam.Group == group, delegate() { mParam.Group = group; }); } menu.ShowAsContext(); } if (GUILayout.Button(EditorGUIUtility.FindTexture("Toolbar Minus"), "label", GUILayout.Width(20))) { globalVariables.Variables = ArrayUtility.Remove(globalVariables.Variables, parameter); FsmEditorUtility.DestroyImmediate(parameter);; EditorUtility.SetDirty(globalVariables); } GUILayout.EndHorizontal(); } } } } GUILayout.EndScrollView(); }