示例#1
0
        public SetVariableNode(SetVariableNodeModel model, Store store, GraphView builderGraphView)
            : base(model, store, builderGraphView)
        {
            // make it clear the ux is not final
            this.Q("title").style.backgroundColor = new StyleColor(new Color32(147, 15, 109, 255));
            this.Q <Label>("title-label").text    = "Set ";

            var pill  = new Pill();
            var label = pill.Q <Label>("title-label");

            label.text = model.DeclarationModel?.Name ?? "<Pick a variable>";

            var pillContainer = new VisualElement();

            pillContainer.AddToClassList("token");
            pillContainer.style.justifyContent = Justify.Center;
            pillContainer.style.flexGrow       = 1;
            pillContainer.Add(pill);

            titleContainer.Insert(1, pillContainer);
            titleContainer.styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(UICreationHelper.templatePath + "Token.uss"));

            pill.RegisterCallback <MouseDownEvent>(_ =>
            {
                SearcherWindow.Show(EditorWindow.focusedWindow, ((VSGraphModel)model.GraphModel).GraphVariableModels.Where(g => GraphBuilder.GetVariableType(g) == GraphBuilder.VariableType.Variable)
                                    .Select(v => (SearcherItem) new VariableSearcherItem(v)).ToList(), "Pick a variable to set", item =>
                {
                    var variableSearcherItem = (item as VariableSearcherItem);
                    if (variableSearcherItem == null)
                    {
                        return(true);
                    }
                    model.DeclarationModel = variableSearcherItem.declarationModel;
                    model.DefineNode();
                    store.Dispatch(new RefreshUIAction(UpdateFlags.GraphTopology));
                    return(true);
                }, Event.current.mousePosition);
            });
        }
        protected override void BuildUI()
        {
            base.BuildUI();

            m_Pill = new Pill();

            var pillContainer = new VisualElement();

            pillContainer.AddToClassList(k_UssClassName + "__variable");
            pillContainer.Add(m_Pill);

            m_Pill.RegisterCallback <MouseDownEvent>(ShowSearcher);

            // make it clear the ux is not final
            var wipOverlay = new VisualElement {
                pickingMode = PickingMode.Ignore
            };

            wipOverlay.AddToClassList("vs-wip-node-overlay");
            Add(wipOverlay);

            TitleContainer?.Insert(1, pillContainer);
        }