public void Initialize() { m_ContentRoot = new InspectorElement(); m_ContentRoot.OnChanged += (element, path) => { Provider.OnContentChanged(new ContentProvider.ChangeContext(element)); }; m_ContentRoot.AddContext(InspectionContext); if (InspectionContext.ApplyInspectorStyling) { m_ContentRoot.RegisterCallback <GeometryChangedEvent, VisualElement>((evt, element) => StylingUtility.AlignInspectorLabelWidth(element), m_ContentRoot); } m_ContentNotReadyRoot = new InspectorElement(); Root.contentContainer.Add(m_ContentRoot); Root.contentContainer.Add(m_ContentNotReadyRoot); m_ContentRoot.style.flexGrow = 1; }
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(); }