public ActorStateNode GenerateEntryPointNode(ActorStateTransitionCondition cond = null) { var node = new ActorStateNode { title = "AWAKE", GUID = "0", relevantState = null, EntryPoint = true }; var generatePort = GeneratePort(node, Direction.Output); generatePort.portName = "Next"; var condField = new ObjectField { objectType = typeof(ActorStateTransitionCondition), value = (cond == null ? ScriptableObject.CreateInstance <AlwaysTrueTransitionCondition>() : cond) }; generatePort.contentContainer.Add(condField); node.outputContainer.Add(generatePort); node.styleSheets.Add(Resources.Load <StyleSheet>("Node")); node.RefreshExpandedState(); node.RefreshPorts(); node.SetPosition(new Rect(100, 200, 100, 150)); return(node); }
public ActorStateNode GenerateAINode(string nodeName, ActorState relevantState = null) { var retNode = new ActorStateNode { relevantState = relevantState, GUID = Guid.NewGuid().ToString(), }; var oldLabel = retNode.titleContainer.Q <Label>(); retNode.titleContainer.Remove(oldLabel); var inputPort = GeneratePort(retNode, Direction.Input, Port.Capacity.Multi); inputPort.portName = "Input"; retNode.inputContainer.Add(inputPort); retNode.styleSheets.Add(Resources.Load <StyleSheet>("Node")); var button = new Button(() => { AddConditionPort(retNode); }); button.text = "New State Transition Condition"; retNode.nodeName = nodeName; var titleText = new TextField(); titleText.value = nodeName; titleText.RegisterValueChangedCallback(evt => { retNode.nodeName = evt.newValue; }); retNode.titleContainer.Add(titleText); retNode.titleContainer.Add(button); /*retNode.titleContainer.Add(new TextField * { * text = nodeName * });*/ retNode.mainContainer.Add(new Label("State Behaviour")); var condField = new ObjectField { objectType = typeof(ActorState), value = relevantState }; condField.RegisterValueChangedCallback(evt => retNode.relevantState = evt.newValue as ActorState); retNode.mainContainer.Add(condField); retNode.SetPosition(new Rect(Vector2.zero, defaultNodeSize)); retNode.RefreshExpandedState(); retNode.RefreshPorts(); return(retNode); }
private void RemovePort(ActorStateNode retNode, Port generatedPort) { var targetEdge = edges.ToList().Where(x => x.output.portName == generatedPort.portName && x.output.node == generatedPort.node); if (targetEdge.Any()) { var edge = targetEdge.First(); edge.input.Disconnect(edge); RemoveElement(targetEdge.First()); } retNode.outputContainer.Remove(generatedPort); retNode.RefreshPorts(); retNode.RefreshExpandedState(); }
public void AddConditionPort(ActorStateNode retNode, ActorStateTransitionCondition transCond = null, ActorState destState = null, string overridenPortName = "") { var generatedPort = GeneratePort(retNode, Direction.Output); var outputPortCount = retNode.outputContainer.Query("connector").ToList().Count; var oldLabel = generatedPort.contentContainer.Q <Label>("type"); generatedPort.contentContainer.Remove(oldLabel); generatedPort.portName = (string.IsNullOrEmpty(overridenPortName) ? $"Condition {outputPortCount}" : overridenPortName); var condField = new ObjectField { objectType = typeof(ActorStateTransitionCondition), value = transCond }; if (transCond != null) { retNode.ports.Add(transCond, destState); } Label l = condField.Q <Label>(); l.text = transCond == null ? "None" : transCond.name; condField.RegisterValueChangedCallback(evt => { if (evt.previousValue != null && retNode.ports.ContainsKey(evt.previousValue as ActorStateTransitionCondition)) { retNode.ports.Remove(evt.previousValue as ActorStateTransitionCondition); } ActorStateTransitionCondition cond = (evt.newValue as ActorStateTransitionCondition); l.text = cond.name; if ((generatedPort.connections.Any(x => (x.input.node as ActorStateNode).GUID != retNode.GUID))) { destState = (generatedPort.connections.First(x => (x.input.node as ActorStateNode).GUID != retNode.GUID).input.node as ActorStateNode).relevantState; } retNode.ports.Add(cond, destState); }); //condField.label = generatedPort.portName; //condField.RegisterValueChangedCallback(evt => generatedPort.contentContainer.GetFirstOfType<ObjectField>().value = evt.newValue); var deleteButton = new Button(() => RemovePort(retNode, generatedPort)) { text = "X" }; generatedPort.contentContainer.Add(new Label(" ")); generatedPort.contentContainer.Add(new IntegerField { label = "Priority: " }); //generatedPort.contentContainer.Add(CreateEd) generatedPort.contentContainer.Add(condField); generatedPort.RegisterCallback <MouseUpEvent>(e => { if ((generatedPort.connections.Any(x => (x.input.node as ActorStateNode).GUID != retNode.GUID))) { destState = (generatedPort.connections.First(x => (x.input.node as ActorStateNode).GUID != retNode.GUID).input.node as ActorStateNode).relevantState; } ActorStateTransitionCondition a = (ActorStateTransitionCondition)generatedPort.Q <ObjectField>().value; if (a != null) { //Debug.Log("Adding key value pair " + a + ", " + destState); if (!retNode.ports.ContainsKey(a)) { retNode.ports.Add(a, destState); } else { retNode.ports[a] = destState; } } }); if (transCond != null) { var inspEl = new InspectorElement(transCond); inspEl.RegisterCallback <MouseUpEvent>(e => { retNode.RefreshExpandedState(); }); generatedPort.contentContainer.Add(inspEl); } generatedPort.contentContainer.Add(deleteButton); retNode.outputContainer.Add(generatedPort); retNode.RefreshPorts(); retNode.RefreshExpandedState(); }