Exemplo n.º 1
0
        public static StateGraph WithStart()
        {
            var stateGraph = new StateGraph();

            var startState = FlowState.WithEnterUpdateExit();

            startState.isStart          = true;
            startState.nest.embed.title = "Start";
            startState.position         = new Vector2(-86, -15);

            stateGraph.states.Add(startState);

            return(stateGraph);
        }
Exemplo n.º 2
0
        private bool CreateStateGraphAsset(GameObject gameObject = null, bool updateName = false)
        {
            var path = EditorUtility.SaveFilePanelInProject("Save Graph", "New State Graph", "asset", null);

            if (string.IsNullOrEmpty(path))
            {
                return(false);
            }

            VSUsageUtility.isVisualScriptingUsed = true;

            var macro       = (IMacro)CreateInstance(typeof(StateGraphAsset));
            var macroObject = (UnityObject)macro;

            macro.graph = StateGraph.WithStart();

            if (gameObject != null)
            {
                StateMachine stateMachine = gameObject.AddComponent <StateMachine>();

                stateMachine.nest.macro = (StateGraphAsset)macro;
            }

            string filename = Path.GetFileNameWithoutExtension(path);

            if (updateName)
            {
                gameObject.name = filename;
            }

            macroObject.name = filename;

            AssetDatabase.CreateAsset(macroObject, path);

            bool shouldSetSceneAsDirty = gameObject != null;

            OpenGraphFromPath(path, shouldSetSceneAsDirty);

            return(true);
        }