Inheritance: UnityEditor.Graphs.AnimationStateMachine.Node
Esempio n. 1
0
        private bool MoveSelectionTo(StateMachineNode targetSM)
        {
            bool flag = false;
            List <UnityEngine.Object> list = new List <UnityEngine.Object> {
                this.rootStateMachine
            };

            foreach (ChildAnimatorStateMachine machine in this.rootStateMachine.stateMachinesRecursive)
            {
                list.Add(machine.stateMachine);
            }
            foreach (UnityEditor.Graphs.AnimationStateMachine.Node node in base.selection)
            {
                if (node is StateNode)
                {
                    list.Add((node as StateNode).state);
                }
            }
            Undo.RegisterCompleteObjectUndo(list.ToArray(), "Move in StateMachine");
            foreach (UnityEditor.Graphs.AnimationStateMachine.Node node2 in base.selection)
            {
                if (node2 is StateNode)
                {
                    this.activeStateMachine.MoveState((node2 as StateNode).state, targetSM.stateMachine);
                }
                else if (node2 is StateMachineNode)
                {
                    this.activeStateMachine.MoveStateMachine((node2 as StateMachineNode).stateMachine, targetSM.stateMachine);
                }
                flag = true;
            }
            return(flag);
        }
Esempio n. 2
0
        private void CreateSelectorEdges(AnimatorTransition transition, AnimatorStateMachine owner, AnimatorStateMachine sourceStateMachine)
        {
            Node node = this.FindNodeForEdges(sourceStateMachine);

            if (node is EntryNode)
            {
                return;
            }
            Node dstNode = null;

            if (transition.destinationStateMachine != null)
            {
                dstNode = this.FindNodeForEdges(transition.destinationStateMachine);
            }
            else if (transition.destinationState)
            {
                dstNode = this.FindNodeForEdges(transition.destinationState);
            }
            else if (transition.isExit)
            {
                dstNode = this.m_ExitNode;
            }
            StateMachineNode stateMachineNode = node as StateMachineNode;

            if (transition.isExit && node && stateMachineNode != null && stateMachineNode.stateMachine != sourceStateMachine)
            {
                return;
            }
            this.CreateEdges(node, dstNode, new TransitionEditionContext(transition, null, sourceStateMachine, owner));
        }
Esempio n. 3
0
 public override void Connect(UnityEditor.Graphs.AnimationStateMachine.Node toNode, UnityEditor.Graphs.Edge edge)
 {
     if (toNode is StateNode)
     {
         base.graphGUI.stateMachineGraph.rootStateMachine.AddAnyStateTransition((toNode as StateNode).state);
         base.graphGUI.stateMachineGraph.RebuildGraph();
     }
     if (toNode is StateMachineNode)
     {
         StateMachineNode node = toNode as StateMachineNode;
         if (node.stateMachine != base.graphGUI.parentStateMachine)
         {
             UnityEditor.Graphs.AnimationStateMachine.Node.GenericMenuForStateMachineNode(toNode as StateMachineNode, true, delegate(object data) {
                 if (data is AnimatorState)
                 {
                     base.graphGUI.stateMachineGraph.rootStateMachine.AddAnyStateTransition(data as AnimatorState);
                 }
                 else if (data is AnimatorStateMachine)
                 {
                     base.graphGUI.stateMachineGraph.rootStateMachine.AddAnyStateTransition(data as AnimatorStateMachine);
                 }
                 base.graphGUI.stateMachineGraph.RebuildGraph();
             });
         }
     }
     if (toNode is EntryNode)
     {
         base.graphGUI.stateMachineGraph.rootStateMachine.AddAnyStateTransition(base.graphGUI.activeStateMachine);
     }
 }
Esempio n. 4
0
 public override void Connect(Node toNode, Edge edge)
 {
     if (toNode is StateNode)
     {
         this.graphGUI.stateMachineGraph.rootStateMachine.AddAnyStateTransition((toNode as StateNode).state);
         this.graphGUI.stateMachineGraph.RebuildGraph();
     }
     if (toNode is StateMachineNode)
     {
         StateMachineNode stateMachineNode = toNode as StateMachineNode;
         if (stateMachineNode.stateMachine != this.graphGUI.parentStateMachine)
         {
             Node.GenericMenuForStateMachineNode(toNode as StateMachineNode, true, delegate(object data)
             {
                 if (data is AnimatorState)
                 {
                     this.graphGUI.stateMachineGraph.rootStateMachine.AddAnyStateTransition(data as AnimatorState);
                 }
                 else if (data is AnimatorStateMachine)
                 {
                     this.graphGUI.stateMachineGraph.rootStateMachine.AddAnyStateTransition(data as AnimatorStateMachine);
                 }
                 this.graphGUI.stateMachineGraph.RebuildGraph();
             });
         }
     }
     if (toNode is EntryNode)
     {
         this.graphGUI.stateMachineGraph.rootStateMachine.AddAnyStateTransition(this.graphGUI.activeStateMachine);
     }
 }
Esempio n. 5
0
 private void CreateSelectorEdges(AnimatorTransition transition, AnimatorStateMachine owner, AnimatorStateMachine sourceStateMachine)
 {
     UnityEditor.Graphs.AnimationStateMachine.Node srcNode = this.FindNodeForEdges(sourceStateMachine);
     if (!(srcNode is EntryNode))
     {
         UnityEditor.Graphs.AnimationStateMachine.Node dstNode = null;
         if (transition.destinationStateMachine != null)
         {
             dstNode = this.FindNodeForEdges(transition.destinationStateMachine);
         }
         else if (transition.destinationState != null)
         {
             dstNode = this.FindNodeForEdges(transition.destinationState);
         }
         else if (transition.isExit)
         {
             dstNode = this.m_ExitNode;
         }
         StateMachineNode node3 = srcNode as StateMachineNode;
         if ((!transition.isExit || (srcNode == null)) || ((node3 == null) || (node3.stateMachine == sourceStateMachine)))
         {
             this.CreateEdges(srcNode, dstNode, new TransitionEditionContext(transition, null, sourceStateMachine, owner));
         }
     }
 }
Esempio n. 6
0
        private void CreateParentStateMachineNode()
        {
            StateMachineNode node = this.CreateAndAddNode <StateMachineNode>("(Up) ", this.activeStateMachine.parentStateMachinePosition);

            node.stateMachine = this.parentStateMachine;
            node.style        = "node hex";
            if (((this.rootStateMachine.defaultState != null) && this.HasState(this.parentStateMachine, this.rootStateMachine.defaultState, true)) && !this.HasState(this.activeStateMachine, this.rootStateMachine.defaultState, true))
            {
                node.color = UnityEditor.Graphs.Styles.Color.Orange;
            }
            this.m_StateMachineNodeLookup.Add(this.parentStateMachine, node);
        }
Esempio n. 7
0
        private void CreateNodeFromStateMachine(ChildAnimatorStateMachine subStateMachine)
        {
            StateMachineNode node = this.CreateAndAddNode <StateMachineNode>("", subStateMachine.position);

            node.stateMachine = subStateMachine.stateMachine;
            node.style        = "node hex";
            if ((this.rootStateMachine.defaultState != null) && this.HasState(subStateMachine.stateMachine, this.rootStateMachine.defaultState, true))
            {
                node.color = UnityEditor.Graphs.Styles.Color.Orange;
            }
            this.m_StateMachineNodeLookup.Add(subStateMachine.stateMachine, node);
        }
Esempio n. 8
0
        private void CreateParentStateMachineNode()
        {
            StateMachineNode stateMachineNode = this.CreateAndAddNode <StateMachineNode>("(Up) ", this.activeStateMachine.parentStateMachinePosition);

            stateMachineNode.stateMachine = this.parentStateMachine;
            stateMachineNode.style        = "node hex";
            if (this.rootStateMachine.defaultState && this.HasState(this.parentStateMachine, this.rootStateMachine.defaultState, true) && !this.HasState(this.activeStateMachine, this.rootStateMachine.defaultState, true))
            {
                stateMachineNode.color = Styles.Color.Orange;
            }
            this.m_StateMachineNodeLookup.Add(this.parentStateMachine, stateMachineNode);
        }
Esempio n. 9
0
        private void CreateNodeFromStateMachine(ChildAnimatorStateMachine subStateMachine)
        {
            StateMachineNode stateMachineNode = this.CreateAndAddNode <StateMachineNode>(string.Empty, subStateMachine.position);

            stateMachineNode.stateMachine = subStateMachine.stateMachine;
            stateMachineNode.style        = "node hex";
            if (this.rootStateMachine.defaultState && this.HasState(subStateMachine.stateMachine, this.rootStateMachine.defaultState, true))
            {
                stateMachineNode.color = Styles.Color.Orange;
            }
            this.m_StateMachineNodeLookup.Add(subStateMachine.stateMachine, stateMachineNode);
        }
Esempio n. 10
0
        private void ReadStateMachinePosition(StateMachineNode stateMachineNode)
        {
            Vector2 vector;

            if (stateMachineNode.stateMachine == this.parentStateMachine)
            {
                vector = this.activeStateMachine.parentStateMachinePosition;
            }
            else
            {
                vector = this.activeStateMachine.GetStateMachinePosition(stateMachineNode.stateMachine);
            }
            stateMachineNode.position.x = vector.x;
            stateMachineNode.position.y = vector.y;
        }
Esempio n. 11
0
        private bool IsCurrentStateMachineNodeLiveLinked(UnityEditor.Graphs.AnimationStateMachine.Node n)
        {
            StateMachineNode node = n as StateMachineNode;

            if (node != null)
            {
                AnimatorState currentState = this.liveLinkInfo.currentState;
                bool          flag         = this.activeStateMachine.HasState(currentState, true);
                bool          flag2        = node.stateMachine.HasState(currentState, true);
                bool          flag3        = node.stateMachine.HasStateMachine(this.activeStateMachine, false);
                if (((flag3 && flag2) && !flag) || (!flag3 && flag2))
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 12
0
        public static void GenericMenuForStateMachineNode(StateMachineNode toStateMachineNode, bool showStateMachine, GenericMenu.MenuFunction2 func)
        {
            AnimatorStateMachine             parentStateMachine = null;
            List <ChildAnimatorState>        stateList          = new List <ChildAnimatorState>();
            List <ChildAnimatorStateMachine> stateMachineList   = new List <ChildAnimatorStateMachine>();

            PopulateSubNodeList(toStateMachineNode, ref stateList, ref stateMachineList, ref parentStateMachine);
            if ((stateList.Count == 0) && (stateMachineList.Count == 1))
            {
                ChildAnimatorStateMachine machine2 = stateMachineList[0];
                func(machine2.stateMachine);
            }
            else
            {
                GenericMenu menu = new GenericMenu();
                foreach (ChildAnimatorState state in stateList)
                {
Esempio n. 13
0
        private bool IsCurrentStateMachineNodeLiveLinked(Node n)
        {
            StateMachineNode stateMachineNode = n as StateMachineNode;

            if (stateMachineNode != null)
            {
                AnimatorState currentState = this.liveLinkInfo.currentState;
                bool          flag         = this.activeStateMachine.HasState(currentState, true);
                bool          flag2        = stateMachineNode.stateMachine.HasState(currentState, true);
                bool          flag3        = stateMachineNode.stateMachine.HasStateMachine(this.activeStateMachine, false);
                if ((flag3 && flag2 && !flag) || (!flag3 && flag2))
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 14
0
        public static void GenericMenuForStateMachineNode(StateMachineNode toStateMachineNode, bool showStateMachine, GenericMenu.MenuFunction2 func)
        {
            AnimatorStateMachine             y     = null;
            List <ChildAnimatorState>        list  = new List <ChildAnimatorState>();
            List <ChildAnimatorStateMachine> list2 = new List <ChildAnimatorStateMachine>();

            Node.PopulateSubNodeList(toStateMachineNode, ref list, ref list2, ref y);
            if (list.Count == 0 && list2.Count == 1)
            {
                func(list2[0].stateMachine);
                return;
            }
            GenericMenu genericMenu = new GenericMenu();

            foreach (ChildAnimatorState current in list)
            {
                string text = current.state.name;
                AnimatorStateMachine currentParent = current.state.FindParent(AnimatorControllerTool.tool.stateMachineGraph.rootStateMachine);
                while (currentParent != null && currentParent != y)
                {
                    text          = text.Insert(0, currentParent.name + "/");
                    currentParent = list2.Find((ChildAnimatorStateMachine sm) => sm.stateMachine.IsDirectParent(currentParent)).stateMachine;
                }
                if (list.Count > 0 && list2.Count > 0 && showStateMachine)
                {
                    text = text.Insert(0, "States/");
                }
                genericMenu.AddItem(new GUIContent(text), false, func, current.state);
            }
            if (showStateMachine)
            {
                foreach (ChildAnimatorStateMachine current2 in list2)
                {
                    string text2 = current2.stateMachine.name;
                    if (list.Count > 0 && list2.Count > 0)
                    {
                        text2 = text2.Insert(0, "StateMachine/");
                    }
                    genericMenu.AddItem(new GUIContent(text2), false, func, current2.stateMachine);
                }
            }
            genericMenu.ShowAsContext();
        }
Esempio n. 15
0
        private void SetHoveredStateMachine()
        {
            Vector2 mousePosition = Event.current.mousePosition;

            this.m_HoveredStateMachineNode = null;
            using (List <UnityEditor.Graphs.Node> .Enumerator enumerator = this.m_Graph.nodes.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Node             node             = (Node)enumerator.Current;
                    StateMachineNode stateMachineNode = node as StateMachineNode;
                    if (stateMachineNode && stateMachineNode.position.Contains(mousePosition) && !this.selection.Contains(stateMachineNode))
                    {
                        this.m_HoveredStateMachineNode = stateMachineNode;
                        break;
                    }
                }
            }
        }
Esempio n. 16
0
        private static void PopulateSubNodeList(StateMachineNode toStateMachineNode, ref List <ChildAnimatorState> stateList, ref List <ChildAnimatorStateMachine> stateMachineList, ref AnimatorStateMachine parentStateMachine)
        {
            if (toStateMachineNode.stateMachine == AnimatorControllerTool.tool.stateMachineGraph.parentStateMachine)
            {
                stateList = AnimatorControllerTool.tool.stateMachineGraph.rootStateMachine.statesRecursive;
                stateList.RemoveAll((ChildAnimatorState s) => AnimatorControllerTool.tool.stateMachineGraph.activeStateMachine.HasState(s.state));
                stateMachineList = AnimatorControllerTool.tool.stateMachineGraph.rootStateMachine.stateMachinesRecursive;
                stateMachineList.RemoveAll((ChildAnimatorStateMachine s) => AnimatorControllerTool.tool.stateMachineGraph.activeStateMachine.HasStateMachine(s.stateMachine) || AnimatorControllerTool.tool.stateMachineGraph.activeStateMachine == s.stateMachine);
                parentStateMachine = AnimatorControllerTool.tool.stateMachineGraph.rootStateMachine;
            }
            else
            {
                parentStateMachine = toStateMachineNode.stateMachine;
                stateList          = toStateMachineNode.stateMachine.statesRecursive;
                stateMachineList   = parentStateMachine.stateMachinesRecursive;
            }
            ChildAnimatorStateMachine item = default(ChildAnimatorStateMachine);

            item.stateMachine = parentStateMachine;
            stateMachineList.Add(item);
        }
Esempio n. 17
0
        private bool MoveSelectionTo(StateMachineNode targetSM)
        {
            bool result = false;
            List <UnityEngine.Object> list = new List <UnityEngine.Object>();

            list.Add(this.rootStateMachine);
            foreach (ChildAnimatorStateMachine current in this.rootStateMachine.stateMachinesRecursive)
            {
                list.Add(current.stateMachine);
            }
            using (List <UnityEditor.Graphs.Node> .Enumerator enumerator2 = this.selection.GetEnumerator())
            {
                while (enumerator2.MoveNext())
                {
                    Node node = (Node)enumerator2.Current;
                    if (node is StateNode)
                    {
                        list.Add((node as StateNode).state);
                    }
                }
            }
            Undo.RegisterCompleteObjectUndo(list.ToArray(), "Move in StateMachine");
            using (List <UnityEditor.Graphs.Node> .Enumerator enumerator3 = this.selection.GetEnumerator())
            {
                while (enumerator3.MoveNext())
                {
                    Node node2 = (Node)enumerator3.Current;
                    if (node2 is StateNode)
                    {
                        this.activeStateMachine.MoveState((node2 as StateNode).state, targetSM.stateMachine);
                    }
                    else if (node2 is StateMachineNode)
                    {
                        this.activeStateMachine.MoveStateMachine((node2 as StateMachineNode).stateMachine, targetSM.stateMachine);
                    }
                    result = true;
                }
            }
            return(result);
        }