private void DrawTransitions()
 {
     Handles.BeginGUI();
     foreach (LZFighterStateTransition t in GetCurrentTransitions())
     {
         StateMachineNode source     = machine[t.source];
         StateMachineNode target     = machine[t.target];
         Vector2          startP     = source.nodeRect.center;
         Vector2          endP       = target.nodeRect.center;
         Vector2          dir        = endP - startP;
         Vector2          rotatedDir = dir.normalized.Rotated(90);
         startP += rotatedDir * 7;
         endP   += rotatedDir * 7;
         if (selectedTransitions.Contains(t) && selectedType == SELECTED_TYPE.TRANSITION)
         {
             Handles.color = Color.cyan;
         }
         else
         {
             Handles.color = Color.white;
         }
         Handles.DrawLine(startP, endP);
         GUITools.DrawArrow(startP + dir / 2f + dir.normalized * 5f, dir.normalized);
         Handles.color = Color.white;
     }
     if (state == STATE.MAKING_TRANSITION)
     {
         Handles.DrawLine(transitionStart.nodeRect.position + transitionStart.nodeRect.size / 2f, Event.current.mousePosition);
     }
     Handles.EndGUI();
 }
示例#2
0
    private void DrawShortcut(StateMachineNode node)
    {
        StateMachineNode target = fighter.stateMachine.states[node.Target];

        node.name = target.name;
        DrawState(target);
    }
    private void OnClickAddNode(Vector2 mousePosition, LZFighter fighter)
    {
        /*string path = AssetDatabase.GetAssetPath(fighter);
         * string filename = Path.GetFileNameWithoutExtension(path);
         * string directory = Path.GetDirectoryName(path);
         * if (!AssetDatabase.IsValidFolder(directory + "/" + filename)) {
         *  AssetDatabase.CreateFolder(directory, filename);
         * }*/
        StateMachineNode newState = new StateMachineNode();

        newState.nodeRect.position = mousePosition;
        int id = machine.states.Add(newState);

        if (treePath.Count > 0)
        {
            StateMachineNode parent = machine.states[treePath[treePath.Count - 1]];
            newState.parent = treePath[treePath.Count - 1];
            parent.containedNodes.Add(id);
            if (parent.containedNodes.Count == 1)
            {
                parent.startState = id;
            }
        }

        /*AssetDatabase.CreateAsset(newState, directory + "/" + filename + "/" + fighter.states.Count + ".asset");
         * Debug.Log(Path.GetDirectoryName(path));*/
    }
示例#4
0
        /// <summary>Triggers a transition to a new state via a specified link.</summary>
        /// <param name="node">The state node to transition to.</param>
        /// <param name="link">The link which triggered this new state.</param>
        public void Transition(StateMachineNode node, StateMachineLink link)
        {
            var e = new TransitionEventArgs(this.currentNode, node, link);

            nodeTime         = 0f;
            this.currentNode = node;
            OnTransition?.Invoke(this, e);
        }
 public void GenerateData(StateMachineNode stateMachineNode, Dictionary <StateNodeUI, State> stateMap)
 {
     if (ExitConnections.Count > 0)
     {
         stateMachineNode.EntryState = stateMap[(StateNodeUI)ExitConnections[0].Destination];
     }
     else if (stateMap.Count > 0)
     {
         stateMachineNode.EntryState = stateMap.Values.ElementAt(0);
     }
 }
    public void ProcessEvents(StateMachineNode fighterState)
    {
        Event ev   = Event.current;
        Rect  rect = new Rect(Vector2.zero, fighterState.nodeRect.size);

        switch (ev.type)
        {
        case EventType.MouseDown:
            if (ev.button == 0 && rect.Contains(ev.mousePosition))
            {
                if (ev.clickCount > 1)
                {
                    int index = machine.states.FindIndex((s) => s == fighterState);
                    treePath.Add(index);
                    if (OnNodeSelected != null)
                    {
                        OnNodeSelected.Invoke(index);
                    }
                    ev.Use();
                    return;
                }
                fighterState.isDragged = true;
                selectedType           = SELECTED_TYPE.STATE;
                if (!ev.shift)
                {
                    selectedStates.Clear();
                }
                selectedTransitions.Clear();

                selectedStates.Add(fighterState);
                hasSelected = true;
                ev.Use();
                LZFighterEditor.RepaintWindow();
                GUI.FocusControl("Node");
            }
            if (ev.button == 1)
            {
                BeginTransition(fighterState);
                ev.Use();
            }
            break;

        case EventType.MouseUp:
            if (state == STATE.MAKING_TRANSITION)
            {
                Debug.Log("Making transition between " + transitionStart.name + " and " + fighterState.name);
                EndTransition(fighterState);
                ev.Use();
            }
            break;
        }
    }
示例#7
0
        /// <summary>Link two states together with a simple test function.</summary>
        /// <param name="a">The state to transition from.</param>
        /// <param name="b">The linked state to transition to.</param>
        /// <param name="test"></param>
        public void LinkNodes(StateMachineNode a, StateMachineNode b, StateMachineLink.TestDelegate test)
        {
            if (a == b)
            {
                throw new NotSupportedException("Cannot link a node to itself.");
            }
            if (!Nodes.Contains(a) || !Nodes.Contains(b))
            {
                throw new NotSupportedException("Cannot link nodes that are not contained within the state machine.");
            }
            var link = new StateMachineLink(b, test);

            a.Links.Add((b, link));
        }
    private void OnClickAddShortcut(Vector2 mousePosition, int state)
    {
        StateMachineNode newState = new StateMachineNode(true, state);

        newState.name = machine.states[state].name;
        newState.nodeRect.position = mousePosition;
        int id = machine.states.Add(newState);

        if (treePath.Count > 0)
        {
            newState.parent = treePath[treePath.Count - 1];
            machine.states[treePath.Count - 1].containedNodes.Add(id);
        }
    }
    private void EndTransition(StateMachineNode end)
    {
        state = STATE.IDLE;
        LZFighterStateTransition newTransition = new LZFighterStateTransition();

        newTransition.source = machine.states.FindIndex((s) => s == transitionStart);
        newTransition.target = machine.states.FindIndex((s) => s == end);
        if (newTransition.source != newTransition.target && machine.transitions.Find((t) => t.source == newTransition.source && t.target == newTransition.target) == null)
        {
            machine.transitions.Add(newTransition);
        }

        LZFighterEditor.RepaintWindow();
    }
示例#10
0
    public void DrawState(StateMachineNode state)
    {
        if (state.IsShortcut)
        {
            DrawShortcut(state);
            return;
        }
        LabelTitle(state.name);
        state.data = (LZFighterStateData)EditorGUILayout.ObjectField(state.data, typeof(LZFighterStateData), false);
        if (state.data != null && state.name == "")
        {
            state.name = state.data.name;
        }
        // Edit instance
        if (GUILayout.Button("Edit"))
        {
            if (state.data == null)
            {
                LZFighter fighter   = LZFighterEditor.Instance.fighter;
                string    path      = AssetDatabase.GetAssetPath(fighter);
                string    filename  = Path.GetFileNameWithoutExtension(path);
                string    directory = Path.GetDirectoryName(path);
                if (!AssetDatabase.IsValidFolder(directory + "/" + filename))
                {
                    AssetDatabase.CreateFolder(directory, filename);
                }
                LZFighterStateData newData = ScriptableObject.CreateInstance <LZFighterStateData>();
                AssetDatabase.CreateAsset(newData, directory + "/" + filename + "/" + state.name + ".asset");
                Debug.Log(Path.GetDirectoryName(path));
                state.data = newData;
            }
            LZFighterStateEditor.Open(state.data);
        }
        string currentName = state.name;
        string newName     = EditorGUILayout.TextField("Name:", currentName);

        /*if (currentName != newName && state.data != null) {
         *  AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(state.data), newName);
         * }*/
        state.name     = newName;
        state.velocity = EditorGUILayout.Vector2Field("StateVelocity: ", state.velocity);
        if (state.data != null)
        {
            state.data.velocity = EditorGUILayout.Vector2Field("DataVelocity:", state.data.velocity);
        }
        state.invert = EditorGUILayout.Toggle("Invert", state.invert);
        state.loop   = EditorGUILayout.Toggle("Loop", state.loop);

        GUITools.ScriptListField(state.scripts, fighter);
    }
示例#11
0
        public void Update(GameTime gameTime)
        {
            if (!Enabled)
            {
                return;
            }

            nodeTime += (float)gameTime.ElapsedGameTime.TotalSeconds;

            StateMachineNode t = null;

            do
            {
                t = currentNode?.TryTransition(this);
            } while (t != null);

            currentNode.Update(new StateUpdateEventArgs(this, gameTime));
        }
示例#12
0
 /// <summary>Add a link to a state.</summary>
 /// <param name="a">The state to transition from.</param>
 /// <param name="link">The link defining the transition.</param>
 public void LinkNodes(StateMachineNode a, StateMachineLink link)
 {
     LinkNodes(a, link.Target, link);
 }
示例#13
0
 public TransitionEventArgs(StateMachineNode from, StateMachineNode to, StateMachineLink link) : base()
 {
     this.from = from;
     this.to   = to;
     this.link = link;
 }
        private void SaveStateMachine()
        {
            var stateMachine = new StateMachineNode();

            NodeUI.StateMachineNodeAsset = new StateMachineNodeAsset {
                Data = stateMachine
            };

            var parameterMap  = new Dictionary <ParameterNodeUI, Parameter>();
            var stateMap      = new Dictionary <StateNodeUI, State>();
            var anyStateMap   = new Dictionary <AnyStateNodeUI, AnyState>();
            var transitionMap = new Dictionary <TransitionInfo, Transition>();

            Parameters.Items.Values.ForEach(p =>
            {
                var parameter  = stateMachine.AddParameter(p.Name);
                parameter.Type = (ValueProviderType)p.ParameterTypeField.value;
                NodeUI.StateMachineNodeAsset.ParameterMap.Add(parameter.Id, new NodeVisualInfo(p.GetPosition().position, p.expanded));

                switch (parameter.ValueProvider)
                {
                case BoolProvider boolProvider:
                    boolProvider.Value = p.BoolField.value;
                    break;

                case IntProvider intProvider:
                    intProvider.Value = p.IntField.value;
                    break;

                case FloatProvider floatProvider:
                    floatProvider.Value = p.FloatField.value;
                    break;

                default:
                    break;
                }

                parameterMap.Add(p, parameter);
            });

            TransitionConnections.ForEach(transitionConnection =>
            {
                transitionConnection.Transitions.ForEach(transitionInfo =>
                {
                    Transition transition = new Transition()
                    {
                        DurationType            = transitionInfo.DurationType,
                        Duration                = transitionInfo.Duration,
                        OffsetType              = transitionInfo.OffsetType,
                        Offset                  = transitionInfo.Offset,
                        InterruptionSource      = transitionInfo.InterruptionSource,
                        OrderedInterruption     = transitionInfo.OrderedInterruption,
                        InterruptableByAnyState = transitionInfo.InterruptableByAnyState,
                        PlayAfterTransition     = transitionInfo.PlayAfterTransition
                    };

                    stateMachine.Transitions.Add(transition);
                    transitionMap.Add(transitionInfo, transition);
                });
            });

            States.Items.Values.ForEach(stateNode =>
            {
                var state = stateMachine.AddState(stateNode.Name);

                stateNode.ExitConnections.ForEach(connection =>
                {
                    ((TransitionConnectionUI)connection).Transitions.ForEach(transitionInfo =>
                    {
                        Transition transition  = transitionMap[transitionInfo];
                        transition.SourceState = state;
                        state.ExitTransitions.Add(transition);
                    });
                });

                stateNode.EntryConnections.ForEach(connection =>
                {
                    if (!(connection is TransitionConnectionUI transitionConnection))
                    {
                        return;
                    }

                    transitionConnection.Transitions.ForEach(transitionInfo =>
                    {
                        Transition transition       = transitionMap[transitionInfo];
                        transition.DestinationState = state;
                        state.EntryTransitions.Add(transition);
                    });
                });

                NodeUI.StateMachineNodeAsset.StateMap.Add(state.Id, new NodeVisualInfo(stateNode.GetPosition().position, stateNode.expanded));
                stateMap.Add(stateNode, state);
            });

            HashSet <AnyStateNodeUI> alreadyAddedAnyStates = new HashSet <AnyStateNodeUI>();

            if (GraphView.AnyStatePriorityManager == null)
            {
                NodeUI.StateMachineNodeAsset.AnyStatePriorityManager = null;
            }
            else
            {
                NodeUI.StateMachineNodeAsset.AnyStatePriorityManager = new NodeVisualInfo(GraphView.AnyStatePriorityManager.GetPosition().position, GraphView.AnyStatePriorityManager.expanded);

                foreach (var anyStateNode in GraphView.AnyStatePriorityManager.AnyStates)
                {
                    if (anyStateNode == null)
                    {
                        continue;
                    }

                    AnyState anyState = anyStateNode.GenerateData(stateMap);

                    anyStateNode.ExitConnections.ForEach(connection =>
                    {
                        ((TransitionConnectionUI)connection).Transitions.ForEach(transitionInfo =>
                        {
                            Transition transition  = transitionMap[transitionInfo];
                            transition.SourceState = anyState;
                            anyState.ExitTransitions.Add(transition);
                        });
                    });

                    stateMachine.AnyStates.AddItem(anyState);
                    NodeUI.StateMachineNodeAsset.AnyStateMap.Add(anyState.Id, new NodeVisualInfo(anyStateNode.GetPosition().position, anyStateNode.expanded));
                    alreadyAddedAnyStates.Add(anyStateNode);
                    anyStateMap.Add(anyStateNode, anyState);
                }
            }

            AnyStates.Items.Values.ForEach(anyStateNode =>
            {
                if (alreadyAddedAnyStates.Contains(anyStateNode))
                {
                    return;
                }

                AnyState anyState = anyStateNode.GenerateData(stateMap);

                anyStateNode.ExitConnections.ForEach(connection =>
                {
                    ((TransitionConnectionUI)connection).Transitions.ForEach(transitionInfo =>
                    {
                        Transition transition  = transitionMap[transitionInfo];
                        transition.SourceState = anyState;
                        anyState.ExitTransitions.Add(transition);
                    });
                });

                stateMachine.AnyStates.AddItem(anyState);
                NodeUI.StateMachineNodeAsset.AnyStateMap.Add(anyState.Id, new NodeVisualInfo(anyStateNode.GetPosition().position, anyStateNode.expanded));
                anyStateMap.Add(anyStateNode, anyState);
            });

            TransitionConnections.ForEach(transitionConnection =>
            {
                transitionConnection.Transitions.ForEach(transitionInfo =>
                {
                    Transition transition          = transitionMap[transitionInfo];
                    transition.Conditions.Capacity = transitionInfo.Conditions.Count;

                    transitionInfo.Conditions.ForEach(infoCondition =>
                    {
                        TransitionCondition condition = new TransitionCondition();

                        if (infoCondition.ProviderSourceType == ValueProviderSourceType.State)
                        {
                            if (infoCondition.State != null)
                            {
                                State state = stateMap[infoCondition.State];

                                switch (infoCondition.StateValueProvider)
                                {
                                case StateValueProviders.PreviousTime:
                                    condition.SetValueProvider(state.PreviousTime);
                                    break;

                                case StateValueProviders.Time:
                                    condition.SetValueProvider(state.Time);
                                    break;

                                case StateValueProviders.PreviousNormalizedTime:
                                    condition.SetValueProvider(state.PreviousNormalizedTime);
                                    break;

                                case StateValueProviders.NormalizedTime:
                                    condition.SetValueProvider(state.NormalizedTime);
                                    break;
                                }

                                FloatConditionEvaluator floatEvaluator = (FloatConditionEvaluator)condition.Evaluator;
                                floatEvaluator.Comparison      = infoCondition.FloatComparison;
                                floatEvaluator.ComparisonValue = infoCondition.FloatComparisonValue;
                            }
                        }
                        else if (infoCondition.Parameter != null)
                        {
                            condition.SetValueProvider(parameterMap[infoCondition.Parameter].ValueProvider);

                            switch (condition.Evaluator)
                            {
                            case BoolConditionEvaluator boolEvaluator:
                                boolEvaluator.ComparisonValue = infoCondition.BoolComparisonValue ? Bool.True : Bool.False;
                                break;

                            case IntConditionEvaluator intEvaluator:
                                intEvaluator.Comparison      = infoCondition.IntComparison;
                                intEvaluator.ComparisonValue = infoCondition.IntComparisonValue;
                                break;

                            case FloatConditionEvaluator floatEvaluator:
                                floatEvaluator.Comparison      = infoCondition.FloatComparison;
                                floatEvaluator.ComparisonValue = infoCondition.FloatComparisonValue;
                                break;

                            default:
                                break;
                            }
                        }

                        transition.Conditions.Add(condition);
                    });
                });
            });

            GraphView.EntryNode.GenerateData(stateMachine, stateMap);
            NodeUI.StateMachineNodeAsset.EntryState = new NodeVisualInfo(GraphView.EntryNode.GetPosition().position, GraphView.EntryNode.expanded);

            NodeUI.UpdateStatePorts();
        }
示例#15
0
        EmailSearchStateMaсhineWithUSM()
        {
            var nodes = new StateMachineNode <char> [9];

            sb            = new StringBuilder();
            resultStrings = new List <FindedDataInfo>();

            nodes[0] = new StateMachineNode <char>(new StateMachineTransaction <char>[] // начало
            {
                new StateMachineTransaction <char>(c => IsSeparator(c), null, 1),
            }, 0);

            nodes[1] = new StateMachineNode <char>(new StateMachineTransaction <char>[] // считывание логина
            {
                new StateMachineTransaction <char>(c => char.IsLetterOrDigit(c), c =>
                {
                    sb.Clear();
                    sb.Append(c);
                    startPosition = position;
                }, 2),
                new StateMachineTransaction <char>(c => IsSeparator(c), null, 1),
            }, 0);

            nodes[2] = new StateMachineNode <char>(new StateMachineTransaction <char>[] // достигли разделителя @
            {
                new StateMachineTransaction <char>(c => c == '@', c => sb.Append(c), 3),
                new StateMachineTransaction <char>(c => char.IsLetterOrDigit(c) || IsEmailAllowSymbol(c) || c == '.', c => sb.Append(c), 2),
                new StateMachineTransaction <char>(c => IsSeparator(c), null, 1),
            }, 0);

            nodes[3] = new StateMachineNode <char>(new StateMachineTransaction <char>[] // считывание первого домена
            {
                new StateMachineTransaction <char>(c => char.IsLetterOrDigit(c), c => sb.Append(c), 4),
                new StateMachineTransaction <char>(c => IsSeparator(c), null, 1),
            }, 0);

            nodes[4] = new StateMachineNode <char>(new StateMachineTransaction <char>[] // достигли разделителя .
            {
                new StateMachineTransaction <char>(c => c == '.', c => sb.Append(c), 5),
                new StateMachineTransaction <char>(c => char.IsLetterOrDigit(c) || IsEmailAllowSymbol(c), c => sb.Append(c), 4),
                new StateMachineTransaction <char>(c => IsSeparator(c), null, 1),
            }, 0);

            nodes[5] = new StateMachineNode <char>(new StateMachineTransaction <char>[] // считывание домена второго уровня
            {
                new StateMachineTransaction <char>(c => char.IsLetter(c), c => sb.Append(c), 6),
                new StateMachineTransaction <char>(c => char.IsNumber(c) || IsEmailAllowSymbol(c), c => sb.Append(c), 4),
                new StateMachineTransaction <char>(c => IsSeparator(c), null, 1),
            }, 0);

            nodes[6] = new StateMachineNode <char>(new StateMachineTransaction <char>[] // считывание домена второго уровня
            {
                new StateMachineTransaction <char>(c => char.IsLetter(c), c => sb.Append(c), 7),
                new StateMachineTransaction <char>(c => char.IsNumber(c) || IsEmailAllowSymbol(c), c => sb.Append(c), 4),
                new StateMachineTransaction <char>(c => IsSeparator(c), null, 1),
            }, 0);

            nodes[7] = new StateMachineNode <char>(new StateMachineTransaction <char>[] //
            {
                new StateMachineTransaction <char>(c => c == '.', c => sb.Append(c), 5),
                new StateMachineTransaction <char>(c => IsSeparator(c), c =>
                {
                    ApplySearchResult();
                }, 1),
                new StateMachineTransaction <char>(c => char.IsLetter(c), c => sb.Append(c), 7),
                new StateMachineTransaction <char>(c => char.IsNumber(c) || IsEmailAllowSymbol(c), c => sb.Append(c), 4),
            }, 0);

            stateMachine = new UniversalStateMachine <char>(nodes);
        }
    private void DoConvert()
    {
        var oldGraph = target as IGraphData;

        IGraphData graphData = null;
        var graph = ScriptableObject.CreateInstance<UnityGraphData>();
        if (oldGraph is ExternalStateMachineGraph)
        {
            graph.Graph = new StateMachineGraph();
        }
        else if (oldGraph is ExternalSubsystemGraph)
        {
            graph.Graph = new StateMachineGraph();
        }
        else
        {
            graph.Graph = new MVVMGraph();
        }

        graphData = graph;
        graph.name = oldGraph.Name;
        graph.Identifier = oldGraph.Identifier;
        graph.Graph.Identifier = oldGraph.Identifier;

        // Convert all the nodes
        Dictionary<DiagramNode, DiagramNode> converted = new Dictionary<DiagramNode, DiagramNode>();
        List<ConnectionData> connections = new List<ConnectionData>();
        foreach (var oldNode in oldGraph.NodeItems.OfType<SceneManagerData>())
        {
            var node = new SceneTypeNode
            {
                Identifier = oldNode.Identifier,
                Name = oldNode.Name
            };
            //foreach (var item in oldNode.Transitions)
            //{
            //    node.ChildItems.Add(new SceneTransitionsReference()
            //    {
            //        Node = node,
            //        Identifier = item.Identifier,
            //        SourceIdentifier = item.CommandIdentifier,
            //    });
            //    if (string.IsNullOrEmpty(item.ToIdentifier)) continue;
            //    connections.Add(new ConnectionData(item.Identifier, item.ToIdentifier));
            //}
            converted.Add(oldNode, node);
        }
        foreach (var oldNode in oldGraph.NodeItems.OfType<SubSystemData>())
        {
            var node = new SubsystemNode()
            {
                Identifier = oldNode.Identifier,
                Name = oldNode.Name
            };
            converted.Add(oldNode, node);
        }
        foreach (var oldNode in oldGraph.NodeItems.OfType<ComputedPropertyData>())
        {
            var node = new ComputedPropertyNode()
            {
                Identifier = oldNode.Identifier,
                Name = oldNode.Name,
                PropertyType = oldNode.RelatedType
            };

            foreach (var item in oldNode.DependantProperties)
            {
                connections.Add(new ConnectionData(item.Identifier, node.Identifier));
            }

            foreach (var x in oldNode.DependantNodes)
            {
                foreach (var item in x.AllProperties)
                {
                    if (x[item.Identifier])
                    {
                        node.ChildItems.Add(new SubPropertiesReference()
                        {
                            SourceIdentifier = item.Identifier,
                            Node = node,
                        });
                    }
                }
            }

            converted.Add(oldNode, node);
        }
        foreach (var oldNode in oldGraph.NodeItems.OfType<ElementData>())
        {
            var node = new ElementNode()
            {
                Identifier = oldNode.Identifier,
                Name = oldNode.Name,
            };
            if (!string.IsNullOrEmpty(oldNode.BaseIdentifier))
            {
                connections.Add(new ConnectionData(oldNode.BaseIdentifier, oldNode.Identifier));
            }
            foreach (var item in oldNode.Properties)
            {
                node.ChildItems.Add(new PropertiesChildItem()
                {
                    Identifier = item.Identifier,
                    Node = node,
                    Name = item.Name,
                    RelatedType = item.RelatedType
                });
            }
            foreach (var item in oldNode.Collections)
            {
                node.ChildItems.Add(new CollectionsChildItem()
                {
                    Identifier = item.Identifier,
                    Name = item.Name,
                    Node = node,
                    RelatedType = item.RelatedType
                });
            }
            foreach (var item in oldNode.Commands)
            {
                node.ChildItems.Add(new CommandsChildItem()
                {
                    Identifier = item.Identifier,
                    Name = item.Name,
                    Node = node,
                    RelatedType = item.RelatedType
                });

                if (!string.IsNullOrEmpty(item.TransitionToIdentifier))
                    connections.Add(new ConnectionData(item.Identifier, item.TransitionToIdentifier));
            }
            converted.Add(oldNode, node);
        }
        foreach (var oldNode in oldGraph.NodeItems.OfType<ClassNodeData>())
        {
            var node = new ElementNode()
            {
                Identifier = oldNode.Identifier,
                Name = oldNode.Name,
            };
            if (!string.IsNullOrEmpty(oldNode.BaseIdentifier))
            {
                connections.Add(new ConnectionData(oldNode.BaseIdentifier, oldNode.Identifier));
            }
            foreach (var item in oldNode.Properties)
            {
                node.ChildItems.Add(new PropertiesChildItem()
                {
                    Identifier = item.Identifier,
                    Node = node,
                    Name = item.Name,
                    RelatedType = item.RelatedType
                });
            }
            foreach (var item in oldNode.Collections)
            {
                node.ChildItems.Add(new CollectionsChildItem()
                {
                    Identifier = item.Identifier,
                    Name = item.Name,
                    Node = node,
                    RelatedType = item.RelatedType
                });
            }

            converted.Add(oldNode, node);
        }
        foreach (var oldNode in oldGraph.NodeItems.OfType<ViewData>())
        {
            var node = new ViewNode()
            {
                Identifier = oldNode.Identifier,
                Name = oldNode.Name
            };
            // TODO CONVERT INHERITANCE
            // Connect the scene property
            foreach (var sceneProperty in oldNode.SceneProperties)
            {
                connections.Add(new ConnectionData(sceneProperty.Identifier, node.ScenePropertiesInputSlot.Identifier));
            }

            // TODO CONVERT BINDINGS

            converted.Add(oldNode, node);
        }

        foreach (var oldNode in oldGraph.NodeItems.OfType<ViewComponentData>())
        {
            var node = new ViewComponentNode()
            {
                Identifier = oldNode.Identifier,
                Name = oldNode.Name
            };
            // TODO CONVERT INHERITANCE
            converted.Add(oldNode, node);
        }

        foreach (var oldNode in oldGraph.NodeItems.OfType<EnumData>())
        {
            var node = new EnumNode()
            {
                Identifier = oldNode.Identifier,
                Name = oldNode.Name
            };
            foreach (var item in oldNode.EnumItems)
            {
                node.ChildItems.Add(new EnumChildItem()
                {
                    Identifier = item.Identifier,
                    Node = node,
                    Name = item.Name
                });
            }
            converted.Add(oldNode, node);
            //Debug.Log(string.Format("Converted {0}", oldNode.Name));
        }

        foreach (var oldNode in oldGraph.NodeItems.OfType<StateMachineNodeData>())
        {
            var node = new StateMachineNode()
            {
                Identifier = oldNode.Identifier,
                Name = oldNode.Name
            };
            if (oldNode.StartState != null)
            {
                connections.Add(new ConnectionData(node.StartStateOutputSlot.Identifier, oldNode.StartState.Identifier));
            }

            foreach (var transition in oldNode.Transitions)
            {
                node.ChildItems.Add(new TransitionsChildItem()
                {
                    Name = transition.Name,
                    Identifier = transition.Identifier,
                    Node = node,
                });
                connections.Add(new ConnectionData(transition.PropertyIdentifier, transition.Identifier));
                //connections.Add();
            }
            connections.Add(new ConnectionData(oldNode.StatePropertyIdentifier, oldNode.Identifier));
            converted.Add(oldNode, node);
        }

        foreach (var oldNode in oldGraph.NodeItems.OfType<StateMachineStateData>())
        {
            var node = new StateNode()
            {
                Identifier = oldNode.Identifier,
                Name = oldNode.Name
            };
            foreach (var transition in oldNode.Transitions)
            {
                node.ChildItems.Add(new StateTransitionsReference()
                {
                    Name = transition.Name,
                    Identifier = transition.Identifier,
                    Node = node,
                });
                connections.Add(new ConnectionData(transition.Identifier, transition.TransitionToIdentifier));
            }

            converted.Add(oldNode, node);
        }

        // Grab all the connections
        ConvertSubsystems(converted, connections);
        ConvertSceneManagers(converted, connections);
        ConvertElements(converted, connections);
        ConvertStateMachines(converted, connections);
        ConvertViews(converted, connections);
        foreach (var item in converted.Values)
        {
            graphData.AddNode(item);
        }

        foreach (var item in connections)
        {
            if (item == null) continue;
            if (item.OutputIdentifier == item.InputIdentifier)
            {
                continue;
            }
            graphData.AddConnection(item.OutputIdentifier, item.InputIdentifier);
            Debug.Log(string.Format("Added connection {0} - {1}", item.OutputIdentifier, item.InputIdentifier));
        }
        // Reconstruct the filters
        var oldElementGraph = oldGraph as IGraphData;
        if (oldElementGraph != null)
        {
            foreach (var node in converted.Keys)
            {
                var newNOde = converted[node];

                if (oldGraph.PositionData.HasPosition(oldGraph.RootFilter, node))
                {
                    graph.SetItemLocation(newNOde, oldGraph.GetItemLocation(node));
                }
            }

            foreach (var item in oldElementGraph.PositionData.Positions)
            {
                graph.PositionData.Positions.Add(item.Key, item.Value);
            }
        }

        AssetDatabase.CreateAsset(graph, AssetDatabase.GetAssetPath(Selection.activeObject).Replace(".asset", "-new.asset"));
        AssetDatabase.SaveAssets();
    }
示例#17
0
 public StateLeaveEventArgs(StateMachine parent, StateMachineNode next) : base()
 {
     this.parent = parent;
     this.next   = next;
 }
示例#18
0
 /// <param name="target">StateMachineNode this link will transition to if the test condition passes.</param>
 /// <param name="test">Function for the test to perform to determine whether or not to transition to the linked state.</param>
 public StateMachineLink(StateMachineNode target, TestDelegate test)
 {
     this.Target = target;
     this.Test   = test;
 }
 private void BeginTransition(StateMachineNode start)
 {
     transitionStart = start;
     state           = STATE.MAKING_TRANSITION;
 }
示例#20
0
 /// <summary>Add a unique state node to this StateMachine.</summary>
 /// <param name="node">The unique state node to add.</param>
 public void AddNode(StateMachineNode node)
 {
     Nodes.Add(node);
 }
示例#21
0
 public StateEnterEventArgs(StateMachine parent, StateMachineNode prev) : base()
 {
     this.parent = parent;
     this.prev   = prev;
 }
示例#22
0
 /// <param name="target">StateMachineNode this link will transition to if the test condition passes.</param>
 public StateMachineLink(StateMachineNode target)
 {
     this.Target = target;
 }