public static async void Compare(ResponseBody body1, ResponseBody body2, bool isCompareValue) { var itemStr1 = body1.Content?.Value as string; var itemStr2 = body2.Content?.Value as string; if ((itemStr1 != null) && (itemStr2 != null)) { if (isCompareValue) { body1.Content.State = itemStr1 != itemStr2 ? StateEnum.ValueUnequal : StateEnum.ValueEqual; } } else if (body1.Content?.Value is StateNode && body2.Content?.Value is StateNode) { if (isCompareValue) { var node1 = (StateNode)body1.Content.Value; var node2 = (StateNode)body2.Content.Value; await StateNode.CompareAsync(node1, node2, true); } } else { if (body1.Content != null) { body1.Content.State = StateEnum.ValueUnequal; } } }
public StateNode HistoryTree() { Dictionary <State, StateNode> stateNodes = new Dictionary <State, StateNode>(); List <List <State> > pdaHistory = pda.history; bool init = true; StateNode head = null; foreach (List <State> states in pdaHistory) { if (init) { var first = states[0]; head = new StateNode(first); stateNodes.Add(first, head); init = false; } else { foreach (State state in states) { StateNode parent = stateNodes[state.previousState]; int childNum = parent.children.Count + 1; StateNode next = new StateNode(parent, childNum, state); stateNodes.Add(state, next); } } } return(head); }
public void OnOkayClicked(object pSender, EventArgs pEventArgs) { Model.SetTitle(_titleTextBox.Text); OkayClicked?.Invoke(this, pEventArgs); NewStateNode = Model.StateNode; DialogResult = DialogResult.OK; }
public static void Part2(FighterStats boss, List <Spell> spells) { var player = new FighterStats(50, 0, 0, 500); var data = new Data { Spells = spells, MinManaUsed = Int32.MaxValue, HardMode = true }; var state = new StateNode { Player = player, Boss = boss, ActiveEffects = new List <Effect>(), }; Func <Data, StateNode, bool> reject = (Data data, StateNode state) => { if (state.Player.Hp <= 0 || state.Player.Mana <= 0 || state.ManaSpent > data.MinManaUsed) { return(true); } return(false); }; Func <Data, StateNode, bool> accept = (Data data, StateNode state) => { if (state.Boss.Hp <= 0) { data.MinManaUsed = Math.Min(data.MinManaUsed, state.ManaSpent); return(true); } return(false); }; Console.WriteLine(AOC.Backtrack(data, state, reject, accept, TrySpells).Select(s => s.ManaSpent).Min()); }
public ParseTableConflict(ParseTableExceptionType conflictType, ColumnRowPair <int, Terminal <T> > tableLocation, StateNode <GrammarElement <T>, LRItem <T>[]> graphLocation, params LRItem <T>[] conflictingItems) { TableLocation = tableLocation; GraphLocation = graphLocation; ConflictType = conflictType; ConflictingItems = new ReadOnlyCollection <LRItem <T> >(conflictingItems.ToList()); }
public DGMulticastNode(MulticastDecisionGraphNode mcdgn, StateNode state) : base(mcdgn, state) { this.mMcDgn = mcdgn; this.mTargetAnchor = new AnchorPoint(this, 1, 0); }
Saved_StateNode GetSavedState(StateNode node) { Saved_StateNode r; stateNodesDict.TryGetValue(node, out r); return(r); }
/// <summary> /// The Initializer for the <seealso cref="FSM"/> /// </summary> /// <param name="editor"></param> /// <param name="parent"></param> /// <param name="posx"></param> /// <param name="posy"></param> public void InitFSM(ClickableElement parent, float posx, float posy) { InitClickableElement(); this.parent = parent; if (parent != null) { elementName = parent.elementNamer.AddName(identificator, "New FSM "); } else { elementName = editor.editorNamer.AddName(identificator, "New FSM "); } windowRect = new Rect(posx, posy, width, height); // Create the entry state StateNode entryNode = CreateInstance <StateNode>(); entryNode.InitStateNode(this, stateType.Entry, 50, 50); if (entryNode != null) { AddEntryState(entryNode); } }
public static async void Compare(RequestBody body1, RequestBody body2, bool isCompareValue) { foreach (var item1 in body1.Content) { if (body2.Content.ContainsKey(item1.Key)) { item1.Value.State = StateEnum.PropertyExisted; if (isCompareValue) { var itemStr1 = item1.Value.Value as string; var itemStr2 = body2.Content[item1.Key].Value as string; if ((itemStr1 != null) && (itemStr2 != null)) { item1.Value.State = itemStr1 != (string)body2.Content[item1.Key].Value ? StateEnum.ValueUnequal : StateEnum.ValueEqual; } else if (item1.Value.Value is StateNode && body2.Content[item1.Key].Value is StateNode) { item1.Value.State = StateEnum.ValueEqual; var node1 = (StateNode)item1.Value.Value; var node2 = (StateNode)body2.Content[item1.Key].Value; await StateNode.CompareAsync(node1, node2, true); } else { item1.Value.State = StateEnum.ValueUnequal; } } } else { item1.Value.State = StateEnum.PropertyMissing; } } }
/// <summary> /// Delete <paramref name="node"/> and all <see cref="TransitionGUI"/> connected to it /// </summary> /// <param name="node"></param> public void DeleteNode(StateNode node, bool deleteTransitions = true) { if (nodes.Remove(node)) { if (deleteTransitions) { List <TransitionGUI> nodeTransitionsList = transitions.Where(t => t.fromNode.Equals(node) || t.toNode.Equals(node)).ToList(); // We have to use a temp list because we are deleting its elements in the middle of the loop foreach (TransitionGUI nodeTransition in nodeTransitionsList) { DeleteTransition(nodeTransition); } } if (node.subElem == null) { elementNamer.RemoveName(node.identificator); } else { elementNamer.RemoveName(node.subElem.identificator); } } }
private StateNode genertateAllState() { Queue <StateNode> deptFirstSearch = new Queue <StateNode>(); StateNode currentState = new StateNode(board, isYouTurn, 0, -1); deptFirstSearch.Enqueue(currentState); while (deptFirstSearch.Count != 0) { StateNode node = deptFirstSearch.Dequeue(); int result = checkIsWinOrLost(node.currentBoard); if (result == TIE) { node.createChileNode(); if (node.childrenState.Count == 0) { node.MiniMaxValue = result; } else { for (int indexChildrenState = 0; indexChildrenState < node.childrenState.Count(); indexChildrenState++) { deptFirstSearch.Enqueue(node.childrenState[indexChildrenState]); } } } else { node.MiniMaxValue = result; } } return(currentState); }
// Get the future State i which is ahead of current State n. If the State i does not // exist, create it. Otherwise return it as-is. public State GetAhead(int consumed, ISequenceCheckpoint checkpoint) { if (consumed <= 0) { return(_current.State); } var i = _current.State.Number + consumed; if (_lookup.ContainsKey(i)) { return(_lookup[i].State); } var state = new State(i, checkpoint); var current = _current; Debug.Assert(i > current.State.Number, "We shouldn't be going backwards"); while (current.Next != null && current.Next.State.Number < i) { current = current.Next; } var newNode = new StateNode(state) { State = state, Next = current.Next }; current.Next = newNode; _lookup.Add(i, newNode); return(state); }
private void AIMove() { if (gameRunning == true) { // choose the min minimax value StateNode minNode = null; var min = int.MaxValue; foreach (var n in currentNode.children) { if (n.minimaxValue < min) { min = n.minimaxValue; minNode = n; } } if (minNode != null) { // perform the ai move now FillWithO(IndexToButtonNumber(minNode.action.Item1, minNode.action.Item2)); Debug.WriteLine("AI moving to " + minNode.action.Item1 + ", " + minNode.action.Item2); } else { Debug.WriteLine("Error node is null"); return; } } }
public void RemoveCrossFromMatrixTest() { int[,] actualWeights = GenerateSampleWeights(); int[,] expectedWeights = new int[2, 2]; (var i, var j) = (1, 2); expectedWeights[0, 0] = actualWeights[0, 0]; expectedWeights[0, 1] = actualWeights[0, 1]; expectedWeights[1, 0] = actualWeights[2, 0]; expectedWeights[1, 1] = actualWeights[2, 1]; var expectedRowIndices = new[] { 0, 2 }; var expectedColumnIndices = new[] { 0, 1 }; var range = Enumerable.Range(0, 3).ToArray(); var state = new StateNode { graph = actualWeights, rowIndices = range, columnIndices = range }; BranchAndBound.UpdateStateNodeWithCrossClippedGraph(state, cutPosition: (i: i, j: j)); Assert.True(state.graph.AreDeepEqual(expectedWeights)); Assert.True(state.rowIndices.AreDeepEqual(expectedRowIndices)); Assert.True(state.columnIndices.AreDeepEqual(expectedColumnIndices)); }
private void MoveNodeToBack(StateNode node) { if (node.Parent) { node.Parent.Node.SortIndex = ++SelectIndex; foreach (var link in Graph.Links) { if (link.IsChild && link.From == node.Parent) { link.To.Node.SortIndex = ++SelectIndex; } } } else { node.SortIndex = ++SelectIndex; foreach (var link in Graph.Links) { if (link.IsChild && link.From == node) { link.To.Node.SortIndex = ++SelectIndex; } } } SortNodes(); }
/// <summary> /// Get the node connection count /// </summary> /// <param name="target"></param> /// <param name="from"></param> /// <returns></returns> public static int GetConnectionCount(Node target, NodeComponent from) { int num = 0; if (target != null && from != null) { if (from is StateNode) { StateNode node = from as StateNode; TransitionEvent[] TE = node.GetTransitions(); foreach (TransitionEvent transition in TE) { if (transition != null && transition.GetTargetNode() == target) { num++; } } } else if (from is EventNode) { EventNode method = from as EventNode; foreach (var node in method.GetFlows()) { if (node.GetTargetNode() == target) { num++; } } } } return(num); }
private void EvaluateStateChange(StateNode exitingState, StateNode enteringState) { if (ValidStates.Contains(enteringState)) { OnEnterValidState.Invoke(); } }
public void UpdateVectors(StateNode src, StateNode dst, bool force = false) { // Prevent updating every gui call if the window didn't move if (!force && (src.HasMoved || dst.HasMoved)) { return; } var Direction = (dst.Center - src.Center).normalized; var CornerOffet = GetCornerOffset(Direction); CornerSource = src.Center; CornerSourceAway = CornerSource + CornerOffet; CornerDestination = dst.Center; CornerDestinationAway = CornerDestination + CornerOffet; CenterSource = GetMiddle(CornerSource, CornerSourceAway); CenterDestination = GetMiddle(CornerDestination, CornerDestinationAway); Center = GetMiddle(CenterSource, CenterDestination); ArrowLeftEnd = GetArrowEnd(Direction, Center, Vector3.forward); ArrowRightEnd = GetArrowEnd(Direction, Center, Vector3.back); Area = GetAreaOfRectangle(CornerSource, CornerSourceAway, CornerDestinationAway); }
public override bool DrawContent(Event e) { StateNode node = _node as StateNode; GUIStyle smallText = new GUIStyle(); smallText.fontSize = 9; smallText.alignment = TextAnchor.MiddleCenter; GUIStyle largeText = new GUIStyle(); largeText.alignment = TextAnchor.MiddleCenter; GUILayout.BeginArea(Transform); GUILayout.BeginVertical(); GUILayout.FlexibleSpace(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.BeginVertical(); GUILayout.Label(node.Valid ? node.stateType.ToString() : node.ToString(), smallText); GUILayout.Label(node.Valid ? node.stateMethodName : "State not found!", largeText); if (node.runOnEncounter) { GUILayout.Label("Run on encounter", smallText); } GUILayout.EndVertical(); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); GUILayout.EndVertical(); GUILayout.EndArea(); return(false); }
public override void OnBodyGUI() { EditorGUIUtility.labelWidth = 350; base.OnBodyGUI(); //End the current GUI Area that is restricted to node's dimensions GUILayout.EndArea(); //Show Label Above node Vector2 nodeLabelPos = NodeEditorWindow.current.GridToWindowPositionNoClipped(target.position + new Vector2(0f, -60f)); StateNode nodeAsState = target as StateNode; NodeEditorPreferences.Settings prefs = NodeEditorPreferences.GetSettings(); GUIStyle labelStyle = XNodeUtils.ZoomBasedStyle(35f, 85f, NodeEditorWindow.current.zoom, prefs.minZoom, prefs.maxZoom, new Color(.85f, .85f, 1f), FontStyle.Bold, TextAnchor.LowerCenter, false); GUI.Label(new Rect(nodeLabelPos, new Vector2(GetWidth(), 50f)), nodeAsState.GetName(), labelStyle); //Put back the GUI area that is restricted to node's dimensions Vector2 nodePos = NodeEditorWindow.current.GridToWindowPositionNoClipped(target.position); GUILayout.BeginArea(new Rect(nodePos, new Vector2(GetWidth(), 4000))); }
private void InitStateMachine() { blackboard = new StateBlackboard(); blackboard.Add <bool>(BlackboardKey.DamageFlag, false); blackboard.Add <bool>(BlackboardKey.RepeatDamageFlag, false); blackboard.Add <Transform>(BlackboardKey.Transform, transform); blackboard.Add <float>(BlackboardKey.AttackRange, 0f); EnemyIdleState idleState = EnemyIdleState.Create(blackboard, animator, "Idle", 0); StateNode idleNode = new StateNode(idleState, new Condition(() => { return(true); })); SetAnimTriggerAction walkAction = new SetAnimTriggerAction(blackboard, animator, "Run"); MeleeAttackState meleeAttackState = MeleeAttackState.Create(blackboard, animator, navAgent, attackValidator.MeleeAttacks, transform, BlackboardKey.AttackRange, BlackboardKey.AnimTrigger, walkAction, 300); StateNode attackNode = new StateNode(meleeAttackState, new Condition(() => { return(target != null); })); DamageState damageState = DamageState.Create(blackboard, animator, "Damage", 500); StateNode damageNode = new StateNode(damageState, new Condition(() => { return(blackboard.Get <bool>(BlackboardKey.DamageFlag)); })); DeathState deathState = DeathState.Create(blackboard, animator, "Death", int.MaxValue); StateNode deathNode = new StateNode(deathState, new Condition(() => { return(!self.IsAlive); })); List <StateNode> nodes = new List <StateNode>(); nodes.Add(idleNode); nodes.Add(attackNode); nodes.Add(damageNode); nodes.Add(deathNode); stateMachine = new StateMachine(blackboard, nodes, idleState); }
private CounterExampleItem GetCounterExample(StateNode state) { return(new CounterExampleItem( GetPositionFromInitialState(state), GetVariablesFromState(state) )); }
public virtual bool CheckLink(StateNode from, StateNode to, bool isChild) { if (isChild && (from.Parent || IsStack(to))) { return(false); } if (!ChechInput(to)) { return(false); } if (isChild && !IsStack(from)) { return(false); } if (!CheckOutput(from) && !isChild) { return(false); } if (isChild && !CheckChildType(from, to.NodeType)) { return(false); } if (from == to || Links.Exists(obj => obj.From == from && obj.To == to && obj.IsChild == isChild)) { return(false); } return(true); }
private bool ValidateOutputState(StateNode outState) { if (subStates.IsNullOrEmpty()) { return(false); } //Only allow animStateNodes as output AnimationStateNode outputAsAnimState = outState as AnimationStateNode; if (outputAsAnimState == null) { return(false); } //Makes sure output state is present in list foreach (var state in subStates) { if (state == outState) { return(true); } } return(false); }
public static TreeNode GetAllTypeNode() { TypesB1Node nodeType = new TypesB1Node(); nodeType.Text = nodeType.KNXMainNumber + "." + nodeType.KNXSubNumber + " " + nodeType.Name; nodeType.Nodes.Add(SwitchNode.GetTypeNode()); nodeType.Nodes.Add(BoolNode.GetTypeNoe()); nodeType.Nodes.Add(EnableNode.GetTypeNode()); nodeType.Nodes.Add(RampNode.GetTypeNode()); nodeType.Nodes.Add(AlarmNode.GetTypeNode()); nodeType.Nodes.Add(BinaryValueNode.GetTypeNode()); nodeType.Nodes.Add(StepNode.GetTypeNode()); nodeType.Nodes.Add(UpDownNode.GetTypeNode()); nodeType.Nodes.Add(OpenCloseNode.GetTypeNode()); nodeType.Nodes.Add(StartNode.GetTypeNode()); nodeType.Nodes.Add(StateNode.GetTypeNode()); nodeType.Nodes.Add(InvertNode.GetTypeNode()); nodeType.Nodes.Add(DimSendStyleNode.GetTypeNode()); nodeType.Nodes.Add(InputSourceNode.GetTypeNode()); nodeType.Nodes.Add(ResetNode.GetTypeNode()); nodeType.Nodes.Add(AckNode.GetTypeNode()); nodeType.Nodes.Add(TriggerNode.GetTypeNode()); nodeType.Nodes.Add(OccupancyNode.GetTypeNode()); nodeType.Nodes.Add(WindowDoorNode.GetTypeNode()); nodeType.Nodes.Add(LogicalFunctionNode.GetTypeNode()); nodeType.Nodes.Add(SceneABNode.GetTypeNode()); nodeType.Nodes.Add(ShutterBlindsModeNode.GetTypeNode()); nodeType.Nodes.Add(HeatCoolNode.GetTypeNode()); return(nodeType); }
public Form1() { InitializeComponent(); buttons[0] = button1; buttons[1] = button2; buttons[2] = button3; buttons[3] = button4; buttons[4] = button5; buttons[5] = button6; buttons[6] = button7; buttons[7] = button8; buttons[8] = button9; currentNode = new StateNode(); currentNode.gs = new GameState(); currentNode.gs.state = new char[3, 3]; currentNode.player = 'x'; // permute over all possible game states. This will take a couple seconds please be patient. GenerateStates(currentNode, 'x'); var terminalNodes = new List <StateNode>(); GetTerminalNodes(currentNode, terminalNodes); Debug.WriteLine("Generated " + terminalNodes.Count + " terminal nodes"); Debug.WriteLine("Generated " + count + " nodes"); }
/// <summary> /// Recalculate every <see cref="StateNode"/>'s state of connection to the <see cref="EntryState"/> /// </summary> /// <param name="baseNode"></param> public void CheckConnected(StateNode baseNode = null) { if (baseNode == null) { baseNode = (StateNode)nodes.Find(n => ((StateNode)n).type == stateType.Entry); foreach (StateNode elem in nodes.FindAll(o => ((StateNode)o).type != stateType.Entry)) { elem.type = stateType.Unconnected; } if (!nodes.Contains(baseNode)) { return; } } else if (baseNode.type == stateType.Unconnected) { baseNode.type = stateType.Default; } else { return; } foreach (TransitionGUI nodeTransition in transitions.FindAll(t => !t.isExit && t.fromNode && t.toNode && t.fromNode.Equals(baseNode))) { CheckConnected((StateNode)nodeTransition.toNode); } }
public static void BuildStateNode(StateNode node, JToken jToken) { if (jToken == null) { return; } switch (jToken.Type) { case JTokenType.Object: var objectNode = AddNode(node, jToken.Type.ToString(), jToken.Type); using (var enumerator = jToken.Children().GetEnumerator()) { while (enumerator.MoveNext()) { BuildStateNode(objectNode, enumerator.Current); } } break; case JTokenType.Array: var arrayNode = AddNode(node, jToken.Type.ToString(), jToken.Type); BuildStateNode(arrayNode, jToken.First); break; case JTokenType.Property: var jProperty = jToken as JProperty; if (jProperty != null) { if (jProperty.Value.HasValues) { var propertyNode = AddNode(node, jProperty.Name, jProperty.Value.Type); BuildStateNode(propertyNode, jProperty.Value); } else { var value = jProperty.Value.ToString(); if (jProperty.Value.Type == JTokenType.Float && !value.Contains(".")) { value += ".0"; } AddLeafNode(node, jProperty.Name, value, jProperty.Value.Type); } } break; default: var jValue = jToken as JValue; if (jValue != null) { AddLeafNode(node, jValue.Type.ToString(), jValue.Value.ToString(), jValue.Type); } else { throw new ArgumentException("Unhandled json type"); } break; } }
void Awake() { machine = GetComponent <Machine>(); foreach (MethodInfo method in GetType().GetMethods().Where(method => method.GetCustomAttribute <StateAttribute>() != null)) { nodes.Add(method.Name, StateNode.GetStateNodeFromMethod(machine._model, GetType(), method.Name)); } }
/// <summary> /// 原因(Action)には結果が伴う /// </summary> public ActionNode(ActionBase action, StateNode stateNodeNext) : base() { _action = action; this.StateNodeNext = stateNodeNext; this.Connect(stateNodeNext); }
public StateCollection(ISequenceCheckpoint cp) { InitialState = new State(0, cp); _current = new StateNode(InitialState); _lookup = new Dictionary <int, StateNode> { { 0, _current } }; }
public override Node Create(Vector2 pos) { StateNode node = CreateInstance <StateNode> (); node.rect = new Rect(pos.x, pos.y, 150, 100); return(node); }
public DGStopNode(StopAnimationNode san, StateNode state) : base(san, state, false) { if (san == null) { throw new ArgumentNullException("san"); } this.mStopNode = san; this.UpdateVisualization(); }
public void softReset() { StateNode seek = new StateNode("Seek", new BehavInkySeek()); StateNode evade = new StateNode("Evade", new BehavInkyEvade()); StateNode dead = new StateNode("Dead", new BehavInkyDead()); seek.addEdge(new StateEdge(seek, evade, new GhostCheckPellet())); evade.addEdge (new StateEdge (evade, seek, new GhostCheckNormalPac ())); evade.addEdge(new StateEdge(evade, dead, new GhostDie())); dead.addEdge(new StateEdge (dead, seek, new GhostRespawn())); machine = new FSM (seek); }
public DGRootNode(DecisionGraph dg, StateNode state) : base(null, state) { if (dg == null) { throw new ArgumentNullException("dg"); } this.mDecisionGraph = dg; this.mEntryAnchor.SetPosition(sRad, 0); this.mEntryAnchor.SetDirection(1, 0); this.UpdateVisualization(); }
public void softReset() { isSuper = false; superCouter = 0; maxSuperCounter = 150; behaviorCounter = 0; StateNode dead = new StateNode ("Dead", new BehavPacmanDead() ); StateNode normal = new StateNode ("Normal", new BehavPacmanEat ()); StateNode beSuper = new StateNode ("Super", new BehavPacmanPower ()); normal.addEdge (new StateEdge(normal, beSuper, new PacmanSuper ())); normal.addEdge (new StateEdge(normal, dead, new PacmanDead ())); beSuper.addEdge (new StateEdge(beSuper, normal, new PacmanNormalize ())); machine = new FSM (normal); points = 0; }
//Will set the comparator the the given one public StateEdge(StateNode from, StateNode end, StateCondition cond) { fromNode = from; endNode = end; condition = cond; }
//Will check if the current node needs changing and do so if needed; public void possibleStateChange(GameObject thisObject, MonoBehaviour thisScript) { currentNode = currentNode.checkState(thisObject, thisScript); }
//constructor will set the current Node; public FSM(StateNode start) { currentNode = start; }
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(); }