示例#1
0
        protected override void SetupInputFields(int width = 3, int height = 3)
        {
            style.alignContent  = new StyleValue <Align>(Align.Center);
            style.alignItems    = new StyleValue <Align>(Align.Center);
            style.flexDirection = new StyleValue <FlexDirection>(FlexDirection.Row);

            const int pad         = 4;
            var       fieldWidth  = (this.style.width / width) - pad - 2;
            var       fieldHeight = (this.style.height / height / 2) - pad;

            for (var i = 0; i < width; i++)
            {
                var x         = (fieldWidth + pad) * i;
                var container = new VisualContainer();
                container.style.width         = fieldWidth;
                container.style.flexDirection = FlexDirection.Row;
                for (var j = 0; j < height; j++)
                {
                    var input = new FloatField(6);
                    input.style.width        = fieldWidth - 16;
                    input.style.positionLeft = x;
                    input.style.positionTop  = fieldHeight * j;
                    input.style.positionType = PositionType.Absolute;
                    input.OnValueChanged(OnMatrixInputUpdate);
                    MatrixInputs[i, j] = input;
                    container.Add(input);
                }

                Add(container);
            }
        }
示例#2
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);
        }
        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.OnValueChanged(evt =>
            {
                var value    = m_Get();
                value[index] = (float)evt.newValue;
                m_Set(value);
                m_Node.Dirty(ModificationScope.Node);
                m_UndoGroup = -1;
            });
            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, out newValue))
                {
                    newValue = 0f;
                }
                var value = m_Get();
                if (Math.Abs(value[index] - newValue) > 1e-9)
                {
                    value[index] = newValue;
                    m_Set(value);
                    m_Node.Dirty(ModificationScope.Node);
                }
            });
            field.RegisterCallback <KeyDownEvent>(evt =>
            {
                if (evt.keyCode == KeyCode.Escape && m_UndoGroup > -1)
                {
                    Undo.RevertAllDownToGroup(m_UndoGroup);
                    m_UndoGroup = -1;
                    evt.StopPropagation();
                }
                Dirty(ChangeType.Repaint);
            });
            Add(field);
        }
示例#4
0
        void AddField(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 = m_Value[index]
            };
            var dragger = new FieldMouseDragger <double>(field);

            dragger.SetDragZone(label);
            field.RegisterCallback <MouseDownEvent>(Repaint);
            field.RegisterCallback <MouseMoveEvent>(Repaint);
            field.OnValueChanged(evt =>
            {
                var value    = GetValue();
                value[index] = (float)evt.newValue;
                SetValue(value);
                m_UndoGroup = -1;
                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, out newValue))
                {
                    newValue = 0f;
                }
                var value    = GetValue();
                value[index] = newValue;
                SetValue(value);
                this.MarkDirtyRepaint();
            });
            field.RegisterCallback <KeyDownEvent>(evt =>
            {
                if (evt.keyCode == KeyCode.Escape && m_UndoGroup > -1)
                {
                    Undo.RevertAllDownToGroup(m_UndoGroup);
                    m_UndoGroup = -1;
                    m_Value     = GetValue();
                    evt.StopPropagation();
                }
                this.MarkDirtyRepaint();
            });
            Add(field);
        }
示例#5
0
        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 <float>(field);

            dragger.SetDragZone(label);
            field.OnValueChanged(evt =>
            {
                var value    = _get();
                value[index] = (float)evt.newValue;
                _set(value);
                _nodeEditor.SetDirty();
                _undoGroup = -1;
            });
            field.RegisterCallback <InputEvent>(evt =>
            {
                if (_undoGroup == -1)
                {
                    _undoGroup = Undo.GetCurrentGroup();
                    _nodeEditor.Owner.LogicGraphEditorObject.RegisterCompleteObjectUndo("Change " + _nodeEditor.NodeType());
                }
                if (!float.TryParse(evt.newData, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out var newValue))
                {
                    newValue = 0f;
                }
                var value = _get();
                if (Math.Abs(value[index] - newValue) > 1e-9)
                {
                    value[index] = newValue;
                    _set(value);
                    _nodeEditor.SetDirty();
                }
            });
            field.RegisterCallback <KeyDownEvent>(evt =>
            {
                if (evt.keyCode == KeyCode.Escape && _undoGroup > -1)
                {
                    Undo.RevertAllDownToGroup(_undoGroup);
                    _undoGroup = -1;
                    evt.StopPropagation();
                }
                MarkDirtyRepaint();
            });
            Add(field);
        }
示例#6
0
 public SliderWithFloatField(float start, float end, float initial)
 {
     m_Slider = new Slider(start, end)
     {
         style = { flexGrow = 1f }
     };
     m_FloatField = new FloatField()
     {
         style = { flexGrow = 0.8f, flexShrink = 1f }
     };
     m_Slider.OnValueChanged(e => e.target     = this);
     m_Slider.OnValueChanged(e => value        = e.newValue);
     m_FloatField.OnValueChanged(e => e.target = this);
     m_FloatField.OnValueChanged(e => value    = e.newValue);
     OnValueChanged(e => m_Slider.value        = e.newValue);
     OnValueChanged(e => m_FloatField.value    = e.newValue);
     value = initial;
     style.flexDirection = FlexDirection.Row;
     Add(m_Slider);
     Add(m_FloatField);
 }
示例#7
0
        public void BindElements()
        {
            m_ModeField             = this.Q <EnumField>("ModeField");
            m_BonePopupContainer    = this.Q <VisualElement>("BoneEnumPopup");
            m_NormalizeToggle       = this.Q <Toggle>("NormalizeToggle");
            m_SizeField             = this.Q <IntegerField>("SizeField");
            m_HardnessField         = this.Q <IntegerField>("HardnessField");
            m_StepField             = this.Q <IntegerField>("StepField");
            m_AmountSlider          = this.Q <Slider>("AmountSlider");
            m_AmountField           = this.Q <FloatField>("AmountField");
            m_AmountField.isDelayed = true;
            m_WeightInspectorPanel  = this.Q <WeightInspectorIMGUIPanel>("WeightsInspector");
            m_PopupWindow           = this.Q <UnityEngine.Experimental.UIElements.PopupWindow>();

            LinkSliderToIntegerField(this.Q <Slider>("HardnessSlider"), m_HardnessField);
            LinkSliderToIntegerField(this.Q <Slider>("StepSlider"), m_StepField);

            m_ModeField.OnValueChanged((evt) =>
            {
                SetupMode();
            });

            m_AmountSlider.valueChanged += (val) =>
            {
                if (!val.Equals(m_AmountField.value))
                {
                    m_AmountField.value = (float)System.Math.Round((double)val, 2);
                }
            };
            m_AmountField.OnValueChanged((evt) =>
            {
                var newValue = Mathf.Clamp(evt.newValue, m_AmountSlider.lowValue, m_AmountSlider.highValue);

                if (focusController.focusedElement == m_AmountField && !newValue.Equals(m_AmountSlider.value))
                {
                    sliderStarted();
                    sliderChanged(newValue);
                    sliderEnded();
                    Focus();
                    m_AmountField.value  = 0f;
                    m_AmountSlider.value = 0f;
                }
            });

            m_WeightInspectorPanel.weightsChanged += () => weightsChanged();
        }
示例#8
0
        FloatField AddField(VisualElement panel, Slider slider, int index, DielectricSpecularNode.DielectricMaterial initMaterial)
        {
            float initValue;

            if (index == 1)
            {
                initValue = initMaterial.indexOfRefraction;
            }
            else
            {
                initValue = initMaterial.range;
            }

            var field = new FloatField {
                userData = index, value = initValue
            };

            field.RegisterCallback <MouseDownEvent>(Repaint);
            field.RegisterCallback <MouseMoveEvent>(Repaint);
            field.OnValueChanged(evt =>
            {
                var value      = (DielectricSpecularNode.DielectricMaterial)m_PropertyInfo.GetValue(m_Node, null);
                var fieldValue = (float)evt.newValue;
                if (index == 1)
                {
                    value.indexOfRefraction = fieldValue;
                    RedrawIORControls(fieldValue);
                }
                else
                {
                    value.range = fieldValue;
                    RedrawRangeControls(fieldValue);
                }
                m_PropertyInfo.SetValue(m_Node, value, null);
                m_UndoGroup = -1;
                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, out newValue))
                {
                    newValue = 0f;
                }
                var value = (DielectricSpecularNode.DielectricMaterial)m_PropertyInfo.GetValue(m_Node, null);
                if (index == 1)
                {
                    value.indexOfRefraction = newValue;
                }
                else
                {
                    value.range = 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;
                    var value   = (DielectricSpecularNode.DielectricMaterial)m_PropertyInfo.GetValue(m_Node, null);
                    if (index == 1)
                    {
                        RedrawIORControls(value.indexOfRefraction);
                    }
                    else
                    {
                        RedrawRangeControls(value.range);
                    }
                    evt.StopPropagation();
                }
                this.MarkDirtyRepaint();
            });
            panel.Add(field);
            return(field);
        }
        public BlackboardFieldPropertyView(AbstractNodeGraph graph, INodeProperty property)
        {
            AddStyleSheetPath("Styles/NodeGraphBlackboard");
            m_Graph = graph;

            m_Reference = new TextField();
            m_Reference.OnValueChanged(evt =>
            {
                property.reference = evt.newValue;
                DirtyNodes(ModificationScope.Graph);
            });
            m_Reference.value = property.reference;
            AddRow("Reference", m_Reference);

            if (property is ValueProperty <float> )
            {
                var        floatProperty = (ValueProperty <float>)property;
                FloatField floatField    = new FloatField {
                    value = floatProperty.value
                };
                floatField.OnValueChanged(evt =>
                {
                    floatProperty.value = (float)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", floatField);

                /*if (floatProperty.floatType == FloatType.Slider)
                 * {
                 *  var minField = new FloatField { value = floatProperty.rangeValues.x };
                 *  minField.OnValueChanged(minEvt =>
                 *      {
                 *          floatProperty.rangeValues = new Vector2((float)minEvt.newValue, floatProperty.rangeValues.y);
                 *          floatProperty.value = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x);
                 *          floatField.value = floatProperty.value;
                 *          DirtyNodes();
                 *      });
                 *  minRow = AddRow("Min", minField);
                 *  var maxField = new FloatField { value = floatProperty.rangeValues.y };
                 *  maxField.OnValueChanged(maxEvt =>
                 *      {
                 *          floatProperty.rangeValues = new Vector2(floatProperty.rangeValues.x, (float)maxEvt.newValue);
                 *          floatProperty.value = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x);
                 *          floatField.value = floatProperty.value;
                 *          DirtyNodes();
                 *      });
                 *  maxRow = AddRow("Max", maxField);
                 * }*/
            }
            else if (property is ValueProperty <int> )
            {
                var intProperty = (ValueProperty <int>)property;

                var field = new IntegerField {
                    value = intProperty.value
                };
                field.OnValueChanged(intEvt =>
                {
                    intProperty.value = intEvt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is ValueProperty <Vector2> )
            {
                var vectorProperty = (ValueProperty <Vector2>)property;
                var field          = new Vector2Field {
                    value = vectorProperty.value
                };
                field.OnValueChanged(evt =>
                {
                    vectorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is ValueProperty <Vector3> )
            {
                var vectorProperty = (ValueProperty <Vector3>)property;
                var field          = new Vector3Field {
                    value = vectorProperty.value
                };
                field.OnValueChanged(evt =>
                {
                    vectorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is ValueProperty <Vector4> )
            {
                var vectorProperty = (ValueProperty <Vector4>)property;
                var field          = new Vector4Field {
                    value = vectorProperty.value
                };
                field.OnValueChanged(evt =>
                {
                    vectorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is ValueProperty <Color> )
            {
                var colorProperty = (ValueProperty <Color>)property;
                //todo add HDR
                var colorField = new ColorField {
                    value = (Color)property.defaultValue, showEyeDropper = false
                };
                colorField.OnValueChanged(evt =>
                {
                    colorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", colorField);
            }
            else if (property is ValueProperty <Texture2D> )
            {
                var textureProperty = (ValueProperty <Texture2D>)property;
                var field           = new ObjectField {
                    value = textureProperty.value, objectType = typeof(Texture2D)
                };
                field.OnValueChanged(evt =>
                {
                    textureProperty.value = (Texture2D)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is ValueProperty <Cubemap> )
            {
                var cubemapProperty = (ValueProperty <Cubemap>)property;
                var field           = new ObjectField {
                    value = cubemapProperty.value, objectType = typeof(Cubemap)
                };
                field.OnValueChanged(evt =>
                {
                    cubemapProperty.value = (Cubemap)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is ValueProperty <bool> )
            {
                var booleanProperty = (ValueProperty <bool>)property;
                EventCallback <ChangeEvent <bool> > onBooleanChanged = evt =>
                {
                    booleanProperty.value = evt.newValue;
                    DirtyNodes();
                };
                var field = new Toggle();
                field.OnValueChanged(onBooleanChanged);
                field.value = booleanProperty.value;
                AddRow("Default", field);
            }
//            AddRow("Type", new TextField());
//            AddRow("Exposed", new Toggle(null));
//            AddRow("Range", new Toggle(null));
//            AddRow("Default", new TextField());
//            AddRow("Tooltip", new TextField());


            AddToClassList("sgblackboardFieldPropertyView");
        }