protected override void BuildUI() { base.BuildUI(); if (NodeModel is ICollapsible) { CollapseButton = new CollapseButton { name = "collapse-button" }; CollapseButton.AddToClassList(k_UssClassName + "__collapse-button"); CollapseButton.RegisterCallback <ChangeEvent <bool> >(OnCollapse); if (TitleContainer != null) { TitleContainer.Add(CollapseButton); } else { Add(CollapseButton); } } if (NodeModel is IHasPorts) { this.AddStylesheet("PortTopContainer.uss"); var ports = new VisualElement { name = "port-top-container" }; ports.AddToClassList(k_UssClassName + "__port-top-container"); Add(ports); InputPortContainer = new PortContainer { name = "inputs" }; InputPortContainer.AddToClassList("ge-node__inputs"); ports.Add(InputPortContainer); OutputPortContainer = new PortContainer { name = "outputs" }; OutputPortContainer.AddToClassList("ge-node__outputs"); ports.Add(OutputPortContainer); } }
public RandomNode(RandomNodeModel model, Store store, GraphView graphView) : base(model, store, graphView) { styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(UICreationHelper.TemplatePath + "Random.uss")); AddToClassList(k_UssClassName); void OnTitleChange(ChangeEvent <string> e) { Model.MethodBaseName = e.newValue; Model.DefineNode(); store.Dispatch(new RefreshUIAction(UpdateFlags.RequestCompilation | UpdateFlags.GraphTopology)); } void OnParamChange(ChangeEvent <Enum> e) { Model.Variant = (RandomNodeModel.ParamVariant)e.newValue; Model.DefineNode(); store.Dispatch(new RefreshUIAction(UpdateFlags.RequestCompilation | UpdateFlags.GraphTopology)); } RegisterCallback <AttachToPanelEvent>(evt => { // Title : Random [Float v ] [(min, max) v ] if (m_TitleField == null) { title = "Random"; m_TitleField = new PopupField <string>(RandomNodeModel.BaseMethodNames.ToList(), Model.MethodBaseName); m_TitleField.RegisterValueChangedCallback(OnTitleChange); TitleContainer?.Add(m_TitleField); m_ParamField = new EnumField(Model.Variant); m_ParamField.RegisterValueChangedCallback(OnParamChange); TitleContainer?.Add(m_ParamField); m_ParamField?.SetEnabled(RandomNodeModel.RngMethods.Count(m => m.Name == Model.RngMethod.Name) > 1); } }); RegisterCallback <DetachFromPanelEvent>(evt => { m_TitleField.UnregisterValueChangedCallback(OnTitleChange); m_ParamField.UnregisterValueChangedCallback(OnParamChange); }); }