Ejemplo n.º 1
0
        public ExposedParameterFieldView(BaseGraphView graphView, ExposedParameter param, string shortType) : base(null, param.name, shortType)
        {
            this.graphView = graphView;
            parameter      = param;
            this.AddManipulator(new ContextualMenuManipulator(BuildContextualMenu));
            this.AddToClassList("parameter-" + shortType);
            this.Q("icon").visible = true;

            (this.Q("textField") as TextField).RegisterValueChangedCallback((e) =>
            {
                param.name = e.newValue;
                text       = e.newValue;
                if (param.name == "inputVector3" || param.name == "inputVector2" || param.name == "inputFloat" || param.name == "inputInteger" || param.name == "inputGameObject")
                {
                    param.settings.isHidden = true;
                }

                graphView.graph.UpdateExposedParameterName(param, e.newValue);
            });

            var parameterElem = this.Q("pill");

            parameterElem.RegisterCallback <MouseOverEvent>((e) =>
            {
                graphView.Query <ParameterNodeView>(className: "pName-" + parameter.name).Build()
                .ForEach(view => view.AddToClassList("Highlight"));
            });

            parameterElem.RegisterCallback <MouseOutEvent>((e) =>
            {
                graphView.Query <ParameterNodeView>(className: "pName-" + parameter.name).Build()
                .ForEach(view => view.RemoveFromClassList("Highlight"));
            });
        }
Ejemplo n.º 2
0
 void OnParamChanged(ExposedParameter modifiedParam)
 {
     if (parameter == modifiedParam)
     {
         onParameterChanged?.Invoke();
     }
 }
Ejemplo n.º 3
0
        public VisualElement GetParameterSettingsField(ExposedParameter parameter, Action <object> valueChangedCallback)
        {
            serializedObject.Update();
            int propIndex           = FindPropertyIndex(parameter);
            var serializedParameter = serializedParameters.GetArrayElementAtIndex(propIndex);

            serializedParameter.managedReferenceValue = exposedParameterObject.parameters[propIndex];
            var serializedSettings = serializedParameter.FindPropertyRelative(nameof(ExposedParameter.settings));

            serializedSettings.managedReferenceValue = exposedParameterObject.parameters[propIndex].settings;
            var settingsField = new PropertyField(serializedSettings);

            settingsField.Bind(serializedObject);

            VisualElement view = new VisualElement();

            view.Add(settingsField);

            // TODO: see if we can replace this with an event
            oldParameterSettings[parameter] = parameter.settings;
            view.Add(new IMGUIContainer(() =>
            {
                if (oldParameterSettings.TryGetValue(parameter, out var settings))
                {
                    if (!settings.Equals(parameter.settings))
                    {
                        valueChangedCallback(parameter.settings);
                    }
                }
                oldParameterSettings[parameter] = parameter.settings;
            }));

            return(view);
        }
        void DrawParameter(ExposedParameter param, VisualElement paramContainer)
        {
            VisualElement prop = new VisualElement();

            prop.style.display = DisplayStyle.Flex;
            Type paramType = Type.GetType(param.type);

            if (!supportedTypes.Contains(paramType))
            {
                var label = new Label {
                    text = param.name + "     (" + paramType.Name + ")"
                };
                label.style.marginLeft   = 3;
                label.style.marginTop    = 1;
                label.style.marginBottom = 1;
                prop.Add(label);
            }
            else
            {
                var field = FieldFactory.CreateField(paramType, param.serializedValue.value, (newValue) =>
                {
                    Undo.RegisterCompleteObjectUndo(graph, "Changed Parameter " + param.name + " to " + newValue);
                    param.serializedValue.value = newValue;
                }, param.name);
                prop.Add(field);
            }

            paramContainer.Add(prop);
        }
Ejemplo n.º 5
0
        public ExposedParameterPropertyView(BaseGraphView graphView, ExposedParameter param)
        {
            baseGraphView = graphView;
            parameter     = param;

            hideInInspector = new Toggle
            {
                text  = "Hide in Inspector",
                value = parameter.settings.isHidden
            };
            hideInInspector.RegisterValueChangedCallback(e =>
            {
                baseGraphView.graph.UpdateExposedParameterVisibility(parameter, e.newValue);
            });

            Add(hideInInspector);

            isInput = new Toggle
            {
                text  = "Is Input",
                value = parameter.settings.isInputParameter
            };
            isInput.RegisterValueChangedCallback(e =>
            {
                baseGraphView.graph.UpdateExposedParameterVisibility(parameter, e.newValue);
            });

            Add(isInput);
        }
        public ExposedParameterPropertyView(BaseGraphView graphView, ExposedParameter param)
        {
            baseGraphView = graphView;
            parameter     = param;

            var field = graphView.exposedParameterFactory.GetParameterSettingsField(param, (newValue) => {
                param.settings = newValue as ExposedParameter.Settings;
            });

            Add(field);
        }
        public ExposedParameterFieldView(BaseGraphView graphView, ExposedParameter param) : base(null, param.name, "")
        {
            this.graphView = graphView;
            parameter      = param;
            this.AddManipulator(new ContextualMenuManipulator(BuildContextualMenu));

            (this.Q("textField") as TextField).RegisterValueChangedCallback((e) => {
                param.name = e.newValue;
                text       = e.newValue;
                graphView.graph.UpdateExposedParameterName(param, e.newValue);
            });
        }
Ejemplo n.º 8
0
        public ExposedParameterFieldView(BaseGraphView graphView, ExposedParameter param) : base(null, param.name, param.shortType)
        {
            this.graphView = graphView;
            parameter      = param;
            this.AddManipulator(new ContextualMenuManipulator(BuildContextualMenu));
            this.Q("icon").AddToClassList("parameter-" + param.shortType);
            this.Q("icon").visible = true;

            (this.Q("textField") as TextField).RegisterValueChangedCallback((e) => {
                param.name = e.newValue;
                text       = e.newValue;
                graphView.graph.UpdateExposedParameterName(param, e.newValue);
            });
        }
Ejemplo n.º 9
0
        void LoadExposedParameter()
        {
            parameter = graph.GetExposedParameterFromGUID(parameterGUID);

            if (parameter == null)
            {
                Debug.Log("Property \"" + parameterGUID + "\" Can't be found !");

                // Delete this node as the property can't be found
                graph.RemoveNode(this);
                return;
            }

            output = parameter.value;
        }
Ejemplo n.º 10
0
        protected override void Process()
        {
#if UNITY_EDITOR // In the editor, an undo/redo can change the parameter instance in the graph, in this case the field in this class will point to the wrong parameter
            parameter = graph.GetExposedParameterFromGUID(parameterGUID);
#endif

            if (accessor == ParameterAccessor.Get)
            {
                output = parameter.value;
            }
            else
            {
                graph.UpdateExposedParameter(parameter.guid, input);
            }
        }
        public ExposedParameterPropertyView(BaseGraphView graphView, ExposedParameter param)
        {
            baseGraphView = graphView;
            parameter     = param;

            var settingField = graphView.exposedParameterFactory.GetParameterSettingsField(param, (newValue) => {
                param.settings = newValue as ExposedParameter.Settings;
            });

            var valueField = graphView.exposedParameterFactory.GetParameterValueField(param, (newValue) =>
            {
                param.value = newValue;
                //serializedObject.ApplyModifiedProperties();
                baseGraphView.graph.NotifyExposedParameterValueChanged(param);
            });

            Add(valueField);

            Add(settingField);
        }
Ejemplo n.º 12
0
        protected override void Process()
        {
#if UNITY_EDITOR // In the editor, an undo/redo can change the parameter instance in the graph, in this case the field in this class will point to the wrong parameter
            parameter = graph.GetExposedParameterFromGUID(parameterGUID);
#endif

            ClearMessages();
            if (parameter == null)
            {
                AddMessage($"Parameter not found: {parameterGUID}", NodeMessageType.Error);
                return;
            }

            if (accessor == ParameterAccessor.Get)
            {
                output = parameter.value;
            }
            else
            {
                graph.UpdateExposedParameter(parameter.guid, input);
            }
        }
Ejemplo n.º 13
0
        public VisualElement GetParameterValueField(ExposedParameter parameter, Action <object> valueChangedCallback)
        {
            serializedObject.Update();
            int propIndex = FindPropertyIndex(parameter);
            var field     = new PropertyField(serializedParameters.GetArrayElementAtIndex(propIndex));

            field.Bind(serializedObject);

            VisualElement view = new VisualElement();

            view.Add(field);

            oldParameterValues[parameter] = parameter.value;
            view.Add(new IMGUIContainer(() =>
            {
                if (oldParameterValues.TryGetValue(parameter, out var value))
                {
                    if (parameter.value != null && !parameter.value.Equals(value))
                    {
                        valueChangedCallback(parameter.value);
                    }
                }
                oldParameterValues[parameter] = parameter.value;
            }));

            // Disallow picking scene objects when the graph is not linked to a scene
            if (!this.graph.IsLinkedToScene())
            {
                var objectField = view.Q <ObjectField>();
                if (objectField != null)
                {
                    objectField.allowSceneObjects = false;
                }
            }
            return(view);
        }
Ejemplo n.º 14
0
 public void ResetOldParameter(ExposedParameter parameter)
 {
     oldParameterValues.Remove(parameter);
     oldParameterSettings.Remove(parameter);
 }
Ejemplo n.º 15
0
        public ExposedParameterPropertyView(BaseGraphView graphView, ExposedParameter param, string shortType) : base()
        {
            baseGraphView = graphView;
            parameter     = param;
            graphView.graph.onExposedParameterModified += UpdateSettingsVisibility;

            thisIsDynamicParameter = new Label("This is Dynamic");
            thisIsDynamicParameter.style.marginBottom = -5;
            Add(thisIsDynamicParameter);

            hideInInspector = new Toggle
            {
                text  = "Hide in Inspector",
                value = parameter.settings.isHidden
            };

            hideInInspector.RegisterValueChangedCallback(e =>
            {
                baseGraphView.graph.UpdateExposedParameterVisibility(parameter, e.newValue);
                UpdateSliderOption();
            });

            Add(hideInInspector);

            if (shortType != "Single" && shortType != "Int32")
            {
                UpdateSettingsVisibility(param.name);
                return;
            }

            thisIsDynamicParameter.style.marginBottom = -10;

            canBeSlider = true;

            showAsSlider = new Toggle
            {
                text  = "Show as Slider",
                value = parameter.settings.isSlider
            };
            showAsSlider.RegisterValueChangedCallback(e =>
            {
                baseGraphView.graph.UpdateExposedSliderVisibility(parameter, e.newValue);
                UpdateSliderFields();
            });

            sliderMin = new FloatField
            {
                label = "Min Value",
                value = parameter.settings.sliderMinValue
            };
            sliderMin.RegisterValueChangedCallback(e => baseGraphView.graph.UpdateExposedSliderMinValue(parameter, e.newValue));

            sliderMax = new FloatField
            {
                label = "Max Value",
                value = parameter.settings.sliderMaxValue
            };
            sliderMax.RegisterValueChangedCallback(e => baseGraphView.graph.UpdateExposedSliderMaxValue(parameter, e.newValue));

            Add(showAsSlider);
            Add(sliderMin);
            Add(sliderMax);
            UpdateSliderFields();
            UpdateSettingsVisibility(param.name);
        }
Ejemplo n.º 16
0
 void UpdateExposedParameters(ExposedParameter param) => UpdateExposedParameters();
Ejemplo n.º 17
0
 int FindPropertyIndex(ExposedParameter param) => exposedParameterObject.parameters.FindIndex(p => p == param);