Esempio n. 1
0
        public ColorControlView(string label, ColorMode colorMode, AbstractMaterialNode node, PropertyInfo propertyInfo)
        {
            m_Node         = node;
            m_PropertyInfo = propertyInfo;
            AddStyleSheetPath("Styles/Controls/ColorControlView");
            if (propertyInfo.PropertyType != typeof(Color))
            {
                throw new ArgumentException("Property must be of type Color.", "propertyInfo");
            }
            label = label ?? ObjectNames.NicifyVariableName(propertyInfo.Name);

            m_Color = (Color)m_PropertyInfo.GetValue(m_Node, null);

            if (!string.IsNullOrEmpty(label))
            {
                Add(new Label(label));
            }

            m_ColorField = new ColorField {
                value = m_Color.color, hdr = m_Color.mode == ColorMode.HDR, showEyeDropper = false
            };
            m_ColorField.OnValueChanged(OnChange);
            Add(m_ColorField);

            VisualElement enumPanel = new VisualElement {
                name = "enumPanel"
            };

            enumPanel.Add(new Label("Mode"));
            var enumField = new EnumField(m_Color.mode);

            enumField.OnValueChanged(OnModeChanged);
            enumPanel.Add(enumField);
            Add(enumPanel);
        }
        public EnumConversionControlView(AbstractMaterialNode node, PropertyInfo propertyInfo)
        {
            if (!propertyInfo.PropertyType.GetInterfaces().Any(t => t == typeof(IEnumConversion)))
            {
                throw new ArgumentException("Property type must implement IEnumConversion.");
            }

            m_Node         = node;
            m_PropertyInfo = propertyInfo;
            var currentValue = value;

            var ec = (IEnumConversion)propertyInfo.GetValue(m_Node, null);

            propertyInfo.SetValue(m_Node, ec, null);

            var fromField = new EnumField(currentValue.from);

            fromField.OnValueChanged(OnFromChanged);
            Add(fromField);

            var arrowLabel = new Label("➔");

            Add(arrowLabel);

            var toField = new EnumField(currentValue.to);

            toField.OnValueChanged(OnToChanged);
            Add(toField);
        }
        public EnumControlView(ControlAttribute attribute, AbstractNode node, ReflectionProperty property)
        {
            var viewCont = new VisualElement();

            viewCont.AddToClassList("ControlField");

            if (!string.IsNullOrEmpty(attribute.label))
            {
                viewCont.Add(new Label(attribute.label)
                {
                    name = DefaultControlView.ControlLabelName
                });
            }

#if UNITY_EDITOR
            var enumField = new EnumField((Enum)property.GetValue(node))
            {
                name = DefaultControlView.ValueFieldName
            };
            enumField.OnValueChanged(e =>
            {
                node.owner.owner.RegisterCompleteObjectUndo("Enum Change");
                property.SetValue(node, e.newValue);
                node.Dirty(ModificationScope.Node);
            });
            viewCont.Add(enumField);
#endif
            Add(viewCont);
        }
        public UVSlotControlView(UVMaterialSlot slot)
        {
            m_Slot = slot;
            var enumField = new EnumField(slot.channel);

            enumField.OnValueChanged(OnValueChanged);
            Add(enumField);
        }
Esempio n. 5
0
        public UVSlotControlView(UVMaterialSlot slot)
        {
            AddStyleSheetPath("Styles/Controls/UVSlotControlView");
            m_Slot = slot;
            var enumField = new EnumField(slot.channel);

            enumField.OnValueChanged(OnValueChanged);
            Add(enumField);
        }
Esempio n. 6
0
        public ScreenPositionSlotControlView(ScreenPositionMaterialSlot slot)
        {
            AddStyleSheetPath("Styles/Controls/ScreenPositionSlotControlView");
            m_Slot = slot;
            var enumField = new EnumField(slot.screenSpaceType);

            enumField.OnValueChanged(OnValueChanged);
            Add(enumField);
        }
Esempio n. 7
0
        public DielectricSpecularControlView(AbstractMaterialNode node, PropertyInfo propertyInfo)
        {
            m_Node         = node;
            m_PropertyInfo = propertyInfo;

            AddStyleSheetPath("Styles/Controls/DielectricSpecularControlView");
            m_DielectricMaterial = (DielectricSpecularNode.DielectricMaterial)m_PropertyInfo.GetValue(m_Node, null);

            if (propertyInfo.PropertyType != typeof(DielectricSpecularNode.DielectricMaterial))
            {
                throw new ArgumentException("Property must be of type DielectricMaterial.", "propertyInfo");
            }

            var enumPanel = new VisualElement {
                name = "enumPanel"
            };

            enumPanel.Add(new Label("Material"));
            var enumField = new EnumField(m_DielectricMaterial.type);

            enumField.OnValueChanged(OnEnumChanged);
            enumPanel.Add(enumField);
            Add(enumPanel);

            m_RangePanel = new VisualElement {
                name = "sliderPanel"
            };
            m_RangePanel.Add(new Label("Range"));
            Action <float> changedRangeSlider = (s) => { OnChangeRangeSlider(s); };

            m_RangeSlider = new Slider(0.01f, 1, changedRangeSlider)
            {
                value = m_DielectricMaterial.range
            };
            m_RangePanel.Add(m_RangeSlider);
            m_RangeField = AddField(m_RangePanel, m_RangeSlider, 0, m_DielectricMaterial);
            m_RangePanel.SetEnabled(m_DielectricMaterial.type == DielectricMaterialType.Common);
            Add(m_RangePanel);

            m_IORPanel = new VisualElement {
                name = "sliderPanel"
            };
            m_IORPanel.Add(new Label("IOR"));
            Action <float> changedIORSlider = (s) => { OnChangeIORSlider(s); };

            m_IORSlider = new Slider(1, 2.5f, changedIORSlider)
            {
                value = m_DielectricMaterial.indexOfRefraction
            };
            m_IORPanel.Add(m_IORSlider);
            m_IORField = AddField(m_IORPanel, m_IORSlider, 1, m_DielectricMaterial);
            m_IORPanel.SetEnabled(m_DielectricMaterial.type == DielectricMaterialType.Custom);
            Add(m_IORPanel);
        }
Esempio n. 8
0
        public EnumControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
        {
            m_Node         = node;
            m_PropertyInfo = propertyInfo;
            if (!propertyInfo.PropertyType.IsEnum)
            {
                throw new ArgumentException("Property must be an enum.", "propertyInfo");
            }
            Add(new Label(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name)));
            var enumField = new EnumField((Enum)m_PropertyInfo.GetValue(m_Node, null));

            enumField.OnValueChanged(OnValueChanged);
            Add(enumField);
        }
Esempio n. 9
0
        public EnumControlView(string label, AbstractLogicNodeEditor logicNodeEditor, PropertyInfo propertyInfo)
        {
            AddStyleSheetPath("Styles/Controls/EnumControlView");
            _logicNodeEditor = logicNodeEditor;
            _propertyInfo    = propertyInfo;
            if (!propertyInfo.PropertyType.IsEnum)
            {
                throw new ArgumentException("Property must be an enum.", nameof(propertyInfo));
            }
            Add(new Label(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name)));
            var enumField = new EnumField((Enum)_propertyInfo.GetValue(_logicNodeEditor, null));

            enumField.OnValueChanged(OnValueChanged);
            Add(enumField);
        }
        public DielectricSpecularControlView(AbstractMaterialNode node, PropertyInfo propertyInfo)
        {
            m_Node               = node;
            m_PropertyInfo       = propertyInfo;
            m_DielectricMaterial = (DielectricSpecularNode.DielectricMaterial)m_PropertyInfo.GetValue(m_Node, null);

            if (propertyInfo.PropertyType != typeof(DielectricSpecularNode.DielectricMaterial))
            {
                throw new ArgumentException("Property must be of type DielectricMaterial.", "propertyInfo");
            }

            var enumPanel = new VisualElement {
                name = "enumPanel"
            };

            enumPanel.Add(new Label("Material"));
            var enumField = new EnumField(m_DielectricMaterial.type);

            enumField.OnValueChanged(OnEnumChanged);
            enumPanel.Add(enumField);
            Add(enumPanel);

            m_RangePanel = new VisualElement {
                name = "sliderPanel"
            };
            m_RangePanel.Add(new Label("Range"));
            Action <float> changedRangeSlider = (s) => { OnChangeRangeSlider(s); };

            m_RangeSlider       = new Slider(0.01f, 1, changedRangeSlider);
            m_RangeSlider.value = 0.5f;
            m_RangePanel.Add(m_RangeSlider);
            m_RangeField = AddField(m_RangePanel, m_RangeSlider, 0, m_DielectricMaterial);
            m_RangePanel.SetEnabled(true);
            Add(m_RangePanel);

            m_IORPanel = new VisualElement {
                name = "sliderPanel"
            };
            m_IORPanel.Add(new Label("IOR"));
            Action <float> changedIORSlider = (s) => { OnChangeIORSlider(s); };

            m_IORSlider       = new Slider(1, 5, changedIORSlider);
            m_IORSlider.value = 1;
            m_IORPanel.Add(m_IORSlider);
            m_IORField = AddField(m_IORPanel, m_IORSlider, 1, m_DielectricMaterial);
            m_IORPanel.SetEnabled(false);
            Add(m_IORPanel);
        }
Esempio n. 11
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();
        }
Esempio n. 12
0
        public override VisualElement InstantiateControl(AbstractNode node, PropertyInfo property)
        {
            var container = new VisualElement();

            container.AddToClassList("ControlField");
            AddLabel(container);
            var enumField = new EnumField((Enum)property.GetValue(node))
            {
                name = "value-field"
            };

            enumField.OnValueChanged(e =>
            {
                node.owner.owner.RegisterCompleteObjectUndo(property.Name + " Changed");
                property.SetValue(node, e.newValue);
                node.Dirty(ModificationScope.Node);
            });
            container.Add(enumField);
            return(container);
        }
Esempio n. 13
0
        public BlackboardFieldPropertyView(AbstractMaterialGraph graph, IShaderProperty property)
        {
            m_Graph = graph;
            if (property is Vector1ShaderProperty)
            {
                VisualElement floatRow   = new VisualElement();
                VisualElement intRow     = new VisualElement();
                VisualElement modeRow    = new VisualElement();
                VisualElement minRow     = new VisualElement();
                VisualElement maxRow     = new VisualElement();
                FloatField    floatField = null;

                var floatProperty = (Vector1ShaderProperty)property;

                if (floatProperty.floatType == FloatType.Integer)
                {
                    var field = new IntegerField {
                        value = (int)floatProperty.value
                    };
                    field.OnValueChanged(intEvt =>
                    {
                        floatProperty.value = (float)intEvt.newValue;
                        DirtyNodes();
                    });
                    intRow = AddRow("Default", field);
                }
                else
                {
                    floatField = new FloatField {
                        value = floatProperty.value
                    };
                    floatField.OnValueChanged(evt =>
                    {
                        floatProperty.value = (float)evt.newValue;
                        DirtyNodes();
                    });
                    floatRow = AddRow("Default", floatField);
                }

                var floatModeField = new EnumField((Enum)floatProperty.floatType);
                floatModeField.value = floatProperty.floatType;
                floatModeField.OnValueChanged(evt =>
                {
                    if (floatProperty.floatType == (FloatType)evt.newValue)
                    {
                        return;
                    }
                    floatProperty           = (Vector1ShaderProperty)property;
                    floatProperty.floatType = (FloatType)evt.newValue;
                    switch (floatProperty.floatType)
                    {
                    case FloatType.Slider:
                        RemoveElements(new VisualElement[] { floatRow, intRow, modeRow, minRow, maxRow });
                        var field = new FloatField {
                            value = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x)
                        };
                        floatProperty.value = (float)field.value;
                        field.OnValueChanged(defaultEvt =>
                        {
                            floatProperty.value = Mathf.Max(Mathf.Min((float)defaultEvt.newValue, floatProperty.rangeValues.y), floatProperty.rangeValues.x);
                            field.value         = floatProperty.value;
                            DirtyNodes();
                        });
                        floatRow     = AddRow("Default", field);
                        field.value  = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x);
                        modeRow      = AddRow("Mode", floatModeField);
                        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);
                            field.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);
                            field.value = floatProperty.value;
                            DirtyNodes();
                        });
                        maxRow = AddRow("Max", maxField);
                        break;

                    case FloatType.Integer:
                        RemoveElements(new VisualElement[] { floatRow, intRow, modeRow, minRow, maxRow });
                        var intField = new IntegerField {
                            value = (int)floatProperty.value
                        };
                        intField.OnValueChanged(intEvt =>
                        {
                            floatProperty.value = (float)intEvt.newValue;
                            DirtyNodes();
                        });
                        intRow  = AddRow("Default", intField);
                        modeRow = AddRow("Mode", floatModeField);
                        break;

                    default:
                        RemoveElements(new VisualElement[] { floatRow, intRow, modeRow, minRow, maxRow });
                        field = new FloatField {
                            value = floatProperty.value
                        };
                        field.OnValueChanged(defaultEvt =>
                        {
                            floatProperty.value = (float)defaultEvt.newValue;
                            DirtyNodes();
                        });
                        floatRow = AddRow("Default", field);
                        modeRow  = AddRow("Mode", floatModeField);
                        break;
                    }
                    DirtyNodes();
                });
                modeRow = AddRow("Mode", floatModeField);

                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 Vector2ShaderProperty)
            {
                var vectorProperty = (Vector2ShaderProperty)property;
                var field          = new Vector2Field {
                    value = vectorProperty.value
                };
                field.OnValueChanged(evt =>
                {
                    vectorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is Vector3ShaderProperty)
            {
                var vectorProperty = (Vector3ShaderProperty)property;
                var field          = new Vector3Field {
                    value = vectorProperty.value
                };
                field.OnValueChanged(evt =>
                {
                    vectorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is Vector4ShaderProperty)
            {
                var vectorProperty = (Vector4ShaderProperty)property;
                var field          = new Vector4Field {
                    value = vectorProperty.value
                };
                field.OnValueChanged(evt =>
                {
                    vectorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is ColorShaderProperty)
            {
                var colorProperty = (ColorShaderProperty)property;
                var colorField    = new ColorField {
                    value = property.defaultValue, showEyeDropper = false, hdr = colorProperty.colorMode == ColorMode.HDR
                };
                colorField.OnValueChanged(evt =>
                {
                    colorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", colorField);
                var colorModeField = new EnumField((Enum)colorProperty.colorMode);
                colorModeField.OnValueChanged(evt =>
                {
                    if (colorProperty.colorMode == (ColorMode)evt.newValue)
                    {
                        return;
                    }
                    colorProperty.colorMode = (ColorMode)evt.newValue;
                    colorField.hdr          = colorProperty.colorMode == ColorMode.HDR;
                    colorField.DoRepaint();
                    DirtyNodes();
                });
                AddRow("Mode", colorModeField);
            }
            else if (property is TextureShaderProperty)
            {
                var textureProperty = (TextureShaderProperty)property;
                var field           = new ObjectField {
                    value = textureProperty.value.texture, objectType = typeof(Texture)
                };
                field.OnValueChanged(evt =>
                {
                    textureProperty.value.texture = (Texture)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is CubemapShaderProperty)
            {
                var cubemapProperty = (CubemapShaderProperty)property;
                var field           = new ObjectField {
                    value = cubemapProperty.value.cubemap, objectType = typeof(Cubemap)
                };
                field.OnValueChanged(evt =>
                {
                    cubemapProperty.value.cubemap = (Cubemap)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is BooleanShaderProperty)
            {
                var    booleanProperty  = (BooleanShaderProperty)property;
                Action onBooleanChanged = () =>
                {
                    booleanProperty.value = !booleanProperty.value;
                    DirtyNodes();
                };
                var field = new Toggle(onBooleanChanged)
                {
                    on = 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");
        }
Esempio n. 14
0
        public BlackboardFieldPropertyView(AbstractMaterialGraph graph, IShaderProperty property)
        {
            AddStyleSheetPath("Styles/ShaderGraphBlackboard");
            m_Graph    = graph;
            m_Property = property;

            m_ExposedToogle = new Toggle(() =>
            {
                property.generatePropertyBlock = m_ExposedToogle.value;
                DirtyNodes(ModificationScope.Graph);
            });
            m_ExposedToogle.value = property.generatePropertyBlock;
            AddRow("Exposed", m_ExposedToogle);

            m_ReferenceNameField = new TextField(512, false, false, ' ');
            m_ReferenceNameField.AddStyleSheetPath("Styles/PropertyNameReferenceField");
            AddRow("Reference", m_ReferenceNameField);
            m_ReferenceNameField.value     = property.referenceName;
            m_ReferenceNameField.isDelayed = true;
            m_ReferenceNameField.OnValueChanged(newName =>
            {
                string newReferenceName        = m_Graph.SanitizePropertyReferenceName(newName.newValue, property.guid);
                property.overrideReferenceName = newReferenceName;
                m_ReferenceNameField.value     = property.referenceName;

                if (string.IsNullOrEmpty(property.overrideReferenceName))
                {
                    m_ReferenceNameField.RemoveFromClassList("modified");
                }
                else
                {
                    m_ReferenceNameField.AddToClassList("modified");
                }

                DirtyNodes(ModificationScope.Graph);
                UpdateReferenceNameResetMenu();
            });

            if (!string.IsNullOrEmpty(property.overrideReferenceName))
            {
                m_ReferenceNameField.AddToClassList("modified");
            }

            if (property is Vector1ShaderProperty)
            {
                VisualElement floatRow   = new VisualElement();
                VisualElement intRow     = new VisualElement();
                VisualElement modeRow    = new VisualElement();
                VisualElement minRow     = new VisualElement();
                VisualElement maxRow     = new VisualElement();
                FloatField    floatField = null;

                var floatProperty = (Vector1ShaderProperty)property;

                if (floatProperty.floatType == FloatType.Integer)
                {
                    var field = new IntegerField {
                        value = (int)floatProperty.value
                    };
                    field.OnValueChanged(intEvt =>
                    {
                        floatProperty.value = (float)intEvt.newValue;
                        DirtyNodes();
                    });
                    intRow = AddRow("Default", field);
                }
                else
                {
                    floatField = new FloatField {
                        value = floatProperty.value
                    };
                    floatField.OnValueChanged(evt =>
                    {
                        floatProperty.value = (float)evt.newValue;
                        DirtyNodes();
                    });
                    floatRow = AddRow("Default", floatField);
                }

                var floatModeField = new EnumField((Enum)floatProperty.floatType);
                floatModeField.value = floatProperty.floatType;
                floatModeField.OnValueChanged(evt =>
                {
                    if (floatProperty.floatType == (FloatType)evt.newValue)
                    {
                        return;
                    }
                    floatProperty           = (Vector1ShaderProperty)property;
                    floatProperty.floatType = (FloatType)evt.newValue;
                    switch (floatProperty.floatType)
                    {
                    case FloatType.Slider:
                        RemoveElements(new VisualElement[] { floatRow, intRow, modeRow, minRow, maxRow });
                        var field = new FloatField {
                            value = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x)
                        };
                        floatProperty.value = (float)field.value;
                        field.OnValueChanged(defaultEvt =>
                        {
                            floatProperty.value = Mathf.Max(Mathf.Min((float)defaultEvt.newValue, floatProperty.rangeValues.y), floatProperty.rangeValues.x);
                            field.value         = floatProperty.value;
                            DirtyNodes();
                        });
                        floatRow     = AddRow("Default", field);
                        field.value  = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x);
                        modeRow      = AddRow("Mode", floatModeField);
                        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);
                            field.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);
                            field.value = floatProperty.value;
                            DirtyNodes();
                        });
                        maxRow = AddRow("Max", maxField);
                        break;

                    case FloatType.Integer:
                        RemoveElements(new VisualElement[] { floatRow, intRow, modeRow, minRow, maxRow });
                        var intField = new IntegerField {
                            value = (int)floatProperty.value
                        };
                        intField.OnValueChanged(intEvt =>
                        {
                            floatProperty.value = (float)intEvt.newValue;
                            DirtyNodes();
                        });
                        intRow  = AddRow("Default", intField);
                        modeRow = AddRow("Mode", floatModeField);
                        break;

                    default:
                        RemoveElements(new VisualElement[] { floatRow, intRow, modeRow, minRow, maxRow });
                        field = new FloatField {
                            value = floatProperty.value
                        };
                        field.OnValueChanged(defaultEvt =>
                        {
                            floatProperty.value = (float)defaultEvt.newValue;
                            DirtyNodes();
                        });
                        floatRow = AddRow("Default", field);
                        modeRow  = AddRow("Mode", floatModeField);
                        break;
                    }
                    DirtyNodes();
                });
                modeRow = AddRow("Mode", floatModeField);

                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 Vector2ShaderProperty)
            {
                var vectorProperty = (Vector2ShaderProperty)property;
                var field          = new Vector2Field {
                    value = vectorProperty.value
                };
                field.OnValueChanged(evt =>
                {
                    vectorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is Vector3ShaderProperty)
            {
                var vectorProperty = (Vector3ShaderProperty)property;
                var field          = new Vector3Field {
                    value = vectorProperty.value
                };
                field.OnValueChanged(evt =>
                {
                    vectorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is Vector4ShaderProperty)
            {
                var vectorProperty = (Vector4ShaderProperty)property;
                var field          = new Vector4Field {
                    value = vectorProperty.value
                };
                field.OnValueChanged(evt =>
                {
                    vectorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is ColorShaderProperty)
            {
                var colorProperty = (ColorShaderProperty)property;
                var colorField    = new ColorField {
                    value = property.defaultValue, showEyeDropper = false, hdr = colorProperty.colorMode == ColorMode.HDR
                };
                colorField.OnValueChanged(evt =>
                {
                    colorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", colorField);
                var colorModeField = new EnumField((Enum)colorProperty.colorMode);
                colorModeField.OnValueChanged(evt =>
                {
                    if (colorProperty.colorMode == (ColorMode)evt.newValue)
                    {
                        return;
                    }
                    colorProperty.colorMode = (ColorMode)evt.newValue;
                    colorField.hdr          = colorProperty.colorMode == ColorMode.HDR;
                    colorField.MarkDirtyRepaint();
                    DirtyNodes();
                });
                AddRow("Mode", colorModeField);
            }
            else if (property is TextureShaderProperty)
            {
                var textureProperty = (TextureShaderProperty)property;
                var field           = new ObjectField {
                    value = textureProperty.value.texture, objectType = typeof(Texture)
                };
                field.OnValueChanged(evt =>
                {
                    textureProperty.value.texture = (Texture)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is Texture2DArrayShaderProperty)
            {
                var textureProperty = (Texture2DArrayShaderProperty)property;
                var field           = new ObjectField {
                    value = textureProperty.value.textureArray, objectType = typeof(Texture2DArray)
                };
                field.OnValueChanged(evt =>
                {
                    textureProperty.value.textureArray = (Texture2DArray)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is Texture3DShaderProperty)
            {
                var textureProperty = (Texture3DShaderProperty)property;
                var field           = new ObjectField {
                    value = textureProperty.value.texture, objectType = typeof(Texture3D)
                };
                field.OnValueChanged(evt =>
                {
                    textureProperty.value.texture = (Texture3D)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is CubemapShaderProperty)
            {
                var cubemapProperty = (CubemapShaderProperty)property;
                var field           = new ObjectField {
                    value = cubemapProperty.value.cubemap, objectType = typeof(Cubemap)
                };
                field.OnValueChanged(evt =>
                {
                    cubemapProperty.value.cubemap = (Cubemap)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is BooleanShaderProperty)
            {
                var    booleanProperty  = (BooleanShaderProperty)property;
                Action onBooleanChanged = () =>
                {
                    booleanProperty.value = !booleanProperty.value;
                    DirtyNodes();
                };
                var field = new Toggle(onBooleanChanged);
                field.SetValue(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");

            UpdateReferenceNameResetMenu();
        }
Esempio n. 15
0
        private void AddMainUI(VisualElement mainView)
        {
            var visualTree = EditorGUIUtility.Load("UXML/SpriteEditor/SpriteFrameModuleInspector.uxml") as VisualTreeAsset;

            m_SelectedFrameInspector = visualTree.CloneTree(null).Q("spriteFrameModuleInspector");

            m_NameElement = m_SelectedFrameInspector.Q("name");
            m_NameField   = m_SelectedFrameInspector.Q <PropertyControl <string> >("spriteName");
            m_NameField.OnValueChanged((evt) =>
            {
                if (hasSelected)
                {
                    selectedSpriteName = evt.newValue;
                }
            });

            m_PositionElement = m_SelectedFrameInspector.Q("position");
            m_PositionFieldX  = m_PositionElement.Q <PropertyControl <long> >("positionX");
            m_PositionFieldX.OnValueChanged((evt) =>
            {
                if (hasSelected)
                {
                    var rect               = selectedSpriteRect;
                    rect.x                 = evt.newValue;
                    selectedSpriteRect     = rect;
                    m_PositionFieldX.value = (long)selectedSpriteRect.x;
                }
            });

            m_PositionFieldY = m_PositionElement.Q <PropertyControl <long> >("positionY");
            m_PositionFieldY.OnValueChanged((evt) =>
            {
                if (hasSelected)
                {
                    var rect               = selectedSpriteRect;
                    rect.y                 = evt.newValue;
                    selectedSpriteRect     = rect;
                    m_PositionFieldY.value = (long)selectedSpriteRect.y;
                }
            });

            m_PositionFieldW = m_PositionElement.Q <PropertyControl <long> >("positionW");
            m_PositionFieldW.OnValueChanged((evt) =>
            {
                if (hasSelected)
                {
                    var rect               = selectedSpriteRect;
                    rect.width             = evt.newValue;
                    selectedSpriteRect     = rect;
                    m_PositionFieldW.value = (long)selectedSpriteRect.width;
                }
            });

            m_PositionFieldH = m_PositionElement.Q <PropertyControl <long> >("positionH");
            m_PositionFieldH.OnValueChanged((evt) =>
            {
                if (hasSelected)
                {
                    var rect               = selectedSpriteRect;
                    rect.height            = evt.newValue;
                    selectedSpriteRect     = rect;
                    m_PositionFieldH.value = (long)selectedSpriteRect.height;
                }
            });

            var borderElement = m_SelectedFrameInspector.Q("border");

            m_BorderFieldL = borderElement.Q <PropertyControl <long> >("borderL");
            m_BorderFieldL.OnValueChanged((evt) =>
            {
                if (hasSelected)
                {
                    var border           = selectedSpriteBorder;
                    border.x             = evt.newValue;
                    selectedSpriteBorder = border;
                    m_BorderFieldL.value = (long)selectedSpriteBorder.x;
                }
            });

            m_BorderFieldT = borderElement.Q <PropertyControl <long> >("borderT");
            m_BorderFieldT.OnValueChanged((evt) =>
            {
                if (hasSelected)
                {
                    var border           = selectedSpriteBorder;
                    border.y             = evt.newValue;
                    selectedSpriteBorder = border;
                    m_BorderFieldT.value = (long)selectedSpriteBorder.y;
                }
            });

            m_BorderFieldR = borderElement.Q <PropertyControl <long> >("borderR");
            m_BorderFieldR.OnValueChanged((evt) =>
            {
                if (hasSelected)
                {
                    var border           = selectedSpriteBorder;
                    border.z             = evt.newValue;
                    selectedSpriteBorder = border;
                    m_BorderFieldR.value = (long)selectedSpriteBorder.z;
                }
            });

            m_BorderFieldB = borderElement.Q <PropertyControl <long> >("borderB");
            m_BorderFieldB.OnValueChanged((evt) =>
            {
                if (hasSelected)
                {
                    var border           = selectedSpriteBorder;
                    border.w             = evt.newValue;
                    selectedSpriteBorder = border;
                    m_BorderFieldB.value = (long)selectedSpriteBorder.w;
                }
            });

            m_PivotField = m_SelectedFrameInspector.Q <EnumField>("pivotField");
            m_PivotField.Init(SpriteAlignment.Center);
            m_PivotField.OnValueChanged((evt) =>
            {
                if (hasSelected)
                {
                    SpriteAlignment alignment = (SpriteAlignment)evt.newValue;
                    SetSpritePivotAndAlignment(selectedSpritePivot, alignment);
                    m_CustomPivotElement.SetEnabled(selectedSpriteAlignment == SpriteAlignment.Custom);

                    Vector2 pivot             = selectedSpritePivotInCurUnitMode;
                    m_CustomPivotFieldX.value = pivot.x;
                    m_CustomPivotFieldY.value = pivot.y;
                }
            });


            m_PivotUnitModeField = m_SelectedFrameInspector.Q <EnumField>("pivotUnitModeField");
            m_PivotUnitModeField.Init(PivotUnitMode.Normalized);
            m_PivotUnitModeField.OnValueChanged((evt) =>
            {
                if (hasSelected)
                {
                    m_PivotUnitMode = (PivotUnitMode)evt.newValue;

                    Vector2 pivot             = selectedSpritePivotInCurUnitMode;
                    m_CustomPivotFieldX.value = pivot.x;
                    m_CustomPivotFieldY.value = pivot.y;
                }
            });


            m_CustomPivotElement = m_SelectedFrameInspector.Q("customPivot");
            m_CustomPivotFieldX  = m_CustomPivotElement.Q <PropertyControl <double> >("customPivotX");
            m_CustomPivotFieldX.OnValueChanged((evt) =>
            {
                if (hasSelected)
                {
                    float newValue = (float)evt.newValue;
                    float pivotX   = m_PivotUnitMode == PivotUnitMode.Pixels
                            ? ConvertFromRectToNormalizedSpace(new Vector2(newValue, 0.0f), selectedSpriteRect).x
                            : newValue;

                    var pivot = selectedSpritePivot;
                    pivot.x   = pivotX;
                    SetSpritePivotAndAlignment(pivot, selectedSpriteAlignment);
                }
            });

            m_CustomPivotFieldY = m_CustomPivotElement.Q <PropertyControl <double> >("customPivotY");
            m_CustomPivotFieldY.OnValueChanged((evt) =>
            {
                if (hasSelected)
                {
                    float newValue = (float)evt.newValue;
                    float pivotY   = m_PivotUnitMode == PivotUnitMode.Pixels
                            ? ConvertFromRectToNormalizedSpace(new Vector2(0.0f, newValue), selectedSpriteRect).y
                            : newValue;

                    var pivot = selectedSpritePivot;
                    pivot.y   = pivotY;
                    SetSpritePivotAndAlignment(pivot, selectedSpriteAlignment);
                }
            });

            //// Force an update of all the fields.
            PopulateSpriteFrameInspectorField();

            mainView.RegisterCallback <SpriteSelectionChangeEvent>(SelectionChange);

            // Stop mouse events from reaching the main view.
            m_SelectedFrameInspector.pickingMode = PickingMode.Ignore;
            m_SelectedFrameInspector.RegisterCallback <MouseDownEvent>((e) => { e.StopPropagation(); });
            m_SelectedFrameInspector.RegisterCallback <MouseUpEvent>((e) => { e.StopPropagation(); });
            m_SelectedFrameInspector.AddToClassList("moduleWindow");
            m_SelectedFrameInspector.AddToClassList("bottomRightFloating");
            mainView.Add(m_SelectedFrameInspector);
        }