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);
        }
Пример #2
0
 private void Update()
 {
     if (globalVariables == null && !EditorApplication.isCompiling)
     {
         globalVariables = GlobalVariables.Load();
         if (globalVariables == null)
         {
             if (!System.IO.Directory.Exists(Application.dataPath + "/Resources"))
             {
                 AssetDatabase.CreateFolder("Assets", "Resources");
             }
             globalVariables = AssetCreator.CreateAsset <GlobalVariables>("Assets/Resources/" + GlobalVariables.assetName + ".asset");
             EditorUtility.DisplayDialog("Created GlobalVariables!",
                                         "Do not delete or rename the Resource folder and the GlobalVariables asset.", "Ok");
         }
         Array.Sort(globalVariables.Variables, (a, b) => a.Group.CompareTo(b.Group));
     }
 }
Пример #3
0
        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();
            }
        }