Exemplo n.º 1
0
        public override void Enable()
        {
            base.Enable();

            var node = nodeTarget as RandomRangeNode;

            var min = new FloatField("Min")
            {
                value = node.min
            };

            min.RegisterValueChangedCallback(e =>
            {
                owner.RegisterCompleteObjectUndo("Updated Min " + e.newValue);
                node.min = e.newValue;
                NotifyNodeChanged();
            });

            var max = new FloatField("Max")
            {
                value = node.max
            };

            max.RegisterValueChangedCallback(e =>
            {
                owner.RegisterCompleteObjectUndo("Updated Max " + e.newValue);
                node.max = e.newValue;
                NotifyNodeChanged();
            });


            controlsContainer.Add(min);
            controlsContainer.Add(max);
        }
Exemplo n.º 2
0
            public EditorFloatSliderField(string label, float value, float min, float max, EventCallback <ChangeEvent <float> > callback)
            {
                slider       = new Slider(label, min, max, SliderDirection.Horizontal);
                slider.name  = nameof(slider);
                slider.value = value;
                labelElement.StylePadding(0, 8, 0, 0);
                Add(slider);

                floatField      = new FloatField();
                floatField.name = nameof(floatField);
                floatField.StyleWidth(64);
                floatField.style.paddingLeft = 4;
                floatField.style.marginRight = 0;
                floatField.value             = value;
                floatField.RegisterValueChangedCallback(callback);
                floatField.RegisterValueChangedCallback((callbackChangedSlider) =>
                {
                    slider.value = callbackChangedSlider.newValue;
                });
                slider.Add(floatField);

                slider.RegisterValueChangedCallback((callbackSlide) =>
                {
                    floatField.value = callbackSlide.newValue;
                });
            }
Exemplo n.º 3
0
    private void SetPotentialsFromNavigationField()
    {
        FloatField costs = NavigationField.Costs;

        for (int y = 0; y < Size.y; y++)
        {
            for (int x = 0; x < Size.x; x++)
            {
                float cost = costs[x, y];

                if (float.IsPositiveInfinity(cost))
                {
                    Potentials[x, y] = float.NegativeInfinity;
                    Vector2i p         = new Vector2i(x, y);
                    bool     foundExit =
                        TestEscapeDirection(p, DownLeft) ||
                        TestEscapeDirection(p, DownRight) ||
                        TestEscapeDirection(p, UpLeft) ||
                        TestEscapeDirection(p, UpRight) ||
                        TestEscapeDirection(p, Left) ||
                        TestEscapeDirection(p, Right) ||
                        TestEscapeDirection(p, Up) ||
                        TestEscapeDirection(p, Down);
                }
                else
                {
                    Potentials[x, y] = UnreachablePotential;
                }
            }
        }
    }
Exemplo n.º 4
0
        VisualElement CreateLightExposureContent()
        {
            var exposure = SceneView.s_DrawModeExposure;

            var root = new VisualElement();

            root.AddToClassList(k_SliderRowClass);

            var icon = new Image()
            {
                name = "exposure-label"
            };

            m_ExposureSlider = new Slider(-m_ExposureMax, m_ExposureMax)
            {
                name = "exposure-slider"
            };
            m_ExposureSlider.AddToClassList(k_SliderClass);
            m_ExposureSlider.RegisterValueChangedCallback(SetBakedExposure);
            m_ExposureSlider.SetValueWithoutNotify(exposure);

            m_ExposureField = new FloatField()
            {
                name = "exposure-float-field"
            };
            m_ExposureField.AddToClassList(k_SliderFloatFieldClass);
            m_ExposureField.RegisterValueChangedCallback(SetBakedExposure);
            m_ExposureField.SetValueWithoutNotify(exposure);

            root.Add(icon);
            root.Add(m_ExposureSlider);
            root.Add(m_ExposureField);
            return(root);
        }
Exemplo n.º 5
0
        public static void TestFloatField()
        {
            BehaviorTreeElement behaviorTree = new BehaviorTreeElement();

            behaviorTree.StartNode = new NodeData();

            FloatField floatField = new FloatField();

            floatField.FieldName = "FloatField";
            floatField.Value     = 100.001f;
            behaviorTree.StartNode.Fields.Add(floatField);

            RepeatFloatField repeatFloatField = new RepeatFloatField();

            repeatFloatField.FieldName = "RepeatIntField";
            repeatFloatField.Value     = new List <float>();
            repeatFloatField.Value.Add(1.1f);
            repeatFloatField.Value.Add(100.11f);
            repeatFloatField.Value.Add(1000.11f);
            repeatFloatField.Value.Add(10000.1119f);
            behaviorTree.StartNode.Fields.Add(repeatFloatField);

            byte[] bytes = Serializer.Serialize(behaviorTree);
            BehaviorTreeElement deBehaviorTreeData = Serializer.DeSerialize <BehaviorTreeElement>(bytes);
        }
        protected override void SetBaseVisualElement(VisualElement visualElement)
        {
            Vector3Field originField = new Vector3Field("Origin: ")
            {
                value = Blueprint.Origin
            };

            originField.RegisterCallback <ChangeEvent <Vector3> >(evt => Blueprint.SetOrigin(evt.newValue));
            visualElement.Add(originField);

            FloatField lengthField = new FloatField("Length: ")
            {
                value = Blueprint.Length
            };

            lengthField.RegisterCallback <ChangeEvent <float> >(evt => Blueprint.SetLength(evt.newValue));
            visualElement.Add(lengthField);

            // visualElement.Add(new ValidatorField(Blueprint.NonZeroVolumeValidator));

            for (int i = 0; i < Blueprint.Points.Count; i++)
            {
                int       pointNum  = i;
                TextField nameField = new TextField((pointNum + 1).GetOrdinalForm() + " Point name: ")
                {
                    value = Blueprint.Points[i].PointName
                };
                nameField.RegisterCallback <ChangeEvent <string> >(evt => Blueprint.SetPointName(pointNum, evt.newValue));
                visualElement.Add(nameField);
                visualElement.Add(new ValidatorField(Blueprint.Points[i].NameNotEmptyValidator));
                visualElement.Add(new ValidatorField(Blueprint.Points[i].NameUniquenessValidator));
                visualElement.Add(new ValidatorField(Blueprint.Points[i].PositionUniquenessValidator));
            }
        }
Exemplo n.º 7
0
        public void OpenClipsTransitionsModal(MVideoClip clip, MTransition transition)
        {
            var modalContent = this.ShowModalWindow("Transition");

            // Create a new field and assign it its value.
            var TypeField = new EnumField("Type:", transition.Type);

            modalContent.Add(TypeField);

            var durationField = new FloatField("Duration:");

            durationField.value = transition.duration;

            modalContent.Add(durationField);

            TypeField.RegisterCallback <ChangeEvent <System.Enum> >((evt) =>
            {
                transition.Type = (MTransition.TransitionType)evt.newValue;
            });

            durationField.RegisterCallback <ChangeEvent <float> >((evt) =>
            {
                transition.duration = evt.newValue;
            });
        }
Exemplo n.º 8
0
        public void CleanTest()
        {
            FloatField target = new FloatField();

            // Default test
            Assert.AreEqual((float?)12.2, (float?)target.Clean("12.2"));

            AssertExtras.Raises <ValidationException>(delegate {
                target.Clean(null);
            }).WithMessage("This field is required.");
            AssertExtras.Raises <ValidationException>(delegate {
                target.Clean("abc");
            }).WithMessage("Enter a number.");

            target.MinValue = (float?)5;
            AssertExtras.Raises <ValidationException>(delegate {
                target.Clean("4.65");
            }).WithMessage("Ensure this value is greater than or equal to 5.");
            Assert.AreEqual((float?)5.5, (float?)target.Clean("5.5"));

            target.MaxValue = (float?)10.3;
            AssertExtras.Raises <ValidationException>(delegate {
                target.Clean("15");
            }).WithMessage("Ensure this value is less than or equal to 10.3.");
            Assert.AreEqual((float?)10.2, (float?)target.Clean("10.2"));

            target.Required = false;
            Assert.IsNull(target.Clean(null));
        }
Exemplo n.º 9
0
        void AddRealtimeFields(MixtureNode node, MixtureGraphView owner)
        {
            doubleBuffered = new Toggle("Double Buffered")
            {
                value = node.rtSettings.doubleBuffered,
            };
            doubleBuffered.RegisterValueChangedCallback(e => {
                owner.RegisterCompleteObjectUndo("Set Double Buffered " + e.newValue);
                node.rtSettings.doubleBuffered = e.newValue;
                onChanged?.Invoke();
            });

            Add(doubleBuffered);

            refreshMode = new EnumField("Refresh Mode", node.rtSettings.refreshMode);
            refreshMode.RegisterValueChangedCallback(e => {
                owner.RegisterCompleteObjectUndo("Set Refresh Mode " + e.newValue);
                node.rtSettings.refreshMode = (RefreshMode)e.newValue;
                onChanged?.Invoke();
            });

            Add(refreshMode);

            period = new FloatField("Period")
            {
                value = node.rtSettings.period
            };
            period.RegisterValueChangedCallback(e => {
                owner.RegisterCompleteObjectUndo("Set Period " + e.newValue);
                node.rtSettings.period = e.newValue;
                onChanged?.Invoke();
            });

            Add(period);
        }
Exemplo n.º 10
0
        public static void TestFloatField()
        {
            AgentData agent = new AgentData();

            agent.StartNode = new NodeData();

            FloatField floatField = new FloatField();

            floatField.FieldName = "FloatField";
            floatField.Value     = 100.001f;
            agent.StartNode.Fields.Add(floatField);

            RepeatFloatField repeatFloatField = new RepeatFloatField();

            repeatFloatField.FieldName = "RepeatIntField";
            repeatFloatField.Value     = new List <float>();
            repeatFloatField.Value.Add(1.1f);
            repeatFloatField.Value.Add(100.11f);
            repeatFloatField.Value.Add(1000.11f);
            repeatFloatField.Value.Add(10000.1119f);
            agent.StartNode.Fields.Add(repeatFloatField);

            byte[]    bytes       = Serializer.Serialize(agent);
            AgentData deAgentData = Serializer.DeSerialize <AgentData>(bytes);
        }
Exemplo n.º 11
0
        public SliderFloatControl(float value, float min, float max)
        {
            _slider = new Slider(min, max);
            _text   = new FloatField();

            Setup(value);
        }
        void LoadTemplate()
        {
            AddToClassList("timeField");
            m_FieldName = new Label();
            m_FieldName.AddToClassList("timeFieldNameLabel");
            Add(m_FieldName);
            var inputContainer = new VisualElement();

            inputContainer.AddToClassList("timeFieldInputContainer");
            Add(inputContainer);

            m_SecondsField = new FloatField("Seconds");
            m_SecondsField.AddToClassList("timeInput");
            m_SecondsField.RegisterValueChangedCallback(OnTimeInSecondsChanged);
            inputContainer.Add(m_SecondsField);

            m_FrameField = new IntegerField("Frame");
            m_FrameField.AddToClassList("timeInput");
            m_FrameField.RegisterValueChangedCallback(OnFrameChanged);
            inputContainer.Add(m_FrameField);

            SyncToViewModeSetting();

            RegisterCallback <AttachToPanelEvent>(OnAttachToPanel);
            RegisterCallback <DetachFromPanelEvent>(OnDetachFromPanel);
        }
Exemplo n.º 13
0
        VisualElement CreateSliderWithField(GUIContent label, float value, float min, float max, EventCallback <ChangeEvent <float> > callback)
        {
            var root = new VisualElement()
            {
                name = "Slider Float Field"
            };

            root.AddToClassList(k_SliderRowClass);

            var slider = new Slider(min, max);

            slider.AddToClassList(k_SliderClass);
            slider.RegisterValueChangedCallback(callback);
            slider.SetValueWithoutNotify(value);

            if (label != null && !string.IsNullOrEmpty(label.text))
            {
                slider.label   = label.text;
                slider.tooltip = label.tooltip;
            }

            var field = new FloatField();

            field.AddToClassList(k_SliderFloatFieldClass);
            field.RegisterValueChangedCallback(callback);
            field.SetValueWithoutNotify(value);

            root.Add(slider);
            root.Add(field);

            return(root);
        }
Exemplo n.º 14
0
        private void RefreshScenarioScoreView()
        {
            scenarioScoreView.Clear();

            if (!EditorApplication.isPlaying)
            {
                scenarioScoreView.Add(new Label("Please enter play mode"));
                return;
            }

            var stateManager = ((GameManager)target).GameStateManager;
            var values       = stateManager.ScenarioScoreDict;

            foreach (var kvp in values)
            {
                var field = new FloatField(kvp.Key.ScenarioName)
                {
                    value = kvp.Value
                };
                field.SetEnabled(false);

                if (kvp.Key == stateManager.TopScenario())
                {
                    field.style.color = Color.red;
                }

                scenarioScoreView.Add(field);
            }
        }
    public void CreateGUI()
    {
        VisualElement root = rootVisualElement;

        var           visualTree    = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/Editor/EasePreview.uxml");
        VisualElement labelFromUXML = visualTree.Instantiate();

        labelFromUXML.style.flexGrow = 1;
        root.Add(labelFromUXML);
        var styleSheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/Editor/EasePreview.uss");

        root.styleSheets.Add(styleSheet);

        var selector = root.Q <EnumField>("selector");

        selector.Init(_easeType);
        selector.RegisterValueChangedCallback(SelectorValueChanged);

        _drawPanel = root.Q <VisualElement>("drawPanel");
        _drawPanel.generateVisualContent = DrawEaseFunction;

        _overField = root.Q <FloatField>("overshootOrAmplitude");
        _overField.RegisterValueChangedCallback(ParaChangedOvershootOrAmplitude);
        _overField.visible = false;
        _periodField       = root.Q <FloatField>("period");
        _periodField.RegisterValueChangedCallback(ParaChangedPeriod);
        _periodField.visible = false;

        root.Bind(new SerializedObject(this));
    }
Exemplo n.º 16
0
        internal VisualElement CreateGUI(
            ValueChangedCallback valueChangedCallback,
            float fieldToDraw,
            string labelName,
            out VisualElement propertyFloatField,
            int indentLevel = 0)
        {
            var floatField = new FloatField {
                label = "X", value = fieldToDraw
            };

            floatField.labelElement.style.minWidth = 15;

            if (valueChangedCallback != null)
            {
                floatField.RegisterValueChangedCallback(evt => { valueChangedCallback((float)evt.newValue); });
            }

            propertyFloatField = floatField;

            var defaultRow = new PropertyRow(PropertyDrawerUtils.CreateLabel(labelName, indentLevel));

            defaultRow.Add(propertyFloatField);
            defaultRow.styleSheets.Add(Resources.Load <StyleSheet>("Styles/PropertyRow"));
            return(defaultRow);
        }
Exemplo n.º 17
0
        // -----------------------------------------------------------------------------------------

        public void Generate_Broadcaster_Vertical_Spacing_Field()
        {
            var floatProp = new FloatProperty();

            floatProp.PropertyName  = _TranzmitGraphView.VerticalYSpacing_Broadcaster.PropertyName;
            floatProp.PropertyValue = _TranzmitGraphView.VerticalYSpacing_Broadcaster.PropertyValue;

            var visualElement   = new VisualElement();
            var blackboardField = new BlackboardField {
                text = floatProp.PropertyName, typeText = ""
            };

            visualElement.Add(blackboardField);

            var field = new FloatField("Value:");

            field.value = floatProp.PropertyValue;

            field.RegisterValueChangedCallback(ChangeEvent =>
            {
                _TranzmitGraphView.VerticalYSpacing_Broadcaster.PropertyValue = field.value;

                if (_TranzmitGraphView.CurrentArrangementType == Tranzmit_Graph_View.ArrangementTypes.Vertical)
                {
                    _TranzmitGraphView.Arrange_Broadcaster_Results(Tranzmit_Graph_View.ArrangementTypes.Vertical);
                }
            });

            var blackBoardValueRow = new BlackboardRow(blackboardField, field);

            visualElement.Add(blackBoardValueRow);

            _TranzmitGraphView.Blackboard.Add(visualElement);
        }
Exemplo n.º 18
0
        public CreateVector2Node()
        {
            Initialize("Create Vector2", DefaultNodePosition);
            var inputField = new FloatField {
                label = "x:", value = 0
            };

            inputField.labelElement.style.minWidth = 0;
            inputField.name = "xInput";
            inputField.RegisterValueChangedCallback(evt => {
                CodeGraph.Instance.InvalidateSaveButton();
                x = evt.newValue;
            });
            inputContainer.Add(inputField);

            var inputField2 = new FloatField {
                label = "y:", value = 0
            };

            inputField2.labelElement.style.minWidth = 0;
            inputField2.name = "yInput";
            inputField2.RegisterValueChangedCallback(evt => {
                CodeGraph.Instance.InvalidateSaveButton();
                y = evt.newValue;
            });
            inputContainer.Add(inputField2);

            var valuePort = base.InstantiatePort(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, typeof(float));

            valuePort.portName = "value (2)";
            AddOutputPort(valuePort, () => $"new Vector2({x}f,{y}f)");
            Refresh();
        }
Exemplo n.º 19
0
        public override VisualElement Build()
        {
            base.Build();
            var range = DrawerAttribute;

            m_Field.lowValue  = TypeConversion.Convert <float, TFieldType>(Mathf.Max(range.min, LowValue));
            m_Field.highValue = TypeConversion.Convert <float, TFieldType>(Mathf.Min(range.max, HighValue));

            var root = new VisualElement();

            root.Add(m_Field);
            m_Field.style.flexGrow = 1;
            m_ValueField           = new FloatField
            {
                name    = Name,
                label   = null,
                tooltip = Tooltip,
            };
            m_ValueField.formatString = "0.##";
            m_ValueField.RegisterValueChangedCallback(OnChanged);
            m_ValueField.style.flexGrow = 0;
            m_ValueField.style.width    = 50;
            root.Add(m_ValueField);
            root.style.flexDirection = FlexDirection.Row;
            return(root);
        }
        public BaseNodeUI()
        {
            VisualElement container = new VisualElement();

            title = DefaultName;
            Label titleLabel = (Label)titleContainer[0];

            titleContainer.RemoveAt(0);

            NameField = new TextField();
            NameField.style.flexGrow = 1f;

            container.Add(titleLabel);
            container.Add(NameField);

            titleContainer.Insert(0, container);

            _speedField = new FloatField("Speed");
            _speedField.SetValueWithoutNotify(1f);
            _speedField.AddToClassList("speed-field");
            mainContainer.Insert(1, _speedField);

            RefreshExpandedState();
            RefreshPorts();
        }
        void AddField(Vector4 initialValue, int index, string subLabel)
        {
            var dummy = new VisualElement {
                name = "dummy"
            };
            var label = new Label(subLabel);

            dummy.Add(label);
            Add(dummy);
            var field = new FloatField {
                userData = index, value = initialValue[index]
            };
            var dragger = new FieldMouseDragger <double>(field);

            dragger.SetDragZone(label);
            field.Q("unity-text-input").RegisterCallback <KeyDownEvent>(evt =>
            {
                // Record Undo for input field edit
                if (m_UndoGroup == -1)
                {
                    m_UndoGroup = Undo.GetCurrentGroup();
                    m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
                }
                // Handle scaping input field edit
                if (evt.keyCode == KeyCode.Escape && m_UndoGroup > -1)
                {
                    Undo.RevertAllDownToGroup(m_UndoGroup);
                    m_UndoGroup = -1;
                    evt.StopPropagation();
                }
                // Dont record Undo again until input field is unfocused
                m_UndoGroup++;
                this.MarkDirtyRepaint();
            });
            // Called after KeyDownEvent
            field.RegisterValueChangedCallback(evt =>
            {
                // Only true when setting value via FieldMouseDragger
                // Undo recorded once per dragger release
                if (m_UndoGroup == -1)
                {
                    m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
                }
                var value = m_Get();
                if (value[index] != (float)evt.newValue)
                {
                    value[index] = (float)evt.newValue;
                    m_Set(value);
                    m_Node.Dirty(ModificationScope.Node);
                }
            });
            // Reset UndoGroup when done editing input field & update title
            field.Q("unity-text-input").RegisterCallback <FocusOutEvent>(evt =>
            {
                m_Node.owner.owner.isDirty = true;
                m_UndoGroup = -1;
            });
            Add(field);
        }
Exemplo n.º 22
0
        static void CreateField <T>(string label, IConstantEditorBuilder builder, VisualElement container, T oldValue, float fieldValue, Func <ChangeEvent <float>, T> generateValue)
        {
            var field = new FloatField(label);

            field.value = fieldValue;
            container.Add(field);
            field.RegisterValueChangedCallback(evt => Dispatch(builder, oldValue, generateValue(evt)));
        }
Exemplo n.º 23
0
        public static void SetFloatFieldRange(this FloatField field, float min = float.MinValue, float max = float.MaxValue)
        {
            k_FloatFieldRanges[field] = new Tuple <float, float>(min, max);
            field.RegisterValueChangedCallback(OnFloatFieldValueChanged);
            field.RegisterCallback <DetachFromPanelEvent>(OnFloatFieldDetachedFromPanel);

            ClampFloatFieldValue(field.value, field);
        }
Exemplo n.º 24
0
    public void SetData(WidgetDataLaunchCommandElement data)
    {
        _widgetData = data;

        _nameLabel.text     = data.GameConsoleInvokable.DisplayName;
        _activeToggle.value = data.Active;
        _paramsContainer.Clear();

        int paramIndex = 0;

        foreach (IGameConsoleParameter param in data.GameConsoleInvokable.Parameters)
        {
            if (param.Type == typeof(bool))
            {
                var field = new Toggle();
                bool.TryParse(TryPopParam(), out bool val);
                field.value = val;
                field.RegisterValueChangedCallback((evt) => OnParameterModified());
                _paramsContainer.Add(field);
            }
            else if (param.Type == typeof(int))
            {
                var field = new IntegerField();
                int.TryParse(TryPopParam(), out int val);
                field.value = val;
                field.RegisterValueChangedCallback((evt) => OnParameterModified());
                _paramsContainer.Add(field);
            }
            else if (param.Type == typeof(float))
            {
                var field = new FloatField();
                float.TryParse(TryPopParam(), out float val);
                field.value = val;
                field.RegisterValueChangedCallback((evt) => OnParameterModified());
                _paramsContainer.Add(field);
            }
            else
            {
                var field = new TextField();
                field.value = TryPopParam();
                field.RegisterValueChangedCallback((evt) => OnParameterModified());
                _paramsContainer.Add(field);
            }
        }

        _nameLabel.SetEnabled(data.Active);
        foreach (var item in _paramsContainer.Children())
        {
            item.SetEnabled(data.Active);
        }

        OnParameterModified();

        string TryPopParam()
        {
            if (data.Parameters == null)
            {
                return(default);
Exemplo n.º 25
0
        FloatField AddField(VisualElement panel, string label, int index, Vector3 initValiue)
        {
            var field = new FloatField {
                userData = index, value = initValiue[index]
            };

            if (label != "")
            {
                var l = new Label(label);
                panel.Add(l);
                var dragger = new FieldMouseDragger <double>(field);
                dragger.SetDragZone(l);
            }

            field.RegisterCallback <MouseDownEvent>(Repaint);
            field.RegisterCallback <MouseMoveEvent>(Repaint);
            field.OnValueChanged(evt =>
            {
                var value    = (Vector3)m_PropertyInfo.GetValue(m_Node, null);
                value[index] = (float)evt.newValue;
                m_PropertyInfo.SetValue(m_Node, value, null);
                m_UndoGroup = -1;
                UpdateSlider(m_SliderPanel, index, value);
                this.MarkDirtyRepaint();
            });
            field.RegisterCallback <InputEvent>(evt =>
            {
                if (m_UndoGroup == -1)
                {
                    m_UndoGroup = Undo.GetCurrentGroup();
                    m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
                }
                float newValue;
                if (!float.TryParse(evt.newData, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out newValue))
                {
                    newValue = 0f;
                }
                var value    = (Vector3)m_PropertyInfo.GetValue(m_Node, null);
                value[index] = newValue;
                m_PropertyInfo.SetValue(m_Node, value, null);
                this.MarkDirtyRepaint();
            });
            field.RegisterCallback <KeyDownEvent>(evt =>
            {
                if (evt.keyCode == KeyCode.Escape && m_UndoGroup > -1)
                {
                    Undo.RevertAllDownToGroup(m_UndoGroup);
                    m_UndoGroup = -1;
                    m_Value     = (Vector3)m_PropertyInfo.GetValue(m_Node, null);
                    UpdateSlider(m_SliderPanel, index, m_Value);
                    evt.StopPropagation();
                }
                this.MarkDirtyRepaint();
            });
            panel.Add(field);
            return(field);
        }
Exemplo n.º 26
0
 ConstantFloat() : base()
 {
     title = "Constant Float";
     AddOutputPort <float>("Value");
     RefreshPorts();
     m_FloatField = new FloatField();
     extensionContainer.Add(m_FloatField);
     RefreshExpandedState();
 }
Exemplo n.º 27
0
        protected void AddProperty <Data>(GUIContent displayName, Func <Data> getter, Action <Data> setter, int indentLevel = 0)
        {
            // Create UIElement from type:
            BaseField <Data> elem     = null;
            BaseField <Enum> elemEnum = null;

            switch (getter())
            {
            case bool b: elem = new Toggle {
                    value = b
            } as BaseField <Data>; break;

            case int i: elem = new IntegerField {
                    value = i, isDelayed = true
            } as BaseField <Data>; break;

            case float f: elem = new FloatField {
                    value = f, isDelayed = true
            } as BaseField <Data>; break;

            case Enum e: elemEnum = new EnumField(e)
            {
                    value = e
            }; break;

            default: throw new Exception($"Can't create UI field for type {getter().GetType()}, please add it if it's relevant. If you can't consider using TargetPropertyGUIContext.AddProperty instead.");
            }

            if (elem != null)
            {
                context.AddProperty <Data>(displayName.text, displayName.tooltip, indentLevel, elem, (evt) =>
                {
                    if (Equals(getter(), evt.newValue))
                    {
                        return;
                    }

                    registerUndo(displayName.text);
                    setter(evt.newValue);
                    onChange();
                });
            }
            else
            {
                context.AddProperty <Enum>(displayName.text, displayName.tooltip, indentLevel, elemEnum, (evt) =>
                {
                    if (Equals(getter(), evt.newValue))
                    {
                        return;
                    }

                    registerUndo(displayName.text);
                    setter((Data)(object)evt.newValue);
                    onChange();
                });
            }
        }
Exemplo n.º 28
0
        public static VisualElement GetElementOfFloatField(float startValue, string fieldName, Action <object> setValue, Action <object> getValue)
        {
            FloatField field = new FloatField(fieldName);

            field.SetValueWithoutNotify(startValue);
            field.RegisterValueChangedCallback(s => setValue.Invoke(s.newValue));
            getValue += o => field.SetValueWithoutNotify((float)o);
            return(field);
        }
Exemplo n.º 29
0
        static void AddDistanceFloatField(string name, string label, VisualElement root)
        {
            var field = new FloatField(label)
            {
                name = name
            };

            field.SetEnabled(false);
            root.Add(field);
        }
Exemplo n.º 30
0
        public static void RenderFloatProperty(VisualElement container, string name, object value,
                                               Action <object> setter)
        {
            var field = new FloatField(name);

            field.SetValueWithoutNotify((float)value);
            field.MarkDirtyRepaint();
            field.RegisterValueChangedCallback(evt => setter(evt.newValue));
            container.Add(field);
        }
Exemplo n.º 31
0
    public PotentialField(
        NavigationField navigationField,
        Target target)
    {
        Size = navigationField.fieldSize;
        NavigationField = navigationField;
        Target = target;
        Potentials = new FloatField(navigationField.fieldSize);
        Flows = new Vector2Field(navigationField.fieldSize);

        _heap =
            new MaxHeap<CellPotentialHeapEntry>
            {
                RemoveAction = CellPotentialHeapEntry.ReturnCellCostHeapEntry
            };
    }
Exemplo n.º 32
0
 public void Start()
 {
     Instance = this;
     _halfGrid = new Vector2(gridSize * 0.5f, gridSize * 0.5f);
     Costs = new FloatField(fieldSize);
     Populate();
 }