Exemple #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);
            });
        }
        public static GraphElement CreateSetVar(this INodeBuilder builder, Store store, SetVariableNodeModel model)
        {
            if (model.DeclarationModel.IsObjectReference())
            {
                return(GraphElementFactoryExtensions.CreateToken(builder, store, model));
            }
            if (!model.IsGetter)
            {
                return(new SetVariableNode(model, store, builder.GraphView));
            }

            GraphElementFactoryExtensions.GetTokenPorts(store, model, out var input, out var output);
            if (output != null)
            {
                output.portName = "";
            }

            var token = new DotsVariableToken(model, store, input, output, builder.GraphView);

            return(token);
        }