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); }
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); } }
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(); }
private void OnGUI() { List <FsmError> errors = ErrorChecker.GetErrors(); if (selectedFsmErrors) { if (FsmEditor.instance != null) { errors = errors.FindAll(x => x.State.Parent == FsmEditor.Active).ToList(); } else { errors.Clear(); } } //Toolbar GUILayout.BeginHorizontal(EditorStyles.toolbar); if (GUILayout.Button("Refresh", EditorStyles.toolbarButton)) { ErrorChecker.CheckForErrors(); } GUILayout.FlexibleSpace(); if (GUILayout.Button("Selected FSM Only", (selectedFsmErrors?(GUIStyle)"TE toolbarbutton" : EditorStyles.toolbarButton))) { selectedFsmErrors = !selectedFsmErrors; ErrorChecker.CheckForErrors(); EditorPrefs.SetBool("SelectedFSMOnly", selectedFsmErrors); } GUILayout.EndHorizontal(); scroll = EditorGUILayout.BeginScrollView(scroll); for (int i = 0; i < errors.Count; i++) { FsmError error = errors[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(error.Type.ToString()); GUILayout.Label(error.State.Parent.Name + " : " + error.State.Name + " : " + error.ExecutableNode.name + (error.FieldInfo != null? " : " + error.FieldInfo.Name:"")); GUILayout.EndVertical(); Rect elementRect = new Rect(0, i * 19f * 2f, Screen.width, 19f * 2f); Event ev = Event.current; switch (ev.rawType) { case EventType.MouseDown: if (elementRect.Contains(Event.current.mousePosition)) { if (Event.current.button == 0) { index = i; if (FsmEditor.instance == null) { FsmEditor.ShowWindow(); } FsmEditor.SelectNode(error.State); Event.current.Use(); } } break; } } EditorGUILayout.EndScrollView(); }
public static void OpenFsmEditor() { FsmEditor.ShowWindow(); }