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 DoFsmSelection(Rect rect){ if (FsmEditor.Root == null) { return; } GUILayout.BeginArea (rect,EditorStyles.toolbar); GUILayout.BeginHorizontal (); StateMachine parent = FsmEditor.Active; List<StateMachine> breadcrumbs = new List<StateMachine> (); while (parent != null) { breadcrumbs.Add(parent); parent=parent.Parent; } breadcrumbs.Reverse (); for (int i=0; i<breadcrumbs.Count; i++) { GUIStyle style=i==0?FsmEditorStyles.breadcrumbLeft:FsmEditorStyles.breadcrumbMiddle; GUIContent content = new GUIContent (breadcrumbs[i].Name); float width = style.CalcSize (content).x; width = Mathf.Clamp (width, 80f, width); if (GUILayout.Button (content, style, GUILayout.Width (width))) { FsmEditor.SelectStateMachine(breadcrumbs[i]); } } GUILayout.EndHorizontal (); GUILayout.EndArea (); }
private void SelectStateMachineMenu(StateMachine stateMachine, ref GenericMenu toolsMenu) { if (stateMachine != null) { StateMachine[] stateMachines = stateMachine.StateMachinesRecursive; if (stateMachines.Length > 0) { toolsMenu.AddItem(new GUIContent(stateMachine.Name + "/" + stateMachine.Name), false, delegate() { FsmEditor.SelectStateMachine(stateMachine); }); foreach (StateMachine mStateMachine in stateMachines) { StateMachine kStateMachine = mStateMachine; toolsMenu.AddItem(new GUIContent(stateMachine.Name + "/" + kStateMachine.Name), false, delegate() { FsmEditor.SelectStateMachine(kStateMachine); }); } } else { toolsMenu.AddItem(new GUIContent(stateMachine.Name), false, delegate() { FsmEditor.SelectStateMachine(stateMachine); }); } } }
public override void OnInspectorGUI() { master.components.RemoveAll(x => x.component == null); for (int i = 0; i < master.components.Count; i++) { ICodeMaster.ComponentModel component = master.components [i]; if (component.component.stateMachine != null) { GUILayout.BeginHorizontal(); component.show = GUILayout.Toggle(component.show, "", Toggle); component.component.hideFlags = component.show ? HideFlags.None : HideFlags.HideInInspector; GUILayout.FlexibleSpace(); if (GUILayout.Button(EditorGUIUtility.FindTexture("UnityEditor.Graphs.AnimatorControllerTool"), Button)) { FsmEditor.ShowWindow(); if (FsmEditor.instance != null) { FsmEditor.SelectStateMachine(component.component.stateMachine); } } GUILayout.EndHorizontal(); GUILayout.Label(master.components [i].component.stateMachine.name, Line); } } EditorUtility.SetDirty(master); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); SerializedProperty property = serializedObject.FindProperty("stateMachine"); if (property.objectReferenceValue != null) { StateMachine fsm = property.objectReferenceValue as StateMachine; showInfo = EditorGUILayout.Foldout(showInfo, "Info"); if (showInfo) { int indent = EditorGUI.indentLevel; EditorGUI.indentLevel++; GUILayout.Label("StateMachines (" + (fsm.StateMachinesRecursive.Length + 1) + ")"); GUILayout.Label("States (" + fsm.StatesRecursive.Length + ")"); GUILayout.Label("Actions (" + fsm.ActionsRecursive.Length + ")"); GUILayout.Label("Variables (" + fsm.VisibleVariables.Length + ")"); EditorGUI.indentLevel = indent; } showVariables = EditorGUILayout.Foldout(showVariables, "Variables"); if (showVariables) { FsmVariable[] variables = fsm.VisibleVariables; for (int i = 0; i < variables.Length; i++) { SerializedObject obj = new SerializedObject(variables[i]); obj.Update(); EditorGUILayout.PropertyField(obj.FindProperty("value"), new GUIContent(obj.FindProperty("name").stringValue)); obj.ApplyModifiedProperties(); } } } bool flag = GUI.enabled; GUI.enabled = !(property.objectReferenceValue == null || !EditorUtility.IsPersistent(property.objectReferenceValue)); if (GUILayout.Button("Bind to GameObject")) { serializedObject.Update(); StateMachine stateMachine = (StateMachine)FsmUtility.Copy((StateMachine)property.objectReferenceValue); property.objectReferenceValue = stateMachine; serializedObject.ApplyModifiedProperties(); if (FsmEditor.instance != null) { FsmEditor.SelectStateMachine(stateMachine); } } GUI.enabled = flag; if (GUILayout.Button("Open in Editor")) { FsmEditor.ShowWindow(); if (FsmEditor.instance != null) { FsmEditor.SelectStateMachine((StateMachine)property.objectReferenceValue); } } }
public virtual void OnDoubleClick(string guid, Rect rect) { if (Event.current.type == EventType.MouseDown && Event.current.clickCount == 2 && rect.Contains(Event.current.mousePosition)) { FsmEditor.ShowWindow(); FsmEditor.SelectStateMachine((StateMachine)target); } }
public static void SelectNode(Node node){ if (FsmEditor.instance == null ) { return; } if (FsmEditor.instance.active != node.Parent) { FsmEditor.SelectStateMachine(node.Parent); } FsmEditor.instance.selection.Clear (); FsmEditor.instance.selection.Add (node); FsmEditor.instance.UpdateUnitySelection (); FsmEditor.instance.Repaint (); }
public static void SelectGameObject(GameObject gameObject){ if (FsmEditor.instance == null){ //|| FsmEditor.ActiveGameObject == gameObject) { return; } if (!PreferencesEditor.GetBool(Preference.LockSelection) && gameObject != null) { ICodeBehaviour behaviour = gameObject.GetComponent<ICodeBehaviour> (); if(behaviour != null && behaviour.stateMachine != null){ FsmEditor.instance.activeGameObject=behaviour.gameObject; FsmEditor.SelectStateMachine(behaviour.stateMachine); } } }
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(); } }
private void OnGUI() { GUILayout.BeginHorizontal(EditorStyles.toolbar); if (GUILayout.Button("Refresh", EditorStyles.toolbarButton)) { FindFsms(); } GUILayout.FlexibleSpace(); FsmTool.Loaction mloc = (FsmTool.Loaction)EditorGUILayout.EnumPopup(location, EditorStyles.toolbarPopup, GUILayout.Width(100f)); if (location != mloc) { location = mloc; FindFsms(); } GUILayout.EndHorizontal(); scroll = EditorGUILayout.BeginScrollView(scroll); for (int i = 0; i < fsms.Length; i++) { StateMachine fsm = fsms[i]; GUIStyle style = FsmEditorStyles.elementBackground; if (i == index) { style = new GUIStyle("MeTransitionSelectHead") { stretchHeight = false, }; style.overflow = new RectOffset(-1, -2, -2, 2); } GUILayout.BeginVertical(style); GUILayout.Label(location == Loaction.Project? AssetDatabase.GetAssetPath(fsm):targets[i] + " : " + fsm.Name); Rect elementRect = GUILayoutUtility.GetLastRect(); Event ev = Event.current; switch (ev.rawType) { case EventType.MouseDown: if (elementRect.Contains(Event.current.mousePosition)) { if (Event.current.button == 0) { DragAndDrop.objectReferences = new Object[1] { fsm }; dragIndex = i; Event.current.Use(); } } break; case EventType.MouseUp: if (elementRect.Contains(Event.current.mousePosition)) { if (Event.current.button == 0) { index = i; if (FsmEditor.instance == null) { FsmEditor.ShowWindow(); } if (location == Loaction.Scene) { FsmEditor.SelectGameObject(targets[i]); } FsmEditor.SelectStateMachine(fsm); Event.current.Use(); } } dragIndex = -1; break; case EventType.MouseDrag: if (dragIndex != -1) { DragAndDrop.StartDrag("Drag"); dragIndex = -1; Event.current.Use(); } break; } GUILayout.EndVertical(); } EditorGUILayout.EndScrollView(); }