Exemplo n.º 1
0
 public override void OnEnter()
 {
     base.OnEnter();
     object[] mArray = array.Value;
     mArray      = ArrayUtility.Add <object> (mArray, variable.GetValue());
     array.Value = mArray;
     Finish();
 }
        private static Node[] CopyNodes(Node[] nodes, StateMachine parent)
        {
            List <Node> mNodes = new List <Node> ();

            foreach (Node original in nodes)
            {
                Type nodeType = original.GetType();

                Node dest = (Node)ScriptableObject.CreateInstance(nodeType);
                dest.color       = original.color;
                dest.comment     = original.comment;
                dest.Name        = original.Name;
                dest.Parent      = parent;
                dest.position    = original.position;
                dest.IsStartNode = original.IsStartNode;
                dest.hideFlags   = HideFlags.HideInHierarchy;

                if (typeof(State).IsAssignableFrom(nodeType))
                {
                    State state = dest as State;
                    state.IsSequence = (original as State).IsSequence;
                    state.Actions    = CopyExecutableNodes <StateAction> ((original as State).Actions, state.Root);
                }
                else
                {
                    StateMachine stateMachine = dest as StateMachine;
                    stateMachine.Nodes = CopyNodes((original as StateMachine).Nodes, stateMachine);
                }
                mNodes.Add(dest);
            }

            foreach (Node original in nodes)
            {
                foreach (Transition origTransition in original.Transitions)
                {
                    Transition destTrasition = ScriptableObject.CreateInstance <Transition> ();
                    Node       dest          = mNodes.Find(x => x.Name == original.Name);
                    destTrasition.hideFlags  = HideFlags.HideInHierarchy;
                    destTrasition.ToNode     = mNodes.ToList().Find(x => x.Name == origTransition.ToNode.Name);
                    destTrasition.FromNode   = dest;
                    destTrasition.Conditions = CopyExecutableNodes <Condition> (origTransition.Conditions, original.Root);
                    dest.Transitions         = ArrayUtility.Add <Transition> (dest.Transitions, destTrasition);
                }
            }

            return(mNodes.ToArray());
        }
        public static Node Copy(Node original)
        {
            Node dest = (Node)ScriptableObject.CreateInstance(original.GetType());

            dest.color       = original.color;
            dest.comment     = original.comment;
            dest.Name        = original.Name;
            dest.position    = original.position;
            dest.Parent      = original.Parent;
            dest.hideFlags   = original.hideFlags;
            dest.IsStartNode = original.IsStartNode;

            if (original is StateMachine)
            {
                StateMachine destFsm = dest as StateMachine;
                StateMachine origFsm = original as StateMachine;

                destFsm.Variables = CopyVariables(origFsm.Variables);
                destFsm.Nodes     = CopyNodes(origFsm.Nodes, destFsm);
            }
            else if (original is State)
            {
                State destState = dest as State;
                State origState = original as State;
                destState.IsSequence = origState.IsSequence;
                destState.Actions    = CopyExecutableNodes <StateAction> (origState.Actions, destState.Root);
            }

            foreach (Transition origTransition in original.Transitions)
            {
                Node toNode = dest.Parent.Nodes.ToList().Find(x => x.Name == origTransition.ToNode.Name);
                if (toNode != null)
                {
                    Transition destTrasition = ScriptableObject.CreateInstance <Transition> ();
                    destTrasition.hideFlags  = HideFlags.HideInHierarchy;
                    destTrasition.ToNode     = toNode;
                    destTrasition.FromNode   = dest;
                    destTrasition.Conditions = CopyExecutableNodes <Condition> (origTransition.Conditions, original.Root);
                    dest.Transitions         = ArrayUtility.Add <Transition> (dest.Transitions, destTrasition);
                }
            }
            return(dest);
        }
Exemplo n.º 4
0
 public override void OnEnter()
 {
     array.Value = ArrayUtlity.Insert <object> (array.Value, element.GetValue(), index.Value);
     Finish();
 }
Exemplo n.º 5
0
 public override void OnEnter()
 {
     base.OnEnter();
     array.Value = ArrayUtility.RemoveAt <object> (array.Value, index.Value);
     Finish();
 }
Exemplo n.º 6
0
 public override void OnEnter()
 {
     array = ArrayUtility.Add <object> (array, variable.GetValue());
     Finish();
 }