/// <summary> /// Creates a copy of this <see cref="TransitionGUI"/> /// </summary> /// <param name="args"></param> /// <returns></returns> public override GUIElement CopyElement(params object[] args) { BaseNode fromNode; BaseNode toNode; if (args.Count() > 1) { fromNode = (BaseNode)args[0]; toNode = (BaseNode)args[1]; } else { fromNode = this.fromNode; toNode = this.toNode; } TransitionGUI result = CreateInstance <TransitionGUI>(); result.identificator = this.identificator; result.transitionName = this.transitionName; result.windowRect = new Rect(this.windowRect); result.width = this.width; result.height = this.height; result.weight = this.weight; result.fromNode = fromNode; result.toNode = toNode; result.rootPerception = (PerceptionGUI)rootPerception.CopyElement(); result.isExit = this.isExit; return(result); }
/// <summary> /// Delete <paramref name="connection"/> /// </summary> /// <param name="connection"></param> public void DeleteConnection(TransitionGUI connection) { if (transitions.Remove(connection)) { elementNamer.RemoveName(connection.identificator); } }
/// <summary> /// Creates and returns the <see cref="TransitionGUI"/> corresponding to this <see cref="XMLElement"/> /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <returns></returns> public TransitionGUI ToTransitionGUI(ClickableElement parent, BaseNode from, BaseNode to) { TransitionGUI transition = ScriptableObject.CreateInstance <TransitionGUI>(); transition.InitTransitionGUIFromXML(parent, from, to, this.Id, this.name, this.perception.ToGUIElement(), this.isExit, this.weight); return(transition); }
/// <summary> /// Delete <paramref name="transition"/> /// </summary> /// <param name="transition"></param> public void DeleteTransition(TransitionGUI transition) { if (transitions.Remove(transition)) { CheckConnected(); elementNamer.RemoveName(transition.identificator); } }
/// <summary> /// Add <paramref name="trans"/> as an Exit transition /// </summary> /// <param name="trans"></param> public void AddAsExit(TransitionGUI trans) { TransitionGUI exitTrans = transitions.Find(t => t.isExit); if (exitTrans) { if (transitions.Remove(exitTrans)) { elementNamer.RemoveName(exitTrans.identificator); } } trans.isExit = true; transitions.Add(trans); }
/// <summary> /// Creates the <see cref="BehaviourNode"/> corresponding to this <see cref="XMLElement"/> /// </summary> /// <param name="selectedNode"></param> /// <param name="currentTree"></param> /// <param name="currentElement"></param> public void ToBehaviourNode(BaseNode selectedNode, BehaviourTree currentTree, ClickableElement currentElement) { switch (this.elemType) { case nameof(FSM): this.ToFSM(currentElement, selectedNode); break; case nameof(BehaviourTree): this.ToBehaviourTree(currentElement, selectedNode); break; case nameof(UtilitySystem): this.ToUtilitySystem(currentElement, selectedNode); break; case nameof(BehaviourNode): BehaviourNode nodeBT = ScriptableObject.CreateInstance <BehaviourNode>(); nodeBT.InitBehaviourNodeFromXML(currentTree, (behaviourType)Enum.Parse(typeof(behaviourType), this.secondType), this.windowPosX, this.windowPosY, this.Id, this.name, this.delayTime, this.Nloops, this.isRandom, this.isInfinite, this.index); currentTree.nodes.Add(nodeBT); if (selectedNode) { TransitionGUI transition = ScriptableObject.CreateInstance <TransitionGUI>(); transition.InitTransitionGUI(currentTree, selectedNode, nodeBT, true); currentTree.transitions.Add(transition); } else { nodeBT.isRoot = true; } foreach (XMLElement childState in this.nodes) { childState.ToBehaviourNode(nodeBT, currentTree, currentTree); } break; default: Debug.LogError("Wrong content in saved data"); break; } }
/// <summary> /// Add <paramref name="newTransition"/> to the <see cref="FSM"/> /// </summary> /// <param name="newTransition"></param> public void AddTransition(TransitionGUI newTransition) { transitions.Add(newTransition); CheckConnected(); }
/// <summary> /// Creates and returns the <see cref="FSM"/> corresponding to this <see cref="XMLElement"/> /// </summary> /// <param name="parent"></param> /// <param name="selectedNode"></param> /// <returns></returns> public UtilitySystem ToUtilitySystem(ClickableElement parent, BaseNode selectedNode = null) { UtilitySystem utilSystem = ScriptableObject.CreateInstance <UtilitySystem>(); utilSystem.InitUtilitySystemFromXML(parent, this.windowPosX, this.windowPosY, this.Id, this.name); foreach (XMLElement node in this.nodes) { switch (node.elemType) { case nameof(FSM): node.ToFSM(utilSystem, null); break; case nameof(BehaviourTree): node.ToBehaviourTree(utilSystem, null); break; case nameof(UtilitySystem): node.ToUtilitySystem(utilSystem, null); break; case nameof(UtilityNode): UtilityNode state = node.ToUtilityNode(utilSystem); utilSystem.nodes.Add(state); break; default: Debug.LogError("Wrong content in saved data"); break; } } foreach (XMLElement trans in this.transitions) { BaseNode node1 = utilSystem.nodes.Where(n => n.identificator == trans.fromId || n.subElem?.identificator == trans.fromId).FirstOrDefault(); BaseNode node2 = utilSystem.nodes.Where(n => n.identificator == trans.toId || n.subElem?.identificator == trans.toId).FirstOrDefault(); if (node1 != null && node2 != null) { utilSystem.transitions.Add(trans.ToTransitionGUI(utilSystem, node1, node2)); } } if (parent) { switch (parent.GetType().ToString()) { case nameof(FSM): StateNode state = ScriptableObject.CreateInstance <StateNode>(); state.InitStateNodeFromXML(parent, stateType.Unconnected, utilSystem.windowRect.position.x, utilSystem.windowRect.position.y, this.Id, this.name, utilSystem); if (this.secondType.Equals(stateType.Entry.ToString())) { ((FSM)parent).AddEntryState(state); } else { parent.nodes.Add(state); } break; case nameof(BehaviourTree): BehaviourNode node = ScriptableObject.CreateInstance <BehaviourNode>(); node.InitBehaviourNode(parent, behaviourType.Leaf, utilSystem.windowRect.x, utilSystem.windowRect.y, utilSystem); parent.nodes.Add(node); if (selectedNode != null) { TransitionGUI transition = ScriptableObject.CreateInstance <TransitionGUI>(); transition.InitTransitionGUI(parent, selectedNode, node); parent.transitions.Add(transition); selectedNode = node; } break; case nameof(UtilitySystem): UtilityNode utilNode = ScriptableObject.CreateInstance <UtilityNode>(); utilNode.InitUtilityNode(parent, utilityType.Action, utilSystem.windowRect.position.x, utilSystem.windowRect.position.y, utilSystem); parent.nodes.Add(utilNode); break; } } return(utilSystem); }