public static SettingsProvider GetSettingsProvider()
        {
            // First parameter is the path in the Settings window.
            // Second parameter is the scope of this setting: it only appears in the Settings window for the Project scope.
            var provider = new SettingsProvider("Preferences/Monospaced Console", SettingsScope.User)
            {
                label = "Monospaced Console",
                // activateHandler is called when the user clicks on the Settings item in the Settings window.
                activateHandler = (searchContext, rootElement) =>
                {
                    State state = (State)EditorPrefs.GetInt(StateKey, (int)DefaultState);
                    Font  font  = (Font)EditorPrefs.GetInt(FontKey, 0);

                    var title = new Label
                    {
                        text  = "Monospaced Console",
                        style =
                        {
                            fontSize                =             19,
                            unityFontStyleAndWeight = FontStyle.Bold,
                            marginLeft =              8,
                            marginTop  = 2
                        }
                    };
                    rootElement.Add(title);

                    var properties = new VisualElement
                    {
                        style =
                        {
                            flexDirection = FlexDirection.Column,
                            marginLeft    =                   10,
                            marginTop     = 10
                        }
                    };
                    rootElement.Add(properties);

                    var stateDropdown = new EnumField(state)
                    {
                        label = "Monospaced"
                    };
                    stateDropdown.RegisterValueChangedCallback(evt =>
                    {
                        EditorPrefs.SetInt(StateKey, (int)(State)evt.newValue);
                        MonospacedConsole.Replacement(true);
                    });
                    properties.Add(stateDropdown);

                    var fontDropdown = new EnumField(font)
                    {
                        label = "Font"
                    };
                    fontDropdown.RegisterValueChangedCallback(evt =>
                    {
                        EditorPrefs.SetInt(FontKey, (int)(Font)evt.newValue);
                        MonospacedConsole.Replacement(true);
                    });
                    properties.Add(fontDropdown);
                },

                // Populate the search keywords to enable smart search filtering and label highlighting:
                keywords = new HashSet <string>(new[] { "Console", "Monospaced" })
            };

            return(provider);
        }
    void SelectSkill(Skill selectedSkill)
    {
        _spellContainer.style.display         = DisplayStyle.None;
        _backToCollectionButton.style.display = DisplayStyle.None;
        _removeSkillButton.style.display      = DisplayStyle.Flex;

        _itemInfo = _root.Q("ItemInfo");
        _itemInfo.Clear();

        var iconPreview = new Image();

        iconPreview.style.width  = 100;
        iconPreview.style.height = 100;
        // iconPreview.style.marginLeft = 10;
        iconPreview.image = selectedSkill.icon.texture;

        var icon = new ObjectField();

        icon.value      = selectedSkill.icon;
        icon.objectType = typeof(Sprite);
        icon.RegisterValueChangedCallback(changeEvent =>
        {
            iconPreview.image  = ((Sprite)changeEvent.newValue).texture;
            selectedSkill.icon = (Sprite)changeEvent.newValue;
            EditorUtility.SetDirty(selectedSkill);
        });

        _currentSelectedSkill = selectedSkill;
        SerializedSkill       = new SerializedObject(_currentSelectedSkill);
        SkillList             = SerializedSkill.FindProperty("SkillEffects");
        _possiblePositions    = _currentSelectedSkill.possiblePositions;
        _possibleTargets      = _currentSelectedSkill.possibleTargets;

        var costField = new IntegerField("Cooldown");

        costField.labelElement.style.minWidth = 60;
        costField.value = selectedSkill.cooldown;
        costField.RegisterValueChangedCallback(changeEvent =>
        {
            selectedSkill.cooldown = changeEvent.newValue;
            EditorUtility.SetDirty(selectedSkill);
        });

        var manaCostField = new IntegerField("Mana Cost");

        manaCostField.labelElement.style.minWidth = 60;
        manaCostField.value = selectedSkill.manaCost;
        manaCostField.RegisterValueChangedCallback(changeEvent =>
        {
            selectedSkill.manaCost = changeEvent.newValue;
            EditorUtility.SetDirty(selectedSkill);
        });

        var nameTextField = new TextField("Name");

        nameTextField.value = selectedSkill.displayName;
        nameTextField.labelElement.style.minWidth = 60;
        nameTextField.RegisterValueChangedCallback(changeEvent =>
        {
            selectedSkill.displayName = changeEvent.newValue;
            EditorUtility.SetDirty(selectedSkill);
        });

        var nameChangeButton = new Button(() =>
        {
            AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(selectedSkill), selectedSkill.displayName);
            EditorUtility.SetDirty(selectedSkill);
        });

        nameChangeButton.text           = "Change GO Name";
        nameChangeButton.style.minWidth = 60;

        var descriptionField = new TextField("Description");

        descriptionField.value        = selectedSkill.description;
        descriptionField.multiline    = true;
        descriptionField.style.height = 80;
        descriptionField.name         = "messageText";
        descriptionField.RegisterValueChangedCallback(changeEvent => { selectedSkill.description = changeEvent.newValue; });

        var passiveField = new Toggle("Passive Skill");

        passiveField.value = selectedSkill.isPassive;
        passiveField.RegisterValueChangedCallback(changeEvent => { selectedSkill.isPassive = changeEvent.newValue; });

        var targetTypeField = new EnumField("Target Type");

        targetTypeField.Init(selectedSkill.targetType);
        targetTypeField.RegisterValueChangedCallback(changeEvent => { selectedSkill.targetType = (TargetType)changeEvent.newValue; });

        var targetField = new EnumField("Target Site");

        targetField.Init(selectedSkill.targetSite);
        targetField.RegisterValueChangedCallback(changeEvent => { selectedSkill.targetSite = (TargetSite)changeEvent.newValue; });

        var amountField = new EnumField("Target Amount");

        amountField.Init(selectedSkill.targetCount);
        amountField.RegisterValueChangedCallback(changeEvent => { selectedSkill.targetCount = (TargetAmount)changeEvent.newValue; });

        var infoContainer  = new VisualElement();
        var upperContainer = new VisualElement();
        var leftContainer  = new VisualElement();

        leftContainer.style.width      = 200;
        leftContainer.style.alignItems = Align.Center;
        leftContainer.Add(iconPreview);
        leftContainer.Add(icon);
        var rightContainer = new VisualElement();

        rightContainer.style.width = 200;
        rightContainer.Add(nameTextField);
        rightContainer.Add(nameChangeButton);
        rightContainer.Add(manaCostField);
        rightContainer.Add(costField);
        rightContainer.Add(descriptionField);

        upperContainer.Add(leftContainer);
        upperContainer.Add(rightContainer);
        upperContainer.style.flexDirection = FlexDirection.Row;

        var bottomContainer = new VisualElement();

        bottomContainer.style.marginLeft = 50;
        bottomContainer.style.marginTop  = 25;
        bottomContainer.style.width      = 300;
        bottomContainer.Add(passiveField);
        bottomContainer.Add(targetTypeField);
        bottomContainer.Add(targetField);
        bottomContainer.Add(amountField);

        infoContainer.Add(upperContainer);
        infoContainer.Add(bottomContainer);

        _itemInfo.Add(infoContainer);

        var positionBlock = new IMGUIContainer(() =>
        {
            GeneratePositionEditor();
        });

        var effectScroller = new ScrollView();

        effectScroller.style.minWidth  = 350;
        effectScroller.style.maxHeight = 350;

        var effectBlock = new IMGUIContainer(() =>
        {
            GenerateEffectEditor();
        });

        effectScroller.Add(effectBlock);

        _itemInfo.Add(positionBlock);
        _itemInfo.Add(effectScroller);

        _backToSkillsButton.style.display = DisplayStyle.Flex;
        _itemInfo.style.display           = DisplayStyle.Flex;
    }
Beispiel #3
0
        protected override void UpdateInputPortModels()
        {
            Port.CreateInputPort(m_Store, Model.InstancePort, inputContainer, inputContainer);
            Port.CreateInputPort(m_Store, Model.EntityPort, titleContainer, inputContainer);
            //TODO deal with presence of same component type in both lists

            foreach (var componentOperation in Model.GetEditableComponents())
            {
                TypeHandle compType           = componentOperation.Type;
                var        componentContainer = new VisualElement {
                    name = "instantiateComponentNode"
                };
                var componentTitleContainer = new VisualElement {
                    name = "componentDataTitle"
                };
                componentContainer.Add(new VisualElement {
                    name = "componentSeparatorLine"
                });
                componentContainer.Add(componentTitleContainer);

                var deleteComponentButton = new Button {
                    name = "deleteComponentIcon"
                };
                deleteComponentButton.clickable.clicked += () => { DeleteComponentOperation(compType); };
                componentTitleContainer.Insert(0, deleteComponentButton);

                deleteComponentButton.EnableInClassList("deletable", !componentOperation.FromArchetype);
                componentTitleContainer.Add(deleteComponentButton);

                componentTitleContainer.Add(new Label(compType.Name(Model.GraphModel.Stencil))
                {
                    name = "componentTitle"
                });

                componentTitleContainer.Add(new VisualElement {
                    name = "filler"
                });

                var operationType = new EnumField(componentOperation.OperationType)
                {
                    name = "componentOperationType"
                };

                //Do I need to unregister it afterwards?
                //Also, allocation a closure for each component operations... meh?
                operationType.RegisterValueChangedCallback(eventValue => SetComponentOperation(compType, (ComponentOperation.ComponentOperationType)eventValue.newValue));
                componentTitleContainer.Add(operationType);
                inputContainer.Add(componentContainer);

                if (componentOperation.OperationType != ComponentOperation.ComponentOperationType.RemoveComponent)
                {
                    var componentPortsContainer = new VisualElement {
                        name = "componentDataPorts"
                    };
                    componentContainer.Add(componentPortsContainer);
                    foreach (var port in Model.GetPortsForComponent(componentOperation.Type))
                    {
                        Port.CreateInputPort(m_Store, port, componentPortsContainer, componentPortsContainer);
                    }
                }
            }
        }
Beispiel #4
0
        void BuildVector1PropertyField(Vector1ShaderProperty property)
        {
            switch (property.floatType)
            {
            case FloatType.Slider:
            {
                float min = Mathf.Min(property.value, property.rangeValues.x);
                float max = Mathf.Max(property.value, property.rangeValues.y);
                property.rangeValues = new Vector2(min, max);

                var defaultField = new FloatField {
                    value = property.value
                };
                var minField = new FloatField {
                    value = property.rangeValues.x
                };
                var maxField = new FloatField {
                    value = property.rangeValues.y
                };

                defaultField.RegisterValueChangedCallback(evt =>
                    {
                        property.value = (float)evt.newValue;
                        this.MarkDirtyRepaint();
                    });
                defaultField.Q("unity-text-input").RegisterCallback <FocusOutEvent>(evt =>
                    {
                        graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                        float minValue       = Mathf.Min(property.value, property.rangeValues.x);
                        float maxValue       = Mathf.Max(property.value, property.rangeValues.y);
                        property.rangeValues = new Vector2(minValue, maxValue);
                        minField.value       = minValue;
                        maxField.value       = maxValue;
                        DirtyNodes();
                    });
                minField.RegisterValueChangedCallback(evt =>
                    {
                        graph.owner.RegisterCompleteObjectUndo("Change Range Property Minimum");
                        property.rangeValues = new Vector2((float)evt.newValue, property.rangeValues.y);
                        DirtyNodes();
                    });
                minField.Q("unity-text-input").RegisterCallback <FocusOutEvent>(evt =>
                    {
                        property.value     = Mathf.Max(Mathf.Min(property.value, property.rangeValues.y), property.rangeValues.x);
                        defaultField.value = property.value;
                        DirtyNodes();
                    });
                maxField.RegisterValueChangedCallback(evt =>
                    {
                        graph.owner.RegisterCompleteObjectUndo("Change Range Property Maximum");
                        property.rangeValues = new Vector2(property.rangeValues.x, (float)evt.newValue);
                        DirtyNodes();
                    });
                maxField.Q("unity-text-input").RegisterCallback <FocusOutEvent>(evt =>
                    {
                        property.value     = Mathf.Max(Mathf.Min(property.value, property.rangeValues.y), property.rangeValues.x);
                        defaultField.value = property.value;
                        DirtyNodes();
                    });

                AddRow("Default", defaultField);
                AddRow("Min", minField);
                AddRow("Max", maxField);
            }
            break;

            case FloatType.Integer:
            {
                property.value = (int)property.value;
                var defaultField = new IntegerField {
                    value = (int)property.value
                };
                defaultField.RegisterValueChangedCallback(evt =>
                    {
                        graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                        property.value = (int)evt.newValue;
                        DirtyNodes();
                    });
                AddRow("Default", defaultField);
            }
            break;

            default:
            {
                var defaultField = new FloatField {
                    value = property.value
                };
                defaultField.RegisterValueChangedCallback(evt =>
                    {
                        graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                        property.value = (float)evt.newValue;
                        DirtyNodes();
                    });
                AddRow("Default", defaultField);
            }
            break;
            }

            if (!graph.isSubGraph)
            {
                var modeField = new EnumField(property.floatType);
                modeField.RegisterValueChangedCallback(evt =>
                {
                    graph.owner.RegisterCompleteObjectUndo("Change Vector1 Mode");
                    property.floatType = (FloatType)evt.newValue;
                    Rebuild();
                });
                AddRow("Mode", modeField);
            }
        }
Beispiel #5
0
        void InitializeView()
        {
            // Register callbacks
            settingsButton.clicked += () => {
                if (settingsButton.ClassListContains("ActiveButton"))
                {
                    settingsButton.RemoveFromClassList("ActiveButton");
                    portSettings.style.display  = DisplayStyle.None;
                    portNameField.style.display = DisplayStyle.None;
                }
                else
                {
                    settingsButton.AddToClassList("ActiveButton");
                    portSettings.style.display  = DisplayStyle.Flex;
                    portNameField.style.display = DisplayStyle.Flex;
                }
            };

            portNameField.RegisterValueChangedCallback(name => {
                graphView.RegisterCompleteObjectUndo("Change output name");
                var uniqueName      = ObjectNames.GetUniqueName(node.outputTextureSettings.Select(o => o.name).ToArray(), name.newValue);
                targetSettings.name = uniqueName;
                portName.text       = uniqueName;
            });
            portNameField.value = targetSettings.name;
            portName.text       = targetSettings.name;

            enableCompression.RegisterValueChangedCallback(enabled => {
                graphView.RegisterCompleteObjectUndo($"Change {targetSettings.name} compression");
                var textureDim = node.rtSettings.GetTextureDimension(graphView.graph);

                if (textureDim == TextureDimension.Tex2D)
                {
                    targetSettings.enableCompression = enabled.newValue;
                    if (enabled.newValue)
                    {
                        compressionFields.style.display = DisplayStyle.Flex;
                    }
                    else
                    {
                        compressionFields.style.display = DisplayStyle.None;
                    }
                }
                else
                {
                    Debug.LogError("Compression is not yet supported for " + textureDim);
                    enableCompression.SetValueWithoutNotify(false);
                }
            });
            enableCompression.value = targetSettings.enableCompression;

            compressionFormat.RegisterValueChangedCallback(format => {
                targetSettings.compressionFormat = (TextureFormat)format.newValue;
            });
            compressionQuality.RegisterValueChangedCallback(quality => {
                targetSettings.compressionQuality = (MixtureCompressionQuality)quality.newValue;
            });

            compressionFormat.SetValueWithoutNotify(targetSettings.compressionFormat);
            compressionQuality.SetValueWithoutNotify(targetSettings.compressionQuality);

            createMipMapShaderButton.clicked += MixtureAssetCallbacks.CreateCustomMipMapShaderGraph;
            // TODO: assign the created shader when finished

            mipmapShaderField.objectType           = typeof(Shader);
            mipmapShaderField.value                = targetSettings.customMipMapShader;
            createMipMapShaderButton.style.display = targetSettings.customMipMapShader != null ? DisplayStyle.None : DisplayStyle.Flex;
            mipmapShaderField.RegisterValueChangedCallback(e => {
                graphView.RegisterCompleteObjectUndo("Changed Custom Mip Map Shader");
                targetSettings.customMipMapShader      = e.newValue as Shader;
                createMipMapShaderButton.style.display = e.newValue != null ? DisplayStyle.None : DisplayStyle.Flex;;
            });

            enableMipMap.RegisterValueChangedCallback(e => {
                targetSettings.hasMipMaps = e.newValue;
                if (supportCustomMipMaps)
                {
                    mipmapFields.style.display = targetSettings.hasMipMaps ? DisplayStyle.Flex : DisplayStyle.None;
                }
            });
            enableMipMap.value = targetSettings.hasMipMaps;

            removeOutputButton.clicked += () => {
                node.RemoveTextureOutput(targetSettings);
                nodeView.ForceUpdatePorts();
            };

            enableConversion.RegisterValueChangedCallback(e => {
                graphView.RegisterCompleteObjectUndo("Changed Conversion value");
                targetSettings.enableConversion = e.newValue;
                conversionFormat.style.display  = e.newValue ? DisplayStyle.Flex : DisplayStyle.None;
            });
            enableConversion.value = targetSettings.enableConversion;

            conversionFormat.RegisterValueChangedCallback(e => {
                graphView.RegisterCompleteObjectUndo("Changed Conversion Format");
                targetSettings.conversionFormat = (ConversionFormat)e.newValue;
            });
            conversionFormat.value = targetSettings.conversionFormat;

            sRGB.RegisterValueChangedCallback(e => {
                graphView.RegisterCompleteObjectUndo("Changed sRGB");
                targetSettings.sRGB = e.newValue;

                // when updating sRGB flag, we need to process the graph to update the final copy material
                graphView.ProcessGraph();
            });
            sRGB.value = targetSettings.sRGB;

            // Initial view state
            portSettings.style.display      = DisplayStyle.None;
            compressionFields.style.display = targetSettings.enableCompression ? DisplayStyle.Flex : DisplayStyle.None;
            mipmapFields.style.display      = targetSettings.hasMipMaps ? DisplayStyle.Flex : DisplayStyle.None;
            portNameField.style.display     = DisplayStyle.None;
            conversionFormat.style.display  = targetSettings.enableConversion ? DisplayStyle.Flex : DisplayStyle.None;
        }
Beispiel #6
0
        public TransitionConditionUI()
        {
            AddToClassList("transition-condition");

            style.flexDirection = FlexDirection.Row;

            _parameterStateSwitch = new Button(() =>
            {
                if (_condition.ProviderSourceType == ValueProviderSourceType.Parameter)
                {
                    _condition.ProviderSourceType = ValueProviderSourceType.State;
                }
                else
                {
                    _condition.ProviderSourceType = ValueProviderSourceType.Parameter;
                }

                SetProviderSourceType(_condition.ProviderSourceType);
            })
            {
                text = "P"
            };
            Add(_parameterStateSwitch);

            _parameterFinder = new NamedItemFinder <ParameterNodeUI>(StateMachineEditor.Editor.Parameters);
            _parameterFinder.OnItemSelected += (previousParameter, parameter, index) =>
            {
                _condition.Parameter = parameter;

                if (previousParameter != null)
                {
                    previousParameter.OnTypeChanged -= ParameterTypeChanged;
                }

                if (parameter != null)
                {
                    SetProviderType(parameter.ParameterType);
                    parameter.OnTypeChanged += ParameterTypeChanged;
                }
                else
                {
                    ComparisonElementsEnabling(_providerType, false);
                }
            };
            Add(_parameterFinder);

            _stateFinder = new NamedItemFinder <StateNodeUI>(StateMachineEditor.Editor.States);
            _stateFinder.OnItemSelected += (previousState, state, index) =>
            {
                _condition.State = state;

                if (state != null)
                {
                    _stateValueProvider.style.display = DisplayStyle.Flex;
                    SetProviderType(ValueProviderType.Float);
                }
                else
                {
                    _stateValueProvider.style.display = DisplayStyle.None;
                    ComparisonElementsEnabling(_providerType, false);
                }
            };
            _stateFinder.style.display = DisplayStyle.None;
            Add(_stateFinder);

            _stateValueProvider = new EnumField(StateValueProviders.Time);
            _stateValueProvider.style.display = DisplayStyle.None;
            _stateValueProvider.RegisterValueChangedCallback(e => _condition.StateValueProvider = (StateValueProviders)e.newValue);
            Add(_stateValueProvider);

            _boolComparisonValueField = new EnumField(Bool.True);
            _boolComparisonValueField.style.display = DisplayStyle.None;
            _boolComparisonValueField.RegisterValueChangedCallback(e => _condition.BoolComparisonValue = (Bool)e.newValue == Bool.True);
            Add(_boolComparisonValueField);

            _intComparisonField = new EnumField(IntComparison.Equal);
            _intComparisonField.style.display = DisplayStyle.None;
            _intComparisonField.RegisterValueChangedCallback(e => _condition.IntComparison = (IntComparison)e.newValue);
            Add(_intComparisonField);

            _intComparisonValueField = new IntegerField();
            _intComparisonValueField.style.display = DisplayStyle.None;
            _intComparisonValueField.RegisterValueChangedCallback(e => _condition.IntComparisonValue = e.newValue);
            Add(_intComparisonValueField);

            _floatComparisonField = new EnumField(FloatComparison.BiggerOrEqual);
            _floatComparisonField.style.display = DisplayStyle.None;
            _floatComparisonField.RegisterValueChangedCallback(e => _condition.FloatComparison = (FloatComparison)e.newValue);
            Add(_floatComparisonField);

            _floatComparisonValueField = new FloatField();
            _floatComparisonValueField.style.display = DisplayStyle.None;
            _floatComparisonValueField.RegisterValueChangedCallback(e => _condition.FloatComparisonValue = e.newValue);
            Add(_floatComparisonValueField);

            RegisterCallback <DetachFromPanelEvent>(e =>
            {
                if (_parameterFinder.Item != null)
                {
                    _parameterFinder.Item.OnTypeChanged -= ParameterTypeChanged;
                }
            });
        }
Beispiel #7
0
        void InitializeView()
        {
            // Register callbacks
            settingsButton.clicked += () => {
                if (settingsButton.ClassListContains("ActiveButton"))
                {
                    settingsButton.RemoveFromClassList("ActiveButton");
                    portSettings.style.display  = DisplayStyle.None;
                    portNameField.style.display = DisplayStyle.None;
                }
                else
                {
                    settingsButton.AddToClassList("ActiveButton");
                    portSettings.style.display  = DisplayStyle.Flex;
                    portNameField.style.display = DisplayStyle.Flex;
                }
            };

            portNameField.RegisterValueChangedCallback(name => {
                graphView.RegisterCompleteObjectUndo("Change output name");
                var uniqueName      = ObjectNames.GetUniqueName(node.outputTextureSettings.Select(o => o.name).ToArray(), name.newValue);
                targetSettings.name = uniqueName;
                portName.text       = uniqueName;

#if UNITY_EDITOR
                if (graphView.graph.type == MixtureGraphType.Realtime)
                {
                    graphView.graph.UpdateRealtimeAssetsOnDisk();
                }
#endif
            });
            portNameField.value = targetSettings.name;
            portName.text       = targetSettings.name;

            enableCompression.RegisterValueChangedCallback(enabled => {
                graphView.RegisterCompleteObjectUndo($"Change {targetSettings.name} compression");
                var textureDim = node.settings.GetResolvedTextureDimension(graphView.graph);

                if (textureDim == TextureDimension.Tex2D || textureDim == TextureDimension.Cube)
                {
                    targetSettings.enableCompression = enabled.newValue;
                    if (enabled.newValue)
                    {
                        compressionFields.style.display = DisplayStyle.Flex;
                    }
                    else
                    {
                        compressionFields.style.display = DisplayStyle.None;
                    }
                }
                else
                {
                    Debug.LogError("Compression is not yet supported for " + textureDim);
                    enableCompression.SetValueWithoutNotify(false);
                }
            });
            enableCompression.value = targetSettings.enableCompression;

            compressionFormat.RegisterValueChangedCallback(format => {
                targetSettings.compressionFormat = (TextureFormat)format.newValue;
            });
            compressionQuality.RegisterValueChangedCallback(quality => {
                targetSettings.compressionQuality = (MixtureCompressionQuality)quality.newValue;
            });

            compressionFormat.SetValueWithoutNotify(targetSettings.compressionFormat);
            compressionQuality.SetValueWithoutNotify(targetSettings.compressionQuality);

            enableMipMap.RegisterValueChangedCallback(e => {
                targetSettings.hasMipMaps = e.newValue;

                // Processing the graph to update the previews with the new mipmaps
                graphView.ProcessGraph();
            });
            enableMipMap.value = targetSettings.hasMipMaps;

            removeOutputButton.clicked += () => {
                node.RemoveTextureOutput(targetSettings);
                nodeView.ForceUpdatePorts();
            };

            enableConversion.RegisterValueChangedCallback(e => {
                graphView.RegisterCompleteObjectUndo("Changed Conversion value");
                targetSettings.enableConversion = e.newValue;
                conversionFormat.style.display  = e.newValue ? DisplayStyle.Flex : DisplayStyle.None;
            });
            enableConversion.value = targetSettings.enableConversion;

            conversionFormat.RegisterValueChangedCallback(e => {
                graphView.RegisterCompleteObjectUndo("Changed Conversion Format");
                targetSettings.conversionFormat = (ConversionFormat)e.newValue;
            });
            conversionFormat.value = targetSettings.conversionFormat;

            sRGB.RegisterValueChangedCallback(e => {
                graphView.RegisterCompleteObjectUndo("Changed sRGB");
                targetSettings.sRGB = e.newValue;

                // when updating sRGB flag, we need to process the graph to update the final copy material
                graphView.ProcessGraph();
            });
            sRGB.value = targetSettings.sRGB;

            // Initial view state
            portSettings.style.display      = DisplayStyle.None;
            compressionFields.style.display = targetSettings.enableCompression ? DisplayStyle.Flex : DisplayStyle.None;
            portNameField.style.display     = DisplayStyle.None;
            conversionFormat.style.display  = targetSettings.enableConversion ? DisplayStyle.Flex : DisplayStyle.None;
        }
Beispiel #8
0
        public override void Enable(bool fromInspector)
        {
            base.Enable(fromInspector);
            curveNode = nodeTarget as CurveNode;

            controlsContainer.styleSheets.Add(Resources.Load <StyleSheet>("MixtureCurveColors"));

            var modeField = new EnumField("Mode", curveNode.mode);

            controlsContainer.Add(modeField as VisualElement);

            var rCurve = CreateCurveField(() => curveNode.redCurve, c => curveNode.redCurve = c);
            var gCurve = CreateCurveField(() => curveNode.greenCurve, c => curveNode.greenCurve = c);
            var bCurve = CreateCurveField(() => curveNode.blueCurve, c => curveNode.blueCurve = c);
            var aCurve = CreateCurveField(() => curveNode.alphaCurve, c => curveNode.alphaCurve = c);

            rCurve.AddToClassList("red");
            gCurve.AddToClassList("green");
            bCurve.AddToClassList("blue");
            aCurve.AddToClassList("white");

            controlsContainer.Add(rCurve);
            controlsContainer.Add(gCurve);
            controlsContainer.Add(bCurve);
            controlsContainer.Add(aCurve);

            if (fromInspector)
            {
                controlsContainer.Add(AddControlField(nameof(CurveNode.evaluationRange), "Evaluation Range", false, () => {
                    curveNode.UpdateTexture();
                    NotifyNodeChanged();
                }));
            }

            modeField.RegisterValueChangedCallback(e => {
                curveNode.mode = (CurveNode.CurveOutputMode)e.newValue;
                owner.RegisterCompleteObjectUndo("Change Curve Mode");
                UpdateVisibleCurves();
                curveNode.UpdateTexture();
                NotifyNodeChanged();
            });
            UpdateVisibleCurves();

            var p = new CustomStyleProperty <Color>("--unity-curve-color");

            void UpdateVisibleCurves()
            {
                rCurve.style.display = DisplayStyle.None;
                gCurve.style.display = DisplayStyle.None;
                bCurve.style.display = DisplayStyle.None;
                aCurve.style.display = DisplayStyle.None;

                switch (curveNode.mode)
                {
                case CurveNode.CurveOutputMode.RRRR:
                case CurveNode.CurveOutputMode.R:
                    rCurve.style.display = DisplayStyle.Flex;
                    break;

                case CurveNode.CurveOutputMode.RG:
                    rCurve.style.display = DisplayStyle.Flex;
                    gCurve.style.display = DisplayStyle.Flex;
                    break;

                case CurveNode.CurveOutputMode.RGB:
                    rCurve.style.display = DisplayStyle.Flex;
                    gCurve.style.display = DisplayStyle.Flex;
                    bCurve.style.display = DisplayStyle.Flex;
                    break;

                case CurveNode.CurveOutputMode.RGBA:
                    rCurve.style.display = DisplayStyle.Flex;
                    gCurve.style.display = DisplayStyle.Flex;
                    bCurve.style.display = DisplayStyle.Flex;
                    aCurve.style.display = DisplayStyle.Flex;
                    break;
                }
            }
        }
        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.UIElements.PopupWindow>();

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

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

            m_AmountSlider.RegisterValueChangedCallback((evt) =>
            {
                if (!evt.Equals(m_AmountField.value))
                {
                    m_AmountField.value = (float)Math.Round((double)evt.newValue, 2);
                }
                if (m_SliderActive)
                {
                    sliderChanged?.Invoke(m_AmountField.value);
                }
            });
            m_AmountSlider.RegisterCallback <MouseCaptureEvent>(evt =>
            {
                m_SliderActive = true;
                sliderStarted?.Invoke();
            }, TrickleDown.TrickleDown);

            m_AmountSlider.RegisterCallback <MouseCaptureOutEvent>(evt =>
            {
                m_SliderActive = false;
                sliderEnded?.Invoke();
                m_AmountSlider.value = 0;
            }, TrickleDown.TrickleDown);

            m_AmountField.RegisterValueChangedCallback((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();
        }
        private void Draw(CustomFunctionNode node)
        {
            var currentControls = this.Children().ToArray();

            for (int i = 0; i < currentControls.Length; i++)
            {
                currentControls[i].RemoveFromHierarchy();
            }

            m_Type = new EnumField(node.sourceType);
            m_Type.RegisterValueChangedCallback(s =>
            {
                if ((HlslSourceType)s.newValue != node.sourceType)
                {
                    node.owner.owner.RegisterCompleteObjectUndo("Change Function Type");
                    node.sourceType = (HlslSourceType)s.newValue;
                    Draw(node);
                    node.Dirty(ModificationScope.Graph);
                }
            });

            m_FunctionName = new TextField {
                value = node.functionName, multiline = false
            };
            m_FunctionName.RegisterCallback <FocusInEvent>(s =>
            {
                if (m_FunctionName.value == CustomFunctionNode.defaultFunctionName)
                {
                    m_FunctionName.value = "";
                }
            });
            m_FunctionName.RegisterCallback <FocusOutEvent>(s =>
            {
                if (m_FunctionName.value == "")
                {
                    m_FunctionName.value = CustomFunctionNode.defaultFunctionName;
                }

                if (m_FunctionName.value != node.functionName)
                {
                    node.owner.owner.RegisterCompleteObjectUndo("Change Function Name");
                    node.functionName = m_FunctionName.value;
                    node.Dirty(ModificationScope.Graph);
                }
            });

            m_FunctionSource = new TextField {
                value = node.functionSource, multiline = false
            };
            m_FunctionSource.RegisterCallback <FocusInEvent>(s =>
            {
                if (m_FunctionSource.value == CustomFunctionNode.defaultFunctionSource)
                {
                    m_FunctionSource.value = "";
                }
            });
            m_FunctionSource.RegisterCallback <FocusOutEvent>(s =>
            {
                if (m_FunctionSource.value == "")
                {
                    m_FunctionSource.value = CustomFunctionNode.defaultFunctionSource;
                }

                if (m_FunctionSource.value != node.functionSource)
                {
                    node.owner.owner.RegisterCompleteObjectUndo("Change Function Source");
                    node.functionSource = m_FunctionSource.value;
                    node.Dirty(ModificationScope.Graph);
                }
            });

            m_FunctionBody = new TextField {
                value = node.functionBody, multiline = true
            };
            m_FunctionBody.RegisterCallback <FocusInEvent>(s =>
            {
                if (m_FunctionBody.value == CustomFunctionNode.defaultFunctionBody)
                {
                    m_FunctionBody.value = "";
                }
            });
            m_FunctionBody.RegisterCallback <FocusOutEvent>(s =>
            {
                if (m_FunctionBody.value == "")
                {
                    m_FunctionBody.value = CustomFunctionNode.defaultFunctionBody;
                }

                if (m_FunctionBody.value != node.functionBody)
                {
                    node.owner.owner.RegisterCompleteObjectUndo("Change Function Body");
                    node.functionBody = m_FunctionBody.value;
                    node.Dirty(ModificationScope.Graph);
                }
            });

            VisualElement typeRow = new VisualElement()
            {
                name = "Row"
            };

            {
                typeRow.Add(new Label("Type"));
                typeRow.Add(m_Type);
            }
            Add(typeRow);
            VisualElement nameRow = new VisualElement()
            {
                name = "Row"
            };

            {
                nameRow.Add(new Label("Name"));
                nameRow.Add(m_FunctionName);
            }
            Add(nameRow);
            switch (node.sourceType)
            {
            case HlslSourceType.File:
                VisualElement sourceRow = new VisualElement()
                {
                    name = "Row"
                };
                {
                    sourceRow.Add(new Label("Source"));
                    sourceRow.Add(m_FunctionSource);
                }
                Add(sourceRow);
                break;

            case HlslSourceType.String:
                VisualElement bodyRow = new VisualElement()
                {
                    name = "Row"
                };
                {
                    bodyRow.Add(new Label("Body"));
                    bodyRow.style.height = 200;
                    bodyRow.Add(m_FunctionBody);
                }
                Add(bodyRow);
                break;
            }
        }
Beispiel #11
0
        void ReloadSettingsView()
        {
            // Remove all old fields
            Clear();

            if (title != null)
            {
                var titleLabel = new Label(title);
                titleLabel.AddToClassList("PropertyEditorTitle");
                this.Add(titleLabel);
            }

            var dimension = settings.GetResolvedTextureDimension(graph);

            // Wrap and Filter Modes
            smpHeader = new Label("Sampler States");
            smpHeader.AddToClassList(headerStyleClass);
            this.Add(smpHeader);

            wrapMode       = showSettingsForNode ? new EnumField(settings.wrapMode) : new EnumField((GraphOutputWrapMode)settings.wrapMode);
            wrapMode.label = "Wrap Mode";
            wrapMode.RegisterValueChangedCallback(e =>
            {
                owner.RegisterCompleteObjectUndo("Updated Wrap Mode " + e.newValue);
                settings.wrapMode = (OutputWrapMode)e.newValue;
                onChanged?.Invoke();
            });

            filterMode       = showSettingsForNode ? new EnumField(settings.filterMode) : new EnumField((GraphOutputFilterMode)settings.filterMode);
            filterMode.label = "Filter Mode";
            filterMode.RegisterValueChangedCallback(e =>
            {
                owner.RegisterCompleteObjectUndo("Updated Filter Mode " + e.newValue);
                settings.filterMode = (OutputFilterMode)e.newValue;
                onChanged?.Invoke();
            });

            this.Add(wrapMode);
            this.Add(filterMode);

            // Size Modes
            sizeHeader = new Label("Size Properties");
            sizeHeader.AddToClassList(headerStyleClass);
            this.Add(sizeHeader);

            outputSizeMode       = showSettingsForNode ? new EnumField(settings.sizeMode) : new EnumField((GraphOutputSizeMode)settings.sizeMode);
            outputSizeMode.label = "Size Mode";
            outputSizeMode.RegisterValueChangedCallback((EventCallback <ChangeEvent <Enum> >)(e => {
                owner.RegisterCompleteObjectUndo("Updated Size mode " + e.newValue);
                settings.sizeMode = (OutputSizeMode)e.newValue;
                onChanged?.Invoke();
                ReloadSettingsView();
                UpdateFieldVisibility(settings);
            }));
            this.Add(outputSizeMode);

            potSize = new EnumField(settings.potSize)
            {
                value = settings.potSize,
                label = "Resolution",
            };
            potSize.RegisterValueChangedCallback(e =>
            {
                owner.RegisterCompleteObjectUndo("Updated Size " + e.newValue);
                var size         = (POTSize)e.newValue;
                settings.potSize = size;

                if (size != POTSize.Custom)
                {
                    settings.width  = (int)size;
                    settings.height = (int)size;
                    settings.depth  = (int)size;
                }
                else
                {
                    settings.width  = outputWidth.value;
                    settings.height = outputHeight.value;
                    if (outputDepth != null)
                    {
                        settings.depth = outputDepth.value;
                    }
                }

                onChanged?.Invoke();
                ReloadSettingsView();
                UpdateFieldVisibility(settings);
            });

            this.Add(potSize);

            outputWidth = new IntegerField()
            {
                value     = settings.width,
                label     = "Width",
                isDelayed = true,
            };
            outputWidth.RegisterValueChangedCallback(e =>
            {
                owner.RegisterCompleteObjectUndo("Updated Width " + e.newValue);
                settings.width = e.newValue;
                onChanged?.Invoke();
            });
            this.Add(outputWidth);

            outputWidthScale = CreateSizeScaleSlider(settings.widthScale, (v) => settings.widthScale = v, "Width Scale");
            this.Add(outputWidthScale);

            if (dimension != TextureDimension.Cube)
            {
                outputHeight = new IntegerField()
                {
                    value     = settings.height,
                    label     = "Height",
                    isDelayed = true,
                };
                outputHeight.RegisterValueChangedCallback(e =>
                {
                    owner.RegisterCompleteObjectUndo("Updated Height " + e.newValue);
                    settings.height = e.newValue;
                    onChanged?.Invoke();
                });
                this.Add(outputHeight);

                outputHeightScale = CreateSizeScaleSlider(settings.heightScale, v => settings.heightScale = v, "Height Scale");
                this.Add(outputHeightScale);

                if (dimension == TextureDimension.Tex3D)
                {
                    outputDepth = new IntegerField()
                    {
                        value     = settings.depth,
                        label     = "Depth",
                        isDelayed = true,
                    };
                    outputDepth.RegisterValueChangedCallback(e =>
                    {
                        owner.RegisterCompleteObjectUndo("Updated Depth " + e.newValue);
                        settings.depth = e.newValue;
                        onChanged?.Invoke();
                    });
                    this.Add(outputDepth);

                    outputDepthScale = CreateSizeScaleSlider(settings.depthScale, v => settings.depthScale = v, "Depth Scale");
                    this.Add(outputDepthScale);
                }
            }

            SliderInt CreateSizeScaleSlider(float defaultValue, Action <float> setter, string propertyName)
            {
                var slider = new SliderInt(0, (int)(Mathf.Log(k_MaxSizeScale, 2) * 2))
                {
                    value = SizeScaleToInt(settings.heightScale),
                    label = propertyName,
                };

                slider.RegisterValueChangedCallback(e =>
                {
                    owner.RegisterCompleteObjectUndo(propertyName + " " + e.newValue);
                    setter(IntToSizeScale(e.newValue));
                    onChanged?.Invoke();
                });

                return(slider);
            }

            // Dimension and Pixel Format
            formatHeader = new Label("Format");
            formatHeader.AddToClassList(headerStyleClass);
            this.Add(formatHeader);

            outputDimension       = showSettingsForNode ? new EnumField(settings.dimension) : new EnumField((GraphOutputDimension)settings.dimension);
            outputDimension.label = "Dimension";
            outputDimension.RegisterValueChangedCallback(e => {
                owner.RegisterCompleteObjectUndo("Updated Texture Dimension " + e.newValue);
                // Check if the new texture is not too high res:
                settings.dimension = (OutputDimension)e.newValue;
                if (settings.dimension == OutputDimension.Texture3D)
                {
                    long pixelCount = settings.GetResolvedWidth(graph) * settings.GetResolvedHeight(graph) * settings.GetResolvedDepth(graph);

                    // Above 16M pixels in a texture3D, processing can take too long and crash the GPU when a conversion happen
                    if (pixelCount > 16777216)
                    {
                        settings.sizeMode = OutputSizeMode.Absolute;
                        settings.SetPOTSize(64);
                    }
                }
                onChanged?.Invoke();
                ReloadSettingsView();
            });

            outputChannels       = showSettingsForNode ? new EnumField(settings.outputChannels) : new EnumField((GraphOutputChannel)settings.outputChannels);
            outputChannels.label = "Output Channels";
            outputChannels.RegisterValueChangedCallback(e => {
                owner.RegisterCompleteObjectUndo("Updated Output Channels " + e.newValue);
                settings.outputChannels = (OutputChannel)e.newValue;
                onChanged?.Invoke();
            });

            outputPrecision       = showSettingsForNode ? new EnumField(settings.outputPrecision) : new EnumField((GraphOutputPrecision)settings.outputPrecision);
            outputPrecision.label = "Output Precision";
            outputPrecision.RegisterValueChangedCallback(e => {
                owner.RegisterCompleteObjectUndo("Updated Output Precision " + e.newValue);
                settings.outputPrecision = (OutputPrecision)e.newValue;
                // outputPrecision.Init();
                onChanged?.Invoke();
            });

            this.Add(outputDimension);
            this.Add(outputChannels);
            this.Add(outputPrecision);

            UpdateFieldVisibility(settings);

            if (showSettingsForNode)
            {
                // Realtime fields and refresh mode
                otherHeader = new Label("Other");
                otherHeader.AddToClassList(headerStyleClass);
                this.Add(otherHeader);

                doubleBuffered = new Toggle("Double Buffered")
                {
                    value = settings.doubleBuffered,
                };
                doubleBuffered.RegisterValueChangedCallback(e => {
                    owner.RegisterCompleteObjectUndo("Set Double Buffered " + e.newValue);
                    settings.doubleBuffered = e.newValue;
                    onChanged?.Invoke();
                });

                Add(doubleBuffered);
            }
            else if (graph.type == MixtureGraphType.Realtime)
            {
                otherHeader = new Label("Realtime");
                otherHeader.AddToClassList(headerStyleClass);
                this.Add(otherHeader);

                AddRealtimeFields(owner);
            }
        }
        private void AddMainUI(VisualElement mainView)
        {
            var visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Packages/com.unity.2d.sprite/Editor/UI/SpriteEditor/SpriteFrameModuleInspector.uxml") as VisualTreeAsset;

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

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

            m_NameField.RegisterCallback <FocusOutEvent>((focus) =>
            {
                if (hasSelected)
                {
                    m_NameField.SetValueWithoutNotify(selectedSpriteName);
                }
            });


            m_PositionElement = m_SelectedFrameInspector.Q("position");
            m_PositionFieldX  = m_PositionElement.Q <IntegerField>("positionX");
            SetupIntegerField(m_PositionFieldX, UpdatePositionField, OnPositionIntXChange);

            m_PositionFieldY = m_PositionElement.Q <IntegerField>("positionY");
            SetupIntegerField(m_PositionFieldY, UpdatePositionField, OnPositionIntYChange);

            m_PositionFieldW = m_PositionElement.Q <IntegerField>("positionW");
            SetupIntegerField(m_PositionFieldW, UpdatePositionField, OnPositionIntWChange);

            m_PositionFieldH = m_PositionElement.Q <IntegerField>("positionH");
            SetupIntegerField(m_PositionFieldH, UpdatePositionField, OnPositionIntHChange);

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

            m_BorderFieldL = borderElement.Q <IntegerField>("borderL");
            SetupIntegerField(m_BorderFieldL, UpdateBorderField, OnBorderIntLChange);

            m_BorderFieldT = borderElement.Q <IntegerField>("borderT");
            SetupIntegerField(m_BorderFieldT, UpdateBorderField, OnBorderIntTChange);

            m_BorderFieldR = borderElement.Q <IntegerField>("borderR");
            SetupIntegerField(m_BorderFieldR, UpdateBorderField, OnBorderIntRChange);

            m_BorderFieldB = borderElement.Q <IntegerField>("borderB");
            SetupIntegerField(m_BorderFieldB, UpdateBorderField, OnBorderIntBChange);

            m_PivotField = m_SelectedFrameInspector.Q <EnumField>("pivotField");
            m_PivotField.Init(SpriteAlignment.Center);
            m_PivotField.label = L10n.Tr("Pivot");
            m_PivotField.RegisterValueChangedCallback((evt) =>
            {
                if (hasSelected)
                {
                    SpriteAlignment alignment = (SpriteAlignment)evt.newValue;
                    SetSpritePivotAndAlignment(selectedSpritePivot, alignment);
                    m_CustomPivotElement.SetEnabled(selectedSpriteAlignment == SpriteAlignment.Custom);
                    Vector2 pivot = selectedSpritePivotInCurUnitMode;
                    m_CustomPivotFieldX.SetValueWithoutNotify(pivot.x);
                    m_CustomPivotFieldY.SetValueWithoutNotify(pivot.y);
                }
            });


            m_PivotUnitModeField = m_SelectedFrameInspector.Q <EnumField>("pivotUnitModeField");
            m_PivotUnitModeField.Init(PivotUnitMode.Normalized);
            m_PivotUnitModeField.label = L10n.Tr("Pivot Unit Mode");
            m_PivotUnitModeField.RegisterValueChangedCallback((evt) =>
            {
                if (hasSelected)
                {
                    m_PivotUnitMode = (PivotUnitMode)evt.newValue;

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


            m_CustomPivotElement = m_SelectedFrameInspector.Q("customPivot");
            m_CustomPivotFieldX  = m_CustomPivotElement.Q <FloatField>("customPivotX");
            m_CustomPivotFieldX.RegisterValueChangedCallback((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 <FloatField>("customPivotY");
            m_CustomPivotFieldY.RegisterValueChangedCallback((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);
        }
        public TransitionInspector()
        {
            text = "Transition";

            _scrollView = new ScrollView(ScrollViewMode.Vertical);
            _scrollView.AddToClassList("content");
            Add(_scrollView);

            Foldout transitionsFoldout = new Foldout()
            {
                value = true, text = "Transitions"
            };

            transitionsFoldout.RegisterValueChangedCallback(e => e.StopPropagation());
            _scrollView.Add(transitionsFoldout);

            _transitions            = new ResizableListView();
            _transitions.name       = "Transitions";
            _transitions.itemHeight = 20;
            _transitions.makeItem   = () =>
            {
                VisualElement container = new VisualElement();

                Label label = new Label()
                {
                    pickingMode = PickingMode.Ignore
                };
                Button removeButton = new Button()
                {
                    text = "X"
                };

                container.Add(label);
                container.Add(removeButton);

                return(container);
            };
            _transitions.bindItem = (item, index) =>
            {
                void Remove()
                {
                    _connection.RemoveTransition(index);
                }

                item.Q <Label>().text = $"{((IStateNode)_connection.Source).Name} >>> {((StateNodeUI)_connection.Destination).Name}";
                Button removeButton = item.Q <Button>();
                removeButton.clicked -= Remove;
                removeButton.clicked += Remove;
            };
            _transitions.onSelectionChange += selection =>
            {
                _selectedTransition = (TransitionInfo)selection.First();
                BindTransitionFields(_selectedTransition);
            };
            _transitions.selectionType = SelectionType.Single;
            _transitions.reorderable   = true;

            transitionsFoldout.Add(_transitions);

            DurationTypeField = new EnumField("Duration Type", DurationType.Fixed);
            DurationTypeField.RegisterValueChangedCallback(e =>
            {
                _selectedTransition.DurationType = (DurationType)e.newValue;
                DurationField.label = (DurationType)e.newValue == DurationType.Fixed ? "Duration (s)" : "Duration (%)";
            });
            _scrollView.Add(DurationTypeField);

            DurationField = new FloatField("Duration (s)");
            DurationField.RegisterValueChangedCallback(e => _selectedTransition.Duration = e.newValue);
            _scrollView.Add(DurationField);

            OffsetTypeField = new EnumField("Offset Type", DurationType.Fixed);
            OffsetTypeField.RegisterValueChangedCallback(e =>
            {
                _selectedTransition.OffsetType = (DurationType)e.newValue;
                OffsetField.label = (DurationType)e.newValue == DurationType.Fixed ? "Offset (s)" : "Offset (%)";
            });
            _scrollView.Add(OffsetTypeField);

            OffsetField = new FloatField("Offset (s)");
            OffsetField.RegisterValueChangedCallback(e => _selectedTransition.Offset = e.newValue);
            _scrollView.Add(OffsetField);

            InterruptionSourceField = new EnumField("Interruption Source", TransitionInterruptionSource.None);
            InterruptionSourceField.RegisterValueChangedCallback(e =>
            {
                TransitionInterruptionSource interruptionSource = (TransitionInterruptionSource)e.newValue;
                _selectedTransition.InterruptionSource          = interruptionSource;

                if (interruptionSource == TransitionInterruptionSource.None || interruptionSource == TransitionInterruptionSource.NextState)
                {
                    OrderedInterruptionToggle.style.display = DisplayStyle.None;
                }
                else
                {
                    OrderedInterruptionToggle.style.display = DisplayStyle.Flex;
                }
            });
            _scrollView.Add(InterruptionSourceField);

            OrderedInterruptionToggle = new Toggle("Ordered Interruption");
            OrderedInterruptionToggle.RegisterValueChangedCallback(e =>
            {
                _selectedTransition.OrderedInterruption = e.newValue;
                e.StopPropagation();
            });
            OrderedInterruptionToggle.style.display = DisplayStyle.None;
            _scrollView.Add(OrderedInterruptionToggle);

            InterruptableByAnyStateToggle = new Toggle("Interruptable By Any State");
            InterruptableByAnyStateToggle.RegisterValueChangedCallback(e =>
            {
                _selectedTransition.InterruptableByAnyState = e.newValue;
                e.StopPropagation();
            });
            _scrollView.Add(InterruptableByAnyStateToggle);

            PlayAfterTransitionToggle = new Toggle("Play After Transition");
            PlayAfterTransitionToggle.RegisterValueChangedCallback(e =>
            {
                _selectedTransition.PlayAfterTransition = e.newValue;
                e.StopPropagation();
            });
            _scrollView.Add(PlayAfterTransitionToggle);

            Foldout conditionsFoldout = new Foldout()
            {
                value = true, text = "Conditions"
            };

            conditionsFoldout.RegisterValueChangedCallback(e => e.StopPropagation());
            _scrollView.Add(conditionsFoldout);

            VisualElement conditionListButtons = new VisualElement();

            conditionListButtons.style.flexDirection = FlexDirection.Row;
            conditionsFoldout.Add(conditionListButtons);

            Button removeConditionButton = new Button(() =>
            {
                if (_conditions.selectedItem == null)
                {
                    return;
                }

                int firstIndex = _conditions.selectedIndex;
                int indexFixer = 0;

                foreach (var index in _conditions.selectedIndices)
                {
                    _selectedTransition.Conditions.RemoveAt(index - indexFixer);
                    indexFixer++;
                }

                _conditions.Refresh();
                _conditions.selectedIndex = Mathf.Min(firstIndex, _selectedTransition.Conditions.Count - 1);
            })
            {
                text = "Remove Condition"
            };

            conditionListButtons.Add(removeConditionButton);

            Button addConditionButton = new Button(() =>
            {
                _selectedTransition.Conditions.Add(new TransitionInfoCondition());
                _conditions.Refresh();
            })
            {
                text = "Add Condition"
            };

            conditionListButtons.Add(addConditionButton);

            _conditions            = new ResizableListView();
            _conditions.name       = "Conditions";
            _conditions.itemHeight = 25;
            _conditions.makeItem   = () =>
            {
                TransitionConditionUI transitionCondition = new TransitionConditionUI();

                return(transitionCondition);
            };
            _conditions.bindItem = (item, index) =>
            {
                ((TransitionConditionUI)item).Bind(_selectedTransition.Conditions[index]);
            };
            _conditions.selectionType = SelectionType.Multiple;
            _conditions.reorderable   = true;
            conditionsFoldout.Add(_conditions);

            RegisterCallback <ChangeEvent <bool> >(e => ToggleInClassList("expanded"));
        }
        void BuildVector1PropertyView(Vector1ShaderProperty floatProperty)
        {
            VisualElement[] rows = null;

            switch (floatProperty.floatType)
            {
            case FloatType.Slider:
            {
                float min = Mathf.Min(floatProperty.value, floatProperty.rangeValues.x);
                float max = Mathf.Max(floatProperty.value, floatProperty.rangeValues.y);
                floatProperty.rangeValues = new Vector2(min, max);

                var defaultField = new FloatField {
                    value = floatProperty.value
                };
                var minField = new FloatField {
                    value = floatProperty.rangeValues.x
                };
                var maxField = new FloatField {
                    value = floatProperty.rangeValues.y
                };

                defaultField.RegisterValueChangedCallback(evt =>
                    {
                        var value           = (float)evt.newValue;
                        floatProperty.value = value;
                        this.MarkDirtyRepaint();
                    });
                defaultField.Q("unity-text-input").RegisterCallback <FocusOutEvent>(evt =>
                    {
                        m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                        float minValue            = Mathf.Min(floatProperty.value, floatProperty.rangeValues.x);
                        float maxValue            = Mathf.Max(floatProperty.value, floatProperty.rangeValues.y);
                        floatProperty.rangeValues = new Vector2(minValue, maxValue);
                        minField.value            = minValue;
                        maxField.value            = maxValue;
                        DirtyNodes();
                    });
                minField.RegisterValueChangedCallback(evt =>
                    {
                        m_Graph.owner.RegisterCompleteObjectUndo("Change Range Property Minimum");
                        float newValue            = (float)evt.newValue;
                        floatProperty.rangeValues = new Vector2(newValue, floatProperty.rangeValues.y);
                        DirtyNodes();
                    });
                minField.Q("unity-text-input").RegisterCallback <FocusOutEvent>(evt =>
                    {
                        floatProperty.value = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x);
                        defaultField.value  = floatProperty.value;
                        DirtyNodes();
                    });
                maxField.RegisterValueChangedCallback(evt =>
                    {
                        m_Graph.owner.RegisterCompleteObjectUndo("Change Range Property Maximum");
                        float newValue            = (float)evt.newValue;
                        floatProperty.rangeValues = new Vector2(floatProperty.rangeValues.x, newValue);
                        DirtyNodes();
                    });
                maxField.Q("unity-text-input").RegisterCallback <FocusOutEvent>(evt =>
                    {
                        floatProperty.value = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x);
                        defaultField.value  = floatProperty.value;
                        DirtyNodes();
                    });
                rows    = new VisualElement[4];
                rows[0] = CreateRow("Default", defaultField);
                rows[2] = CreateRow("Min", minField);
                rows[3] = CreateRow("Max", maxField);
            }
            break;

            case FloatType.Integer:
            {
                floatProperty.value = (int)floatProperty.value;
                var defaultField = new IntegerField {
                    value = (int)floatProperty.value
                };
                defaultField.RegisterValueChangedCallback(evt =>
                    {
                        m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                        var value           = (int)evt.newValue;
                        floatProperty.value = value;
                        DirtyNodes();
                    });
                rows    = new VisualElement[2];
                rows[0] = CreateRow("Default", defaultField);
            }
            break;

            default:
            {
                var defaultField = new FloatField {
                    value = floatProperty.value
                };
                defaultField.RegisterValueChangedCallback(evt =>
                    {
                        m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                        var value           = (float)evt.newValue;
                        floatProperty.value = value;
                        DirtyNodes();
                    });
                rows    = new VisualElement[2];
                rows[0] = CreateRow("Default", defaultField);
            }
            break;
            }

            if (!m_Graph.isSubGraph)
            {
                var modeField = new EnumField(floatProperty.floatType);
                modeField.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Vector1 Mode");
                    var value = (FloatType)evt.newValue;
                    floatProperty.floatType = value;
                    if (rows != null)
                    {
                        RemoveElements(rows);
                    }
                    BuildVector1PropertyView(floatProperty);
                    this.MarkDirtyRepaint();
                });
                rows[1] = CreateRow("Mode", modeField);
            }

            if (rows == null)
            {
                return;
            }

            for (int i = 0; i < rows.Length; i++)
            {
                Add(rows[i]);
            }
        }
        void OnEnable()
        {
            rootVisualElement.StyleBorderWidth(1);
            Color c = new Color32(58, 121, 187, 255);

            rootVisualElement.StyleBorderColor(c);

            // EditorHelpBox helpBox = new EditorHelpBox("This feature currently in preview state", MessageType.Info);
            // rootVisualElement.Add(helpBox);

            hierarchyLocalData         = HierarchyEditor.Instance.GetHierarchyLocalData(Selection.activeGameObject.scene);
            gameObject                 = Selection.activeGameObject;
            Selection.activeGameObject = null;

            CustomRowItem customRowItem = null;

            if (hierarchyLocalData.TryGetCustomRowData(gameObject, out customRowItem) == false)
            {
                customRowItem = hierarchyLocalData.CreateCustomRowItemFor(gameObject);
            }

            Hierarchy2.Toggle useBackground = new Hierarchy2.Toggle("Use Background",
                                                                    customRowItem.useBackground,
                                                                    Justify.FlexStart,
                                                                    (evt) =>
            {
                customRowItem.useBackground = evt.newValue;
                EditorApplication.RepaintHierarchyWindow();
            });
            rootVisualElement.Add(useBackground);

            EnumField backgroundStyle = new EnumField(customRowItem.backgroundStyle);

            backgroundStyle.label = "Background Style";
            backgroundStyle.RegisterValueChangedCallback((evt) =>
            {
                customRowItem.backgroundStyle = (CustomRowItem.BackgroundStyle)evt.newValue;
                EditorApplication.RepaintHierarchyWindow();
            });
            rootVisualElement.Add(backgroundStyle);

            EnumField backgroundMode = new EnumField(customRowItem.backgroundMode);

            backgroundMode.label = "Background Mode";
            backgroundMode.RegisterValueChangedCallback((evt) =>
            {
                customRowItem.backgroundMode = (CustomRowItem.BackgroundMode)evt.newValue;
                EditorApplication.RepaintHierarchyWindow();
            });
            rootVisualElement.Add(backgroundMode);

            ColorField backgroundColor = new ColorField("Background Color");

            backgroundColor.value = customRowItem.backgroundColor;
            backgroundColor.RegisterValueChangedCallback((evt) =>
            {
                customRowItem.backgroundColor = evt.newValue;
                EditorApplication.RepaintHierarchyWindow();
            });
            rootVisualElement.Add(backgroundColor);
        }
Beispiel #16
0
        private void Init(SimulatorJsonSerialization states)
        {
            InitPlayerSettings(states);

            bool overrideDefaultPlayerSettings = (states != null) ? states.overrideDefaultPlayerSettings : false;

            m_OverrideDefaultPlayerSettings = m_RootElement.Q <Toggle>("override-default-player-settings");
            m_OverrideDefaultPlayerSettings.RegisterValueChangedCallback(SetOverridePlayerSettings);
            m_OverrideDefaultPlayerSettings.SetValueWithoutNotify(overrideDefaultPlayerSettings);
            UpdateOverridePlayerSettingsStatus();

            m_CustomizedPlayerSettingsElement = m_RootElement.Q <VisualElement>("customized-player-settings");

            m_StartInFullscreen = m_RootElement.Q <Toggle>("android-start-in-fullscreen");
            m_StartInFullscreen.SetValueWithoutNotify(m_CustomizedPlayerSettings.androidStartInFullscreen);
            m_StartInFullscreen.RegisterValueChangedCallback((evt) => { m_CustomizedPlayerSettings.androidStartInFullscreen = evt.newValue; });

            m_ResolutionScalingMode = m_RootElement.Q <EnumField>("resolution-scaling-mode");
            m_ResolutionScalingMode.Init(ResolutionScalingMode.Disabled);
            m_ResolutionScalingMode.RegisterValueChangedCallback(SetResolutionScalingMode);
            m_ResolutionScalingMode.SetValueWithoutNotify(m_CustomizedPlayerSettings.resolutionScalingMode);

            #region DPI
            m_DpiContainer = m_RootElement.Q <VisualElement>("dpi-container");

            m_DpiSlider = m_DpiContainer.Q <SliderInt>("dpi-slider");
            m_DpiSlider.RegisterValueChangedCallback(SyncDpiField);
            m_DpiSlider.SetValueWithoutNotify(m_CustomizedPlayerSettings.targetDpi);

            m_DpiField = m_DpiContainer.Q <IntegerField>("dpi-field");
            m_DpiField.RegisterValueChangedCallback(SyncDpiSlider);
            m_DpiField.RegisterCallback <KeyDownEvent>(OnDpiFieldKeyDown);
            m_DpiField.SetValueWithoutNotify(m_CustomizedPlayerSettings.targetDpi);
            #endregion

            #region Orientation
            m_DefaultOrientation = m_RootElement.Q <EnumField>("default-screen-orientation");
            m_DefaultOrientation.Init(UIOrientation.AutoRotation);
            m_DefaultOrientation.RegisterValueChangedCallback(SetDefaultOrientation);
            m_DefaultOrientation.SetValueWithoutNotify(m_CustomizedPlayerSettings.defaultOrientation);

            m_AllowedOrienations = m_RootElement.Q <Foldout>("allowed-orientations");

            m_AllowedPortrait = m_AllowedOrienations.Q <Toggle>("orientation-allow-portrait");
            m_AllowedPortrait.SetValueWithoutNotify(m_CustomizedPlayerSettings.allowedPortrait);
            m_AllowedPortrait.RegisterValueChangedCallback((evt) => { m_CustomizedPlayerSettings.allowedPortrait = evt.newValue; });

            m_AllowedPortraitUpsideDown = m_AllowedOrienations.Q <Toggle>("orientation-allow-portrait-upside-down");
            m_AllowedPortraitUpsideDown.SetValueWithoutNotify(m_CustomizedPlayerSettings.allowedPortraitUpsideDown);
            m_AllowedPortraitUpsideDown.RegisterValueChangedCallback((evt) => { m_CustomizedPlayerSettings.allowedPortraitUpsideDown = evt.newValue; });

            m_AllowedLandscapeLeft = m_AllowedOrienations.Q <Toggle>("orientation-allow-landscape-left");
            m_AllowedLandscapeLeft.SetValueWithoutNotify(m_CustomizedPlayerSettings.allowedLandscapeLeft);
            m_AllowedLandscapeLeft.RegisterValueChangedCallback((evt) => { m_CustomizedPlayerSettings.allowedLandscapeLeft = evt.newValue; });

            m_AllowedLandscapeRight = m_AllowedOrienations.Q <Toggle>("orientation-allow-landscape-right");
            m_AllowedLandscapeRight.SetValueWithoutNotify(m_CustomizedPlayerSettings.allowedLandscapeRight);
            m_AllowedLandscapeRight.RegisterValueChangedCallback((evt) => { m_CustomizedPlayerSettings.allowedLandscapeRight = evt.newValue; });
            #endregion

            #region Graphics API
            m_AutoGraphicsAPI = m_RootElement.Q <Toggle>("auto-graphics-api");
            m_AutoGraphicsAPI.SetValueWithoutNotify(m_CustomizedPlayerSettings.autoGraphicsAPI);
            m_AutoGraphicsAPI.RegisterValueChangedCallback(SetAutoGraphicsAPI);

            m_GraphicsAPIPlaceholder = m_RootElement.Q <VisualElement>("graphics-api-placeholder");
            m_GraphicsAPIPlaceholder.SetEnabled(!m_CustomizedPlayerSettings.autoGraphicsAPI);
            #endregion

            UpdateCustomizedPlayerSettings(m_OverrideDefaultPlayerSettings.value);
            UpdateStartInFullScreen();
            UpdateResolutionScalingMode(m_CustomizedPlayerSettings.resolutionScalingMode);
            UpdateAllowedOrientations(m_CustomizedPlayerSettings.defaultOrientation);
            UpdateGraphicsAPI();
        }
Beispiel #17
0
        public static DialogueNode Create(string title, DialogueProperties properties, string next = "")
        {
            var node = new DialogueNode
            {
                title      = title,
                Guid       = System.Guid.NewGuid().ToString(),
                name       = "CustomNode",
                Properties = properties,
            };


            var inputPort = DialoguePort.Create(Direction.Input, Port.Capacity.Multi);

            inputPort.portName = "Prev";
            inputPort.name     = "Port";

            var outputPort = DialoguePort.Create(Direction.Output, Port.Capacity.Single);

            outputPort.portName = "Next";
            outputPort.name     = "Port";
            (outputPort as DialoguePort).Next = next;

            var propertiesFoldout = new Foldout
            {
                text = "Dialogue Properties"
            };

            //Dialogue Background
            var bgField = new ObjectField
            {
                objectType = typeof(Sprite),
                value      = properties.Speaker,
                label      = "Background"
            };

            bgField.RegisterValueChangedCallback(e => {
                node.Properties.Background = e.newValue as Sprite;
            });
            node.Properties.Background = bgField.value as Sprite;

            //Create Dialogue Properties
            var sentenceTextfield = new TextField
            {
                value     = properties.Text,
                multiline = true,
            };

            node.Properties.Text = sentenceTextfield.value;
            sentenceTextfield.RegisterValueChangedCallback(e => {
                node.Properties.Text = e.newValue;
            });

            //Create Speaker
            var speakerField = new ObjectField
            {
                objectType = typeof(Character),
                value      = properties.Speaker,
                label      = "Speaker"
            };

            speakerField.RegisterValueChangedCallback(e => {
                node.Properties.Speaker = e.newValue as Character;
            });
            node.Properties.Speaker = speakerField.value as Character;
            var speakerPositionEnum = new EnumField();

            speakerPositionEnum.label = "Speaker On-Screen Position";
            speakerPositionEnum.Init(CharacterScreenPosition.Middle);
            speakerPositionEnum.value = CharacterScreenPosition.Middle;
            speakerPositionEnum.RegisterValueChangedCallback(e => {
                node.Properties.speakerPosition = (CharacterScreenPosition)e.newValue;
            });


            //Create Conversant1
            var conversant1Field = new ObjectField
            {
                objectType = typeof(Character),
                value      = properties.Conversant1,
                label      = "Conversant1"
            };

            conversant1Field.RegisterValueChangedCallback(e => {
                node.Properties.Conversant1 = e.newValue as Character;
            });
            node.Properties.Conversant1 = conversant1Field.value as Character;
            var conversant1PositionEnum = new EnumField();

            conversant1PositionEnum.label = "Conversant1 On-Screen Position";
            conversant1PositionEnum.Init(properties.conversant1Position);
            conversant1PositionEnum.value = properties.conversant1Position;
            conversant1PositionEnum.RegisterValueChangedCallback(e => {
                node.Properties.conversant1Position = (CharacterScreenPosition)e.newValue;
            });
            //Create Conversant2
            var conversant2Field = new ObjectField
            {
                objectType = typeof(Character),
                value      = properties.Conversant2,
                label      = "Conversant2"
            };

            conversant2Field.RegisterValueChangedCallback(e => {
                node.Properties.Conversant2 = e.newValue as Character;
            });
            node.Properties.Conversant2 = conversant2Field.value as Character;
            var conversant2PositionEnum = new EnumField();

            conversant2PositionEnum.label = "Conversant2 On-Screen Position";
            conversant2PositionEnum.Init(properties.conversant2Position);
            conversant2PositionEnum.value = properties.conversant2Position;
            conversant2PositionEnum.RegisterValueChangedCallback(e => {
                node.Properties.conversant2Position = (CharacterScreenPosition)e.newValue;
            });



            node.mainContainer.Add(propertiesFoldout);

            propertiesFoldout.contentContainer.Add(bgField);
            propertiesFoldout.contentContainer.Add(speakerField);
            propertiesFoldout.contentContainer.Add(speakerPositionEnum);
            propertiesFoldout.contentContainer.Add(conversant1Field);
            propertiesFoldout.contentContainer.Add(conversant1PositionEnum);
            propertiesFoldout.contentContainer.Add(conversant2Field);
            propertiesFoldout.contentContainer.Add(conversant2PositionEnum);



            node.mainContainer.Add(sentenceTextfield);

            node.inputContainer.Add(inputPort);

            node.outputContainer.Add(outputPort);
            node.RefreshPorts();
            node.RefreshExpandedState();
            node.SetPosition(new Rect(Vector2.zero, nodeSize));


            return(node);
        }
Beispiel #18
0
        void ReloadSettingsView()
        {
            // Remove all old fields
            Clear();

            var title     = new Label("Node Output Settings");
            var dimension = node.rtSettings.GetTextureDimension(graph);

            title.AddToClassList("PropertyEditorTitle");
            this.Add(title);

            // Wrap and Filter Modes
            var smpHeader = new Label("Sampler States");

            smpHeader.AddToClassList("PropertyEditorHeader");
            this.Add(smpHeader);

            wrapMode = new EnumField(node.rtSettings.wrapMode)
            {
                label = "Wrap Mode",
            };
            wrapMode.RegisterValueChangedCallback(e =>
            {
                owner.RegisterCompleteObjectUndo("Updated Wrap Mode " + e.newValue);
                node.rtSettings.wrapMode = (TextureWrapMode)e.newValue;
                onChanged?.Invoke();
            });

            filterMode = new EnumField(node.rtSettings.filterMode)
            {
                label = "Filter Mode",
            };
            filterMode.RegisterValueChangedCallback(e =>
            {
                owner.RegisterCompleteObjectUndo("Updated Filter Mode " + e.newValue);
                node.rtSettings.filterMode = (FilterMode)e.newValue;
                onChanged?.Invoke();
            });

            this.Add(wrapMode);
            this.Add(filterMode);

            // Size Modes
            var sizeHeader = new Label("Size Properties");

            sizeHeader.AddToClassList("PropertyEditorHeader");
            this.Add(sizeHeader);

            outputWidthMode = new EnumField(node.rtSettings.widthMode)
            {
                label = "Width Mode",
            };
            outputWidthMode.RegisterValueChangedCallback(e => {
                owner.RegisterCompleteObjectUndo("Updated Texture Dimension " + e.newValue);
                node.rtSettings.widthMode = (OutputSizeMode)e.newValue;
                onChanged?.Invoke();
                UpdateFieldVisibility(node);
            });
            this.Add(outputWidthMode);

            if (dimension != TextureDimension.Cube)
            {
                outputHeightMode = new EnumField(node.rtSettings.heightMode)
                {
                    label = "Height Mode",
                };
                outputHeightMode.RegisterValueChangedCallback(e => {
                    owner.RegisterCompleteObjectUndo("Updated Texture Dimension " + e.newValue);
                    node.rtSettings.heightMode = (OutputSizeMode)e.newValue;
                    onChanged?.Invoke();
                    UpdateFieldVisibility(node);
                });
                this.Add(outputHeightMode);

                if (dimension == TextureDimension.Tex3D)
                {
                    outputDepthMode = new EnumField(node.rtSettings.depthMode)
                    {
                        label = "Depth Mode",
                    };
                    outputDepthMode.RegisterValueChangedCallback(e => {
                        owner.RegisterCompleteObjectUndo("Updated Texture Dimension " + e.newValue);
                        node.rtSettings.depthMode = (OutputSizeMode)e.newValue;
                        onChanged?.Invoke();
                        UpdateFieldVisibility(node);
                    });
                    this.Add(outputDepthMode);
                }
            }

            potSize = new EnumField(node.rtSettings.potSize)
            {
                value = node.rtSettings.potSize,
                label = "Resolution",
            };
            potSize.RegisterValueChangedCallback(e =>
            {
                owner.RegisterCompleteObjectUndo("Updated Size " + e.newValue);
                var size = (POTSize)e.newValue;
                node.rtSettings.potSize = size;

                if (size != POTSize.Custom)
                {
                    node.rtSettings.width      = (int)size;
                    node.rtSettings.height     = (int)size;
                    node.rtSettings.sliceCount = (int)size;
                }
                else
                {
                    node.rtSettings.width      = outputWidth.value;
                    node.rtSettings.height     = outputHeight.value;
                    node.rtSettings.sliceCount = outputDepth.value;
                }

                onChanged?.Invoke();
                UpdateFieldVisibility(node);
            });

            this.Add(potSize);

            outputWidth = new IntegerField()
            {
                value     = node.rtSettings.width,
                label     = "Width",
                isDelayed = true,
            };
            outputWidth.RegisterValueChangedCallback(e =>
            {
                owner.RegisterCompleteObjectUndo("Updated Width " + e.newValue);
                node.rtSettings.width = e.newValue;
                onChanged?.Invoke();
            });
            this.Add(outputWidth);

            outputWidthPercentage = new FloatField()
            {
                value     = node.rtSettings.widthPercent,
                label     = "Width Percentage",
                isDelayed = true,
            };
            outputWidthPercentage.RegisterValueChangedCallback(e =>
            {
                owner.RegisterCompleteObjectUndo("Updated Width " + e.newValue);
                node.rtSettings.widthPercent = e.newValue;
                onChanged?.Invoke();
            });
            this.Add(outputWidthPercentage);

            if (dimension != TextureDimension.Cube)
            {
                outputHeight = new IntegerField()
                {
                    value     = node.rtSettings.height,
                    label     = "Height",
                    isDelayed = true,
                };
                outputHeight.RegisterValueChangedCallback(e =>
                {
                    owner.RegisterCompleteObjectUndo("Updated Height " + e.newValue);
                    node.rtSettings.height = e.newValue;
                    onChanged?.Invoke();
                });
                this.Add(outputHeight);

                outputHeightPercentage = new FloatField()
                {
                    value     = node.rtSettings.heightPercent,
                    label     = "Height Percentage",
                    isDelayed = true,
                };
                outputHeightPercentage.RegisterValueChangedCallback(e =>
                {
                    owner.RegisterCompleteObjectUndo("Updated Height " + e.newValue);
                    node.rtSettings.heightPercent = e.newValue;
                    onChanged?.Invoke();
                });
                this.Add(outputHeightPercentage);

                if (dimension == TextureDimension.Tex3D)
                {
                    outputDepth = new IntegerField()
                    {
                        value     = node.rtSettings.sliceCount,
                        label     = "Depth",
                        isDelayed = true,
                    };
                    outputDepth.RegisterValueChangedCallback(e =>
                    {
                        owner.RegisterCompleteObjectUndo("Updated Depth " + e.newValue);
                        node.rtSettings.sliceCount = e.newValue;
                        onChanged?.Invoke();
                    });
                    this.Add(outputDepth);

                    outputDepthPercentage = new FloatField()
                    {
                        value     = node.rtSettings.depthPercent,
                        label     = "Depth Percentage",
                        isDelayed = true,
                    };
                    outputDepthPercentage.RegisterValueChangedCallback(e =>
                    {
                        owner.RegisterCompleteObjectUndo("Updated Depth " + e.newValue);
                        node.rtSettings.depthPercent = e.newValue;
                        onChanged?.Invoke();
                    });
                    this.Add(outputDepthPercentage);
                }
            }

            // Dimension and Pixel Format
            var formatHeader = new Label("Format");

            formatHeader.AddToClassList("PropertyEditorHeader");
            this.Add(formatHeader);

            outputDimension = new EnumField(node.rtSettings.dimension)
            {
                label = "Dimension",
            };
            outputDimension.RegisterValueChangedCallback(e => {
                owner.RegisterCompleteObjectUndo("Updated Texture Dimension " + e.newValue);
                node.rtSettings.dimension = (OutputDimension)e.newValue;
                onChanged?.Invoke();
            });

            outputFormat = new EnumField(node.rtSettings.targetFormat)
            {
                label = "Pixel Format",
            };
            outputFormat.RegisterValueChangedCallback(e => {
                owner.RegisterCompleteObjectUndo("Updated Graphics Format " + e.newValue);
                node.rtSettings.targetFormat = (OutputFormat)e.newValue;
                onChanged?.Invoke();
            });

            this.Add(outputDimension);
            this.Add(outputFormat);

            UpdateFieldVisibility(node);

            if (owner.graph.isRealtime)
            {
                AddRealtimeFields(node, owner);
            }
        }
        public void GenerateBlackBoard(GraphData currentData)
        {
            Blackboard blackboard = new Blackboard(this)
            {
                scrollable = true,
            };

            blackboard.AddToClassList("grayboard");
            //blackboard.Add(new BlackboardSection { title="Exposed Properties" });
            blackboard.addItemRequested = _blackboard => { };
            blackboard.SetPosition(new Rect(10, 30, 200, 200));
            this.Add(blackboard);

            /* Start: how to add to blackboard */

            /*var container = new VisualElement();
             * var blackboardField = new BlackboardField {
             *  text = "Sample_Property",
             *  typeText = "String Property"
             * };
             * var blackboardFieldValue = new TextField("Value") {
             *  value = "Value"
             * };
             * blackboardFieldValue.RegisterValueChangedCallback(evt => {
             *  Debug.Log(evt.newValue);
             * });
             * var blackBoardRow = new BlackboardRow(blackboardField, blackboardFieldValue);
             * container.Add(blackboardField);
             * container.Add(blackBoardRow);
             * blackboard.Add(container);*/
            /* End: how to add to blackboard */
            if (currentData != null)
            {
                blackboard.title    = currentData.name;
                blackboard.subTitle = "Properties";
                FieldInfo[] fields = currentData.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance);
                //Debug.Log(currentData.GetType());
                for (int i = 0; i < fields.Length; i++)
                {
                    FieldInfo fieldInfo = fields[i];
                    if (!hiddenFields.Contains(fieldInfo.Name))
                    {
                        //Debug.Log(fields[i].ToString());
                        string            fName     = SplitCamelCase(fieldInfo.Name);
                        var               container = new VisualElement();
                        BlackboardSection bbField;
                        BlackboardRow     bbRow;
                        switch (fieldInfo.FieldType.ToString())
                        {
                        case "System.String":
                            bbField = new BlackboardSection {
                                title = fName
                            };
                            container.Add(bbField);
                            TextField bbfValue = new TextField()
                            {
                                value     = fieldInfo.GetValue(currentData) as string,
                                multiline = true
                            };
                            bbfValue.RegisterValueChangedCallback(evt => {
                                fieldInfo.SetValue(currentData, evt.newValue);
                                //Debug.Log(evt.newValue);
                            });
                            bbRow = new BlackboardRow(bbField, bbfValue);
                            container.Add(bbRow);
                            break;

                        case "System.Int32":
                            bbField = new BlackboardSection {
                                title = fName
                            };
                            container.Add(bbField);
                            IntegerField bbfIntValue = new IntegerField()
                            {
                                value = (int)fieldInfo.GetValue(currentData)
                            };
                            bbfIntValue.RegisterValueChangedCallback(evt => {
                                fieldInfo.SetValue(currentData, evt.newValue);
                                //Debug.Log(evt.newValue);
                            });
                            bbRow = new BlackboardRow(bbField, bbfIntValue);
                            container.Add(bbRow);
                            break;

                        case "System.Single":
                            bbField = new BlackboardSection {
                                title = fName
                            };
                            container.Add(bbField);
                            FloatField bbfFloatValue = new FloatField()
                            {
                                value = (float)fieldInfo.GetValue(currentData)
                            };
                            bbfFloatValue.RegisterValueChangedCallback(evt => {
                                fieldInfo.SetValue(currentData, evt.newValue);
                                //Debug.Log(evt.newValue);
                            });
                            bbRow = new BlackboardRow(bbField, bbfFloatValue);
                            container.Add(bbRow);
                            break;

                        case "UnityEngine.Vector2":
                            bbField = new BlackboardSection {
                                title = fName
                            };
                            container.Add(bbField);
                            Vector2Field bbfVector2Value = new Vector2Field()
                            {
                                value = (Vector2)fieldInfo.GetValue(currentData)
                            };
                            bbfVector2Value.RegisterValueChangedCallback(evt => {
                                fieldInfo.SetValue(currentData, evt.newValue);
                                //Debug.Log(evt.newValue);
                            });
                            bbRow = new BlackboardRow(bbField, bbfVector2Value);
                            container.Add(bbRow);
                            break;

                        case "UnityEngine.Vector3":
                            bbField = new BlackboardSection {
                                title = fName
                            };
                            container.Add(bbField);
                            Vector3Field bbfVector3Value = new Vector3Field()
                            {
                                value = (Vector3)fieldInfo.GetValue(currentData)
                            };
                            bbfVector3Value.RegisterValueChangedCallback(evt => {
                                fieldInfo.SetValue(currentData, evt.newValue);
                                //Debug.Log(evt.newValue);
                            });
                            bbRow = new BlackboardRow(bbField, bbfVector3Value);
                            container.Add(bbRow);
                            break;

                        case "UnityEngine.AnimationCurve":
                            bbField = new BlackboardSection {
                                title = fName
                            };
                            container.Add(bbField);
                            CurveField bbfAnimationCurveValue = new CurveField()
                            {
                                value = (UnityEngine.AnimationCurve)fieldInfo.GetValue(currentData)
                            };
                            bbfAnimationCurveValue.RegisterValueChangedCallback(evt => {
                                fieldInfo.SetValue(currentData, evt.newValue);
                                //Debug.Log(evt.newValue);
                            });
                            bbRow = new BlackboardRow(bbField, bbfAnimationCurveValue);
                            container.Add(bbRow);
                            break;

                        default:
                            if (fieldInfo.FieldType.ToString().IndexOf("UnityEngine.") == 0)
                            {
                                bbField = new BlackboardSection {
                                    title = fName
                                };
                                container.Add(bbField);
                                ObjectField bbfObjectValue = new ObjectField()
                                {
                                    value             = (UnityEngine.Object)fieldInfo.GetValue(currentData),
                                    allowSceneObjects = false,
                                    objectType        = fieldInfo.FieldType
                                };
                                bbfObjectValue.RegisterValueChangedCallback(evt => {
                                    fieldInfo.SetValue(currentData, evt.newValue);
                                    //Debug.Log(evt.newValue);
                                });
                                bbRow = new BlackboardRow(bbField, bbfObjectValue);
                                container.Add(bbRow);
                            }
                            else
                            {
                                bbField = new BlackboardSection {
                                    title = fName
                                };
                                container.Add(bbField);
                                EnumField bbfEnumValue = new EnumField((System.Enum)fieldInfo.GetValue(currentData))
                                {
                                    value = (System.Enum)fieldInfo.GetValue(currentData)
                                };
                                bbfEnumValue.RegisterValueChangedCallback(evt => {
                                    fieldInfo.SetValue(currentData, evt.newValue);
                                    //Debug.Log(evt.newValue);
                                });
                                bbRow = new BlackboardRow(bbField, bbfEnumValue);
                                container.Add(bbRow);
                            }
                            break;
                        }

                        blackboard.Add(container);
                    }
                }
            }
            // Get the properties of 'Type' class object.
        }
Beispiel #20
0
        void ReloadSettingsView()
        {
            // Remove all old fields
            Clear();

            var title     = new Label("Node Output Settings");
            var dimension = node.rtSettings.GetTextureDimension(graph);

            title.AddToClassList("PropertyEditorTitle");
            this.Add(title);

            // Wrap and Filter Modes
            smpHeader = new Label("Sampler States");
            smpHeader.AddToClassList(headerStyleClass);
            this.Add(smpHeader);

            wrapMode = new EnumField(node.rtSettings.wrapMode)
            {
                label = "Wrap Mode",
            };
            wrapMode.RegisterValueChangedCallback(e =>
            {
                owner.RegisterCompleteObjectUndo("Updated Wrap Mode " + e.newValue);
                node.rtSettings.wrapMode = (TextureWrapMode)e.newValue;
                onChanged?.Invoke();
            });

            filterMode = new EnumField(node.rtSettings.filterMode)
            {
                label = "Filter Mode",
            };
            filterMode.RegisterValueChangedCallback(e =>
            {
                owner.RegisterCompleteObjectUndo("Updated Filter Mode " + e.newValue);
                node.rtSettings.filterMode = (FilterMode)e.newValue;
                onChanged?.Invoke();
            });

            this.Add(wrapMode);
            this.Add(filterMode);

            // Size Modes
            sizeHeader = new Label("Size Properties");
            sizeHeader.AddToClassList(headerStyleClass);
            this.Add(sizeHeader);

            outputWidthMode = new EnumField(node.rtSettings.widthMode)
            {
                label = "Width Mode",
            };
            outputWidthMode.RegisterValueChangedCallback(e => {
                owner.RegisterCompleteObjectUndo("Updated Texture Dimension " + e.newValue);
                node.rtSettings.widthMode = (OutputSizeMode)e.newValue;
                onChanged?.Invoke();
                UpdateFieldVisibility(node);
            });
            this.Add(outputWidthMode);

            if (dimension != TextureDimension.Cube)
            {
                outputHeightMode = new EnumField(node.rtSettings.heightMode)
                {
                    label = "Height Mode",
                };
                outputHeightMode.RegisterValueChangedCallback(e => {
                    owner.RegisterCompleteObjectUndo("Updated Texture Dimension " + e.newValue);
                    node.rtSettings.heightMode = (OutputSizeMode)e.newValue;
                    onChanged?.Invoke();
                    UpdateFieldVisibility(node);
                });
                this.Add(outputHeightMode);

                if (dimension == TextureDimension.Tex3D)
                {
                    outputDepthMode = new EnumField(node.rtSettings.depthMode)
                    {
                        label = "Depth Mode",
                    };
                    outputDepthMode.RegisterValueChangedCallback(e => {
                        owner.RegisterCompleteObjectUndo("Updated Texture Dimension " + e.newValue);
                        node.rtSettings.depthMode = (OutputSizeMode)e.newValue;
                        onChanged?.Invoke();
                        UpdateFieldVisibility(node);
                    });
                    this.Add(outputDepthMode);
                }
            }

            potSize = new EnumField(node.rtSettings.potSize)
            {
                value = node.rtSettings.potSize,
                label = "Resolution",
            };
            potSize.RegisterValueChangedCallback(e =>
            {
                owner.RegisterCompleteObjectUndo("Updated Size " + e.newValue);
                var size = (POTSize)e.newValue;
                node.rtSettings.potSize = size;

                if (size != POTSize.Custom)
                {
                    node.rtSettings.width      = (int)size;
                    node.rtSettings.height     = (int)size;
                    node.rtSettings.sliceCount = (int)size;
                }
                else
                {
                    node.rtSettings.width      = outputWidth.value;
                    node.rtSettings.height     = outputHeight.value;
                    node.rtSettings.sliceCount = outputDepth.value;
                }

                onChanged?.Invoke();
                UpdateFieldVisibility(node);
            });

            this.Add(potSize);

            outputWidth = new IntegerField()
            {
                value     = node.rtSettings.width,
                label     = "Width",
                isDelayed = true,
            };
            outputWidth.RegisterValueChangedCallback(e =>
            {
                owner.RegisterCompleteObjectUndo("Updated Width " + e.newValue);
                node.rtSettings.width = e.newValue;
                onChanged?.Invoke();
            });
            this.Add(outputWidth);

            outputWidthPercentage = new FloatField()
            {
                value     = node.rtSettings.widthPercent,
                label     = "Width Percentage",
                isDelayed = true,
            };
            outputWidthPercentage.RegisterValueChangedCallback(e =>
            {
                owner.RegisterCompleteObjectUndo("Updated Width " + e.newValue);
                node.rtSettings.widthPercent = e.newValue;
                onChanged?.Invoke();
            });
            this.Add(outputWidthPercentage);

            if (dimension != TextureDimension.Cube)
            {
                outputHeight = new IntegerField()
                {
                    value     = node.rtSettings.height,
                    label     = "Height",
                    isDelayed = true,
                };
                outputHeight.RegisterValueChangedCallback(e =>
                {
                    owner.RegisterCompleteObjectUndo("Updated Height " + e.newValue);
                    node.rtSettings.height = e.newValue;
                    onChanged?.Invoke();
                });
                this.Add(outputHeight);

                outputHeightPercentage = new FloatField()
                {
                    value     = node.rtSettings.heightPercent,
                    label     = "Height Percentage",
                    isDelayed = true,
                };
                outputHeightPercentage.RegisterValueChangedCallback(e =>
                {
                    owner.RegisterCompleteObjectUndo("Updated Height " + e.newValue);
                    node.rtSettings.heightPercent = e.newValue;
                    onChanged?.Invoke();
                });
                this.Add(outputHeightPercentage);

                if (dimension == TextureDimension.Tex3D)
                {
                    outputDepth = new IntegerField()
                    {
                        value     = node.rtSettings.sliceCount,
                        label     = "Depth",
                        isDelayed = true,
                    };
                    outputDepth.RegisterValueChangedCallback(e =>
                    {
                        owner.RegisterCompleteObjectUndo("Updated Depth " + e.newValue);
                        node.rtSettings.sliceCount = e.newValue;
                        onChanged?.Invoke();
                    });
                    this.Add(outputDepth);

                    outputDepthPercentage = new FloatField()
                    {
                        value     = node.rtSettings.depthPercent,
                        label     = "Depth Percentage",
                        isDelayed = true,
                    };
                    outputDepthPercentage.RegisterValueChangedCallback(e =>
                    {
                        owner.RegisterCompleteObjectUndo("Updated Depth " + e.newValue);
                        node.rtSettings.depthPercent = e.newValue;
                        onChanged?.Invoke();
                    });
                    this.Add(outputDepthPercentage);
                }
            }

            // Dimension and Pixel Format
            formatHeader = new Label("Format");
            formatHeader.AddToClassList(headerStyleClass);
            this.Add(formatHeader);

            outputDimension = new EnumField(node.rtSettings.dimension)
            {
                label = "Dimension",
            };
            outputDimension.RegisterValueChangedCallback(e => {
                owner.RegisterCompleteObjectUndo("Updated Texture Dimension " + e.newValue);
                // Check if the new texture is not too high res:
                node.rtSettings.dimension = (OutputDimension)e.newValue;
                if (node.rtSettings.dimension == OutputDimension.Texture3D)
                {
                    long pixelCount = node.rtSettings.GetWidth(graph) * node.rtSettings.GetHeight(graph) * node.rtSettings.GetDepth(graph);

                    // Above 16M pixels in a texture3D, processing can take too long and crash the GPU when a conversion happen
                    if (pixelCount > 16777216)
                    {
                        node.rtSettings.SetPOTSize(64);
                    }
                }
                onChanged?.Invoke();
            });

            outputChannels = new EnumField(node.rtSettings.outputChannels)
            {
                label = "Output Channels",
            };
            outputChannels.RegisterValueChangedCallback(e => {
                owner.RegisterCompleteObjectUndo("Updated Output Channels " + e.newValue);
                node.rtSettings.outputChannels = (OutputChannel)e.newValue;
                onChanged?.Invoke();
            });

            outputPrecision = new EnumField(node.rtSettings.outputPrecision)
            {
                label = "Output Precision",
            };
            outputPrecision.RegisterValueChangedCallback(e => {
                owner.RegisterCompleteObjectUndo("Updated Output Precision " + e.newValue);
                node.rtSettings.outputPrecision = (OutputPrecision)e.newValue;
                // outputPrecision.Init();
                onChanged?.Invoke();
            });

            this.Add(outputDimension);
            this.Add(outputChannels);
            this.Add(outputPrecision);

            UpdateFieldVisibility(node);

            if (owner.graph.isRealtime)
            {
                // Realtime fields and refresh mode
                otherHeader = new Label("Other");
                otherHeader.AddToClassList(headerStyleClass);
                this.Add(otherHeader);

                AddRealtimeFields(node, owner);
            }
        }
Beispiel #21
0
        BuilderStyleRow CreateAttributeRow(UxmlAttributeDescription attribute)
        {
            var attributeType = attribute.GetType();
            var vea           = currentVisualElement.GetVisualElementAsset();

            // Generate field label.
            var fieldLabel = BuilderNameUtilities.ConvertDashToHuman(attribute.name);

            BindableElement fieldElement = null;

            if (attribute is UxmlStringAttributeDescription)
            {
                var uiField = new TextField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attribute is UxmlFloatAttributeDescription)
            {
                var uiField = new FloatField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attribute is UxmlDoubleAttributeDescription)
            {
                var uiField = new DoubleField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attribute is UxmlIntAttributeDescription)
            {
                var uiField = new IntegerField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attribute is UxmlLongAttributeDescription)
            {
                var uiField = new LongField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attribute is UxmlBoolAttributeDescription)
            {
                var uiField = new Toggle(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attribute is UxmlColorAttributeDescription)
            {
                var uiField = new ColorField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attributeType.IsGenericType && attributeType.GetGenericArguments()[0].IsEnum)
            {
                var propInfo  = attributeType.GetProperty("defaultValue");
                var enumValue = propInfo.GetValue(attribute, null) as Enum;

                // Create and initialize the EnumField.
                var uiField = new EnumField(fieldLabel);
                uiField.Init(enumValue);

                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else
            {
                var uiField = new TextField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }

            // Create row.
            var styleRow = new BuilderStyleRow();

            styleRow.Add(fieldElement);

            // Link the field.
            fieldElement.SetProperty(BuilderConstants.InspectorLinkedStyleRowVEPropertyName, styleRow);
            fieldElement.SetProperty(BuilderConstants.InspectorLinkedAttributeDescriptionVEPropertyName, attribute);

            // Set initial value.
            RefreshAttributeField(fieldElement);

            // Setup field binding path.
            fieldElement.bindingPath = attribute.name;

            // Tooltip.
            var label = fieldElement.Q <Label>();

            if (label != null)
            {
                label.tooltip = attribute.name;
            }
            else
            {
                fieldElement.tooltip = attribute.name;
            }

            // Context menu.
            fieldElement.AddManipulator(new ContextualMenuManipulator(BuildAttributeFieldContextualMenu));

            return(styleRow);
        }
        public void RefreshPropertyValue(object val, int specificity)
        {
            if (val is StyleFloat)
            {
                var style = (StyleFloat)val;
                FloatField field = GetOrCreateField<FloatField, float>();
                if (!IsFocused(field))
                    field.SetValueWithoutNotify(style.value);
            }
            else if (val is StyleInt)
            {
                var style = (StyleInt)val;
                IntegerField field = GetOrCreateField<IntegerField, int>();
                if (!IsFocused(field))
                    field.SetValueWithoutNotify(style.value);
            }
            else if (val is StyleLength)
            {
                var style = (StyleLength)val;
                StyleLengthField field = GetOrCreateField<StyleLengthField, StyleLength>();
                if (!IsFocused(field))
                    field.SetValueWithoutNotify(style);
            }
            else if (val is StyleColor)
            {
                var style = (StyleColor)val;
                ColorField field = GetOrCreateField<ColorField, Color>();
                if (!IsFocused(field))
                    field.SetValueWithoutNotify(style.value);
            }
            else if (val is StyleFont)
            {
                var style = (StyleFont)val;
                ObjectField field = GetOrCreateObjectField<Font>();
                if (!IsFocused(field))
                    field.SetValueWithoutNotify(style.value);
            }
            else if (val is StyleBackground)
            {
                var background = ((StyleBackground)val).value;
                ObjectField field;
                if (background.vectorImage != null)
                    field = GetOrCreateObjectField<VectorImage>();
                else
                    field = GetOrCreateObjectField<Texture2D>();
                if (!IsFocused(field))
                    field.SetValueWithoutNotify(background.vectorImage != null ? (UnityEngine.Object)background.vectorImage : (UnityEngine.Object)background.texture);
            }
            else if (val is StyleCursor)
            {
                // Recreate the cursor fields every time since StyleCursor
                // can be made of different fields (based on the value)
                Clear();

                StyleCursor style = (StyleCursor)val;
                if (style.value.texture != null)
                {
                    var uiTextureField = new ObjectField(m_PropertyName) { value = style.value.texture };
                    uiTextureField.RegisterValueChangedCallback(e =>
                    {
                        StyleCursor styleCursor = (StyleCursor)StyleDebug.GetComputedStyleValue(m_SelectedElement.computedStyle, m_PropertyInfo.id);
                        var currentCursor = styleCursor.value;
                        currentCursor.texture = e.newValue as Texture2D;
                        SetPropertyValue(new StyleCursor(currentCursor));
                    });
                    Add(uiTextureField);

                    var uiHotspotField = new Vector2Field("hotspot") { value = style.value.hotspot };
                    uiHotspotField.RegisterValueChangedCallback(e =>
                    {
                        StyleCursor styleCursor = (StyleCursor)StyleDebug.GetComputedStyleValue(m_SelectedElement.computedStyle, m_PropertyInfo.id);
                        var currentCursor = styleCursor.value;
                        currentCursor.hotspot = e.newValue;
                        SetPropertyValue(new StyleCursor(currentCursor));
                    });
                    Add(uiHotspotField);
                }
                else
                {
                    int mouseId = style.value.defaultCursorId;
                    var uiField = new EnumField(m_PropertyName, (MouseCursor)mouseId);
                    uiField.RegisterValueChangedCallback(e =>
                    {
                        int cursorId = Convert.ToInt32(e.newValue);
                        var cursor = new Cursor() { defaultCursorId = cursorId };
                        SetPropertyValue(new StyleCursor(cursor));
                    });
                    Add(uiField);
                }
                Add(m_SpecificityLabel);
                SetSpecificity(specificity);
            }
            else
            {
                // StyleEnum<T>
                var type = val.GetType();
                var propInfo = type.GetProperty("value");
                Enum enumValue = propInfo.GetValue(val, null) as Enum;
                EnumField field = GetOrCreateEnumField(enumValue);
                if (!IsFocused(field))
                    field.SetValueWithoutNotify(enumValue);
            }

            SetSpecificity(specificity);
        }
        static SettingsProvider UIElementSettingsProvider()
        {
            var provider = new SettingsProvider("Project/Hierarchy", SettingsScope.Project)
            {
                label = "Hierarchy",

                activateHandler = (searchContext, rootElement) =>
                {
                    Editor editor   = Editor.CreateEditor(GetAssets());
                    var    settings = editor.target as HierarchySettings;

                    float TITLE_MARGIN_TOP    = 10;
                    float TITLE_MARGIN_BOTTOM = 4;
                    float CONTENT_MARGIN_LEFT = 10;

                    Label hierarchyTitle = new Label("Hierarchy");
                    hierarchyTitle.StyleFontSize(20);
                    hierarchyTitle.StyleMargin(10, 0, 2, 2);
                    hierarchyTitle.StyleFont(FontStyle.Bold);
                    rootElement.Add(hierarchyTitle);


                    ScrollView scrollView = new ScrollView();
                    rootElement.Add(scrollView);

                    VerticalLayout verticalLayout = new VerticalLayout();
                    verticalLayout.StylePadding(8, 8, 8, 8);
                    scrollView.Add(verticalLayout);

                    Label Object = new Label("Object");
                    Object.StyleFont(FontStyle.Bold);
                    Object.StyleMargin(0, 0, TITLE_MARGIN_TOP, TITLE_MARGIN_BOTTOM);
                    verticalLayout.Add(Object);

                    Hierarchy2.Toggle displayObjectIcon = new Hierarchy2.Toggle("Display Object Icon",
                                                                                settings.displayObjectIcon,
                                                                                Justify.FlexStart,
                                                                                (evt) =>
                    {
                        settings.displayObjectIcon = evt.newValue;
                        settings.OnSettingsChanged(nameof(settings.displayObjectIcon));
                    });
                    displayObjectIcon.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                    verticalLayout.Add(displayObjectIcon);

                    Hierarchy2.Toggle displayCustomObjectIcon = new Hierarchy2.Toggle("Display Custom Icon",
                                                                                      settings.displayCustomObjectIcon,
                                                                                      Justify.FlexStart,
                                                                                      (evt) =>
                    {
                        settings.displayCustomObjectIcon = evt.newValue;
                        settings.OnSettingsChanged(nameof(settings.displayCustomObjectIcon));
                    });
                    displayCustomObjectIcon.StyleMarginLeft(CONTENT_MARGIN_LEFT * 2);
                    verticalLayout.Add(displayCustomObjectIcon);
                    displayCustomObjectIcon.StyleDisplay(settings.displayObjectIcon);
                    displayObjectIcon.RegisterValueChangedCallback((evt) =>
                    {
                        displayCustomObjectIcon.StyleDisplay(evt.newValue);
                    });

                    Hierarchy2.Toggle displayDirtyTrack = new Hierarchy2.Toggle("Display Dirty Track [EXPERIMENTAL]",
                                                                                settings.displayDirtyTrack,
                                                                                Justify.FlexStart,
                                                                                (evt) =>
                    {
                        settings.displayDirtyTrack = evt.newValue;
                        settings.OnSettingsChanged(nameof(settings.displayDirtyTrack));
                    });
                    displayDirtyTrack.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                    verticalLayout.Add(displayDirtyTrack);

                    Label View = new Label("View");
                    View.StyleFont(FontStyle.Bold);
                    View.StyleMargin(0, 0, TITLE_MARGIN_TOP, TITLE_MARGIN_BOTTOM);
                    verticalLayout.Add(View);

                    Hierarchy2.Toggle displayRowBackground = new Hierarchy2.Toggle("Display RowBackground",
                                                                                   settings.displayRowBackground,
                                                                                   Justify.FlexStart,
                                                                                   (evt) =>
                    {
                        settings.displayRowBackground = evt.newValue;
                        settings.OnSettingsChanged(nameof(settings.displayRowBackground));
                    });
                    displayRowBackground.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                    verticalLayout.Add(displayRowBackground);

                    Hierarchy2.Toggle displayTreeView = new Hierarchy2.Toggle("Display TreeView",
                                                                              settings.displayTreeView,
                                                                              Justify.FlexStart,
                                                                              (evt) =>
                    {
                        settings.displayTreeView = evt.newValue;
                        settings.OnSettingsChanged(nameof(settings.displayTreeView));
                    });
                    displayTreeView.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                    verticalLayout.Add(displayTreeView);

                    Hierarchy2.Toggle displayGrid = new Hierarchy2.Toggle("Display Grid",
                                                                          settings.displayGrid,
                                                                          Justify.FlexStart,
                                                                          (evt) =>
                    {
                        settings.displayGrid = evt.newValue;
                        settings.OnSettingsChanged(nameof(settings.displayGrid));
                    });
                    displayGrid.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                    verticalLayout.Add(displayGrid);

                    Label Components = new Label("Components");
                    Components.StyleFont(FontStyle.Bold);
                    Components.StyleMargin(0, 0, TITLE_MARGIN_TOP, TITLE_MARGIN_BOTTOM);
                    verticalLayout.Add(Components);

                    Hierarchy2.Toggle displayComponents = new Hierarchy2.Toggle("Display Components Icon",
                                                                                settings.displayComponents,
                                                                                Justify.FlexStart,
                                                                                (evt) =>
                    {
                        settings.displayComponents = evt.newValue;
                        settings.OnSettingsChanged(nameof(settings.displayComponents));
                    });
                    displayComponents.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                    verticalLayout.Add(displayComponents);

                    EnumField componentAlignment = new EnumField(settings.componentAlignment);
                    componentAlignment.label = "Component Alignment";
                    componentAlignment.RegisterValueChangedCallback((evt) =>
                    {
                        settings.componentAlignment = (ElementAlignment)evt.newValue;
                        settings.OnSettingsChanged(nameof(settings.componentAlignment));
                    });
                    componentAlignment.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                    verticalLayout.Add(componentAlignment);

                    EnumField componentDisplayMode = new EnumField(settings.componentDisplayMode);
                    componentDisplayMode.label = "Component Display Mode";
                    componentDisplayMode.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                    verticalLayout.Add(componentDisplayMode);

                    TextField componentListInput = new TextField();
                    componentListInput.value = string.Join(" ", settings.components);
                    componentListInput.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                    verticalLayout.Add(componentListInput);
                    componentListInput.RegisterValueChangedCallback((evt) =>
                    {
                        settings.components = evt.newValue.Split(' ');
                        settings.OnSettingsChanged(nameof(settings.components));
                    });
                    componentDisplayMode.RegisterValueChangedCallback((evt) =>
                    {
                        settings.componentDisplayMode = (ComponentDisplayMode)evt.newValue;
                        switch (settings.componentDisplayMode)
                        {
                        case ComponentDisplayMode.Below:
                            componentListInput.StyleDisplay(true);
                            break;

                        case ComponentDisplayMode.Ignore:
                            componentListInput.StyleDisplay(true);
                            break;

                        case ComponentDisplayMode.All:
                            componentListInput.StyleDisplay(false);
                            break;

                        case ComponentDisplayMode.ScriptOnly:
                            componentListInput.StyleDisplay(false);
                            break;
                        }

                        settings.OnSettingsChanged(nameof(settings.componentDisplayMode));
                    });

                    var componentSizeEnum = ComponentSize.Normal;
                    switch (settings.componentSize)
                    {
                    case 12:
                        componentSizeEnum = ComponentSize.Small;
                        break;

                    case 14:
                        componentSizeEnum = ComponentSize.Normal;
                        break;

                    case 16:
                        componentSizeEnum = ComponentSize.Large;
                        break;
                    }

                    EnumField componentSize = new EnumField(componentSizeEnum);
                    componentSize.label = "Component Size";
                    componentSize.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                    componentSize.RegisterValueChangedCallback((evt) =>
                    {
                        switch (evt.newValue)
                        {
                        case ComponentSize.Small:
                            settings.componentSize = 12;
                            break;

                        case ComponentSize.Normal:
                            settings.componentSize = 14;
                            break;

                        case ComponentSize.Large:
                            settings.componentSize = 16;
                            break;
                        }

                        settings.OnSettingsChanged(nameof(settings.componentSize));
                    });
                    verticalLayout.Add(componentSize);

                    IntegerField componentSpacing = new IntegerField();
                    componentSpacing.label = "Component Spacing";
                    componentSpacing.value = settings.componentSpacing;
                    componentSpacing.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                    componentSpacing.RegisterValueChangedCallback((evt) =>
                    {
                        settings.componentSpacing = evt.newValue;
                        settings.OnSettingsChanged(nameof(settings.componentSpacing));
                    });
                    verticalLayout.Add(componentSpacing);

                    Label TagAndLayer = new Label("Tag And Layer");
                    TagAndLayer.StyleFont(FontStyle.Bold);
                    TagAndLayer.StyleMargin(0, 0, TITLE_MARGIN_TOP, TITLE_MARGIN_BOTTOM);
                    verticalLayout.Add(TagAndLayer);

                    Hierarchy2.Toggle displayTag = new Hierarchy2.Toggle("Display Tag",
                                                                         settings.displayTag,
                                                                         Justify.FlexStart,
                                                                         (evt) =>
                    {
                        settings.displayTag = evt.newValue;
                        settings.OnSettingsChanged(nameof(settings.displayTag));
                    });
                    displayTag.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                    verticalLayout.Add(displayTag);

                    Hierarchy2.Toggle applyTagTargetAndChild = new Hierarchy2.Toggle(
                        "Apply Child Tag When Parent Tag Change",
                        settings.applyTagTargetAndChild,
                        Justify.FlexStart,
                        (evt) =>
                    {
                        settings.applyTagTargetAndChild = evt.newValue;
                        settings.OnSettingsChanged(nameof(settings.applyTagTargetAndChild));
                    });
                    applyTagTargetAndChild.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                    verticalLayout.Add(applyTagTargetAndChild);

                    EnumField tagAlignment = new EnumField(settings.tagAlignment);
                    tagAlignment.label = "Tag Alignment";
                    tagAlignment.RegisterValueChangedCallback((evt) =>
                    {
                        settings.tagAlignment = (ElementAlignment)evt.newValue;
                        settings.OnSettingsChanged(nameof(settings.tagAlignment));
                    });
                    tagAlignment.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                    verticalLayout.Add(tagAlignment);

                    Hierarchy2.Toggle displayLayer = new Hierarchy2.Toggle("Display Layer",
                                                                           settings.displayLayer,
                                                                           Justify.FlexStart,
                                                                           (evt) =>
                    {
                        settings.displayLayer = evt.newValue;
                        settings.OnSettingsChanged(nameof(settings.displayLayer));
                    });
                    displayLayer.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                    verticalLayout.Add(displayLayer);

                    Hierarchy2.Toggle applyLayerTargetAndChild = new Hierarchy2.Toggle(
                        "Apply Child Layer When Parent Layer Change",
                        settings.applyLayerTargetAndChild,
                        Justify.FlexStart,
                        (evt) =>
                    {
                        settings.applyLayerTargetAndChild = evt.newValue;
                        settings.OnSettingsChanged(nameof(settings.applyLayerTargetAndChild));
                    });
                    applyLayerTargetAndChild.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                    verticalLayout.Add(applyLayerTargetAndChild);

                    EnumField layerAlignment = new EnumField(settings.layerAlignment);
                    layerAlignment.label = "Layer Alignment";
                    layerAlignment.RegisterValueChangedCallback((evt) =>
                    {
                        settings.layerAlignment = (ElementAlignment)evt.newValue;
                        settings.OnSettingsChanged(nameof(settings.layerAlignment));
                    });
                    layerAlignment.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                    verticalLayout.Add(layerAlignment);

                    Label advanced = new Label("Advanced");
                    advanced.StyleFont(FontStyle.Bold);
                    advanced.StyleMargin(0, 0, TITLE_MARGIN_TOP, TITLE_MARGIN_BOTTOM);
                    verticalLayout.Add(advanced);

                    Hierarchy2.Toggle onlyDisplayWhileMouseHovering = new Hierarchy2.Toggle(
                        "Only Display While Mouse Hovering",
                        settings.onlyDisplayWhileMouseEnter,
                        Justify.FlexStart,
                        (evt) =>
                    {
                        settings.onlyDisplayWhileMouseEnter = evt.newValue;
                        settings.OnSettingsChanged(nameof(settings.onlyDisplayWhileMouseEnter));
                    });
                    onlyDisplayWhileMouseHovering.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                    verticalLayout.Add(onlyDisplayWhileMouseHovering);

                    EnumFlagsField contentMaskEnumFlags = new EnumFlagsField(settings.contentDisplay);
                    contentMaskEnumFlags.StyleDisplay(onlyDisplayWhileMouseHovering.value);
                    contentMaskEnumFlags.label = "Content Mask";
                    onlyDisplayWhileMouseHovering.RegisterValueChangedCallback((evt) =>
                    {
                        contentMaskEnumFlags.StyleDisplay(evt.newValue);
                    });
                    contentMaskEnumFlags.RegisterValueChangedCallback((evt) =>
                    {
                        settings.contentDisplay = (ContentDisplay)evt.newValue;
                        settings.OnSettingsChanged(nameof(settings.contentDisplay));
                    });
                    verticalLayout.Add(contentMaskEnumFlags);

                    Label Theme = new Label("Theme");
                    Theme.StyleFont(FontStyle.Bold);
                    Theme.StyleMargin(0, 0, TITLE_MARGIN_TOP, TITLE_MARGIN_BOTTOM);
                    verticalLayout.Add(Theme);

                    if (EditorApplication.isPlayingOrWillChangePlaymode)
                    {
                        EditorHelpBox themeWarningPlaymode =
                            new EditorHelpBox("This setting only available on edit mode.", MessageType.Info);
                        verticalLayout.Add(themeWarningPlaymode);
                    }
                    else
                    {
                        EditorHelpBox selectionColorHelpBox = new EditorHelpBox(
                            "Theme selection color require editor assembly recompile to take affect.\nBy selecting any script, right click -> Reimport. it will force the editor to recompile.",
                            MessageType.Info);
                        selectionColorHelpBox.StyleDisplay(false);
                        verticalLayout.Add(selectionColorHelpBox);

                        ColorField colorRowEven = new ColorField("Row Even");
                        colorRowEven.value = settings.usedTheme.colorRowEven;
                        colorRowEven.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                        colorRowEven.RegisterValueChangedCallback((evt) =>
                        {
                            if (EditorGUIUtility.isProSkin)
                            {
                                settings.professionalTheme.colorRowEven = evt.newValue;
                            }
                            else
                            {
                                settings.personalTheme.colorRowEven = evt.newValue;
                            }

                            settings.OnSettingsChanged();
                        });
                        verticalLayout.Add(colorRowEven);

                        ColorField colorRowOdd = new ColorField("Row Odd");
                        colorRowOdd.value = settings.usedTheme.colorRowOdd;
                        colorRowOdd.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                        colorRowOdd.RegisterValueChangedCallback((evt) =>
                        {
                            if (EditorGUIUtility.isProSkin)
                            {
                                settings.professionalTheme.colorRowOdd = evt.newValue;
                            }
                            else
                            {
                                settings.personalTheme.colorRowOdd = evt.newValue;
                            }

                            settings.OnSettingsChanged();
                        });
                        verticalLayout.Add(colorRowOdd);

                        ColorField colorGrid = new ColorField("Grid Color");
                        colorGrid.value = settings.usedTheme.colorGrid;
                        colorGrid.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                        colorGrid.RegisterValueChangedCallback((evt) =>
                        {
                            if (EditorGUIUtility.isProSkin)
                            {
                                settings.professionalTheme.colorGrid = evt.newValue;
                            }
                            else
                            {
                                settings.personalTheme.colorGrid = evt.newValue;
                            }

                            settings.OnSettingsChanged();
                        });
                        verticalLayout.Add(colorGrid);

                        ColorField colorTreeView = new ColorField("TreeView");
                        colorTreeView.value = settings.usedTheme.colorTreeView;
                        colorTreeView.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                        colorTreeView.RegisterValueChangedCallback((evt) =>
                        {
                            if (EditorGUIUtility.isProSkin)
                            {
                                settings.professionalTheme.colorTreeView = evt.newValue;
                            }
                            else
                            {
                                settings.personalTheme.colorTreeView = evt.newValue;
                            }

                            settings.OnSettingsChanged();
                        });
                        verticalLayout.Add(colorTreeView);

                        ColorField colorLockIcon = new ColorField("Lock Icon");
                        colorLockIcon.value = settings.usedTheme.colorLockIcon;
                        colorLockIcon.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                        colorLockIcon.RegisterValueChangedCallback((evt) =>
                        {
                            if (EditorGUIUtility.isProSkin)
                            {
                                settings.professionalTheme.colorLockIcon = evt.newValue;
                            }
                            else
                            {
                                settings.personalTheme.colorLockIcon = evt.newValue;
                            }

                            settings.OnSettingsChanged();
                        });
                        verticalLayout.Add(colorLockIcon);

                        ColorField tagColor = new ColorField("Tag Text");
                        tagColor.value = settings.usedTheme.tagColor;
                        tagColor.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                        tagColor.RegisterValueChangedCallback((evt) =>
                        {
                            if (EditorGUIUtility.isProSkin)
                            {
                                settings.professionalTheme.tagColor = evt.newValue;
                            }
                            else
                            {
                                settings.personalTheme.tagColor = evt.newValue;
                            }

                            settings.OnSettingsChanged();
                        });
                        verticalLayout.Add(tagColor);

                        ColorField layerColor = new ColorField("Layer Text");
                        layerColor.value = settings.usedTheme.layerColor;
                        layerColor.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                        layerColor.RegisterValueChangedCallback((evt) =>
                        {
                            if (EditorGUIUtility.isProSkin)
                            {
                                settings.professionalTheme.layerColor = evt.newValue;
                            }
                            else
                            {
                                settings.personalTheme.layerColor = evt.newValue;
                            }

                            settings.OnSettingsChanged();
                        });
                        verticalLayout.Add(layerColor);

                        ColorField colorHeaderTitle = new ColorField("Header Title");
                        colorHeaderTitle.value = settings.usedTheme.colorHeaderTitle;
                        colorHeaderTitle.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                        colorHeaderTitle.RegisterValueChangedCallback((evt) =>
                        {
                            if (EditorGUIUtility.isProSkin)
                            {
                                settings.professionalTheme.colorHeaderTitle = evt.newValue;
                            }
                            else
                            {
                                settings.personalTheme.colorHeaderTitle = evt.newValue;
                            }

                            settings.OnSettingsChanged();
                        });
                        verticalLayout.Add(colorHeaderTitle);

                        ColorField colorHeaderBackground = new ColorField("Header Background");
                        colorHeaderBackground.value = settings.usedTheme.colorHeaderBackground;
                        colorHeaderBackground.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                        colorHeaderBackground.RegisterValueChangedCallback((evt) =>
                        {
                            if (EditorGUIUtility.isProSkin)
                            {
                                settings.professionalTheme.colorHeaderBackground = evt.newValue;
                            }
                            else
                            {
                                settings.personalTheme.colorHeaderBackground = evt.newValue;
                            }

                            settings.OnSettingsChanged();
                        });
                        verticalLayout.Add(colorHeaderBackground);

                        ColorField comSelBGColor = new ColorField("Component Selection");
                        comSelBGColor.value = settings.usedTheme.comSelBGColor;
                        comSelBGColor.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                        comSelBGColor.RegisterValueChangedCallback((evt) =>
                        {
                            if (EditorGUIUtility.isProSkin)
                            {
                                settings.professionalTheme.comSelBGColor = evt.newValue;
                            }
                            else
                            {
                                settings.personalTheme.comSelBGColor = evt.newValue;
                            }

                            settings.OnSettingsChanged();
                        });
                        verticalLayout.Add(comSelBGColor);

                        // ColorField selectionColor = new ColorField("Selection");
                        // selectionColor.value = settings.usedTheme.selectionColor;
                        // selectionColor.StyleMarginLeft(CONTENT_MARGIN_LEFT);
                        // selectionColor.RegisterValueChangedCallback((evt) =>
                        // {
                        //     if (EditorGUIUtility.isProSkin)
                        //         settings.professionalTheme.selectionColor = evt.newValue;
                        //     else
                        //         settings.personalTheme.selectionColor = evt.newValue;
                        //
                        //     selectionColorHelpBox.StyleDisplay(true);
                        //     settings.OnSettingsChanged();
                        // });
                        // verticalLayout.Add(selectionColor);
                    }
                },

                keywords = new HashSet <string>(new[] { "Hierarchy" })
            };

            return(provider);
        }
        private void RefreshUI()
        {
            rootVisualElement.Clear();

            VisualElement topRowElement = new VisualElement();

            topRowElement.AddToClassList("svbm-row");
            rootVisualElement.Add(topRowElement);

            Button refreshButton = new Button(RefreshUI)
            {
                name = "Refresh", text = "Refresh"
            };

            refreshButton.AddToClassList("svbm-cell");
            topRowElement.Add(refreshButton);

            Button saveButton = new Button(() => Bookmarks.Instance?.SaveToJson(Bookmarks.path))
            {
                name = "Save", text = "Save"
            };

            saveButton.AddToClassList("svbm-cell");
            topRowElement.Add(saveButton);

            IMGUIContainer header = new IMGUIContainer(OnCustomGUI);

            header.AddToClassList("sceneLightingButton");
            rootVisualElement.Add(header);

            if (Bookmarks.Count == 0)
            {
                return;
            }


            for (int i = 0; i < Bookmarks.Count; i++)
            {
                var index = i;

                VisualElement bookmarkElement = new VisualElement();
                bookmarkElement.AddToClassList("svbm-row");

                Button loadButton = new Button(() => Bookmarks.Instance[index].Load(SceneView.lastActiveSceneView))
                {
                    name = "LOAD", text = "LOAD"
                };
                loadButton.AddToClassList("svbm-cell-button");
                bookmarkElement.Add(loadButton);

                Button updateButton = new Button(() => Bookmarks.Instance[index].Save(SceneView.lastActiveSceneView))
                {
                    name = "UPDATE", text = "UPDATE"
                };
                updateButton.AddToClassList("svbm-cell-button");
                bookmarkElement.Add(updateButton);

                Button deleteButton = new Button(() =>
                {
                    Bookmarks.Instance.viewpoints.RemoveAt(index);
                    RefreshUI();
                })
                {
                    name = "DELETE", text = "DELETE"
                };
                deleteButton.AddToClassList("svbm-cell-button");
                bookmarkElement.Add(deleteButton);

                TextField nameField = new TextField("")
                {
                    tooltip = "Set this bookmark's menu path / name.\nUse '/' to create a submenu."
                };
                nameField.value = Bookmarks.Instance[index].name;
                nameField.AddToClassList("svbm-cell-text");
                nameField.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].name = x.newValue);
                bookmarkElement.Add(nameField);

                MaskField overridesMask = new MaskField(Enum.GetNames(typeof(Viewpoint.Overrides)).ToList(), (int)Bookmarks.Instance[index].overrides)
                {
                    tooltip = "Set this bookmark's Overrides."
                };
                overridesMask.AddToClassList("svbm-cell-mask");
                overridesMask.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].overrides = (Viewpoint.Overrides)x.newValue);
                bookmarkElement.Add(overridesMask);

                Toggle orthoToggle = new Toggle("")
                {
                    tooltip = "Enable to set this bookmark's SceneView to Orthographic."
                };
                orthoToggle.value = Bookmarks.Instance[index].settings.ortho;
                orthoToggle.AddToClassList("svbm-cell-checkbox");
                orthoToggle.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].settings.ortho = x.newValue);
                bookmarkElement.Add(orthoToggle);

                Toggle is2dToggle = new Toggle("")
                {
                    tooltip = "Enable to set this bookmark's SceneView to 2D Mode."
                };
                is2dToggle.value = Bookmarks.Instance[index].settings.is2D;
                is2dToggle.AddToClassList("svbm-cell-checkbox");
                is2dToggle.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].settings.is2D = x.newValue);
                bookmarkElement.Add(is2dToggle);

                FloatField fovField = new FloatField()
                {
                    tooltip = "Set this bookmark's Camera Field of View."
                };
                fovField.value = Bookmarks.Instance[index].settings.fov;
                fovField.AddToClassList("svbm-cell-float");
                fovField.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].settings.fov = Mathf.Clamp(x.newValue, 4, 120));
                bookmarkElement.Add(fovField);

                EnumField cameraModeMask = new EnumField("", Bookmarks.Instance[index].settings.mode.drawMode)
                {
                    tooltip = "Set this bookmark's Camera Shading Mode."
                };
                cameraModeMask.AddToClassList("svbm-cell-mask");
                // Catching cases where SceneView.GetBuiltinCameraMode() will fail on some DrawCameraMode such as Normal and User Defined
                cameraModeMask.RegisterValueChangedCallback((x) => {
                    try
                    {
                        Bookmarks.Instance[index].settings.mode = SceneView.GetBuiltinCameraMode((DrawCameraMode)x.newValue);
                    }
                    catch
                    {
                        cameraModeMask.SetValueWithoutNotify(x.previousValue);
                    }
                });
                bookmarkElement.Add(cameraModeMask);

                Toggle lightingToggle = new Toggle("")
                {
                    tooltip = "Enable this bookmark's SceneView Lighting."
                };
                lightingToggle.value = Bookmarks.Instance[index].settings.sceneLighting;
                lightingToggle.AddToClassList("svbm-cell-checkbox");
                lightingToggle.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].settings.sceneLighting = x.newValue);
                bookmarkElement.Add(lightingToggle);

                MaskField viewStatesMask = new MaskField(SceneViewStatesLabels, (int)Bookmarks.Instance[index].settings.sceneViewState.GetFlags())
                {
                    tooltip = "Set this bookmark's SceneView States."
                };
                viewStatesMask.AddToClassList("svbm-cell-mask");
                viewStatesMask.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].settings.sceneViewState.SetFlags((SceneViewExtensions.SceneViewStateFlags)x.newValue));
                bookmarkElement.Add(viewStatesMask);

                Toggle gridToggle = new Toggle("")
                {
                    tooltip = "Enable this bookmark's SceneView Grid."
                };
                gridToggle.value = Bookmarks.Instance[index].settings.showGrid;
                gridToggle.AddToClassList("svbm-cell-checkbox");
                gridToggle.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].settings.showGrid = x.newValue);
                bookmarkElement.Add(gridToggle);

                Toggle gizmosToggle = new Toggle("")
                {
                    tooltip = "Enable this bookmark's SceneView Gizmos."
                };
                gizmosToggle.value = Bookmarks.Instance[index].settings.drawGizmos;
                gizmosToggle.AddToClassList("svbm-cell-checkbox");
                gizmosToggle.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].settings.drawGizmos = x.newValue);
                bookmarkElement.Add(gizmosToggle);

                LayerMaskField visibleLayerMask = new LayerMaskField("", Bookmarks.Instance[index].visibleLayers)
                {
                    tooltip = "Set this bookmark's Visible Layers."
                };
                visibleLayerMask.AddToClassList("svbm-cell-mask");
                visibleLayerMask.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].visibleLayers = x.newValue);
                bookmarkElement.Add(visibleLayerMask);

                LayerMaskField lockedLayerMask = new LayerMaskField("", Bookmarks.Instance[index].lockedLayers)
                {
                    tooltip = "Set this bookmark's Locked Layers."
                };
                lockedLayerMask.AddToClassList("svbm-cell-mask");
                lockedLayerMask.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].lockedLayers = x.newValue);
                bookmarkElement.Add(lockedLayerMask);

                EnumField shortcutMask = new EnumField("", Bookmarks.Instance[index].shortcut)
                {
                    tooltip = "Set this bookmark's shortcut\nBeware this will override any other function the shortcut is associated with."
                };
                shortcutMask.AddToClassList("svbm-cell-mask");
                shortcutMask.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].shortcut = (KeyCode)x.newValue);
                bookmarkElement.Add(shortcutMask);

                Button moveUpButton = new Button(() =>
                {
                    if (index <= 0)
                    {
                        return;
                    }

                    var item = Bookmarks.Instance.viewpoints[index];
                    Bookmarks.Instance.viewpoints.RemoveAt(index);

                    Bookmarks.Instance.viewpoints.Insert(index - 1, item);
                    RefreshUI();
                })
                {
                    name = "Up", text = "Up"
                };
                moveUpButton.AddToClassList("svbm-cell-button");
                bookmarkElement.Add(moveUpButton);

                Button moveDownButton = new Button(() =>
                {
                    if (index >= Bookmarks.Instance.viewpoints.Count - 1)
                    {
                        return;
                    }

                    var item = Bookmarks.Instance.viewpoints[index];
                    Bookmarks.Instance.viewpoints.RemoveAt(index);

                    Bookmarks.Instance.viewpoints.Insert(index + 1, item);
                    RefreshUI();
                })
                {
                    name = "Down", text = "Dn"
                };
                moveDownButton.AddToClassList("svbm-cell-button");
                bookmarkElement.Add(moveDownButton);

                rootVisualElement.Add(bookmarkElement);
            }
        }
Beispiel #25
0
        private void Draw(CustomFunctionNode node)
        {
            var currentControls = this.Children().ToArray();

            for (int i = 0; i < currentControls.Length; i++)
            {
                currentControls[i].RemoveFromHierarchy();
            }

            m_Type = new EnumField(node.sourceType);
            m_Type.RegisterValueChangedCallback(s =>
            {
                if ((HlslSourceType)s.newValue != node.sourceType)
                {
                    node.owner.owner.RegisterCompleteObjectUndo("Change Function Type");
                    node.sourceType = (HlslSourceType)s.newValue;
                    Draw(node);
                    node.ValidateNode();
                    node.Dirty(ModificationScope.Graph);
                }
            });

            m_FunctionName = new TextField {
                value = node.functionName, multiline = false
            };
            m_FunctionName.RegisterCallback <FocusInEvent>(s =>
            {
                if (m_FunctionName.value == CustomFunctionNode.defaultFunctionName)
                {
                    m_FunctionName.value = "";
                }
            });
            m_FunctionName.RegisterCallback <FocusOutEvent>(s =>
            {
                if (m_FunctionName.value == "")
                {
                    m_FunctionName.value = CustomFunctionNode.defaultFunctionName;
                }
                else
                {
                    m_FunctionName.value = NodeUtils.ConvertToValidHLSLIdentifier(m_FunctionName.value);
                }

                if (m_FunctionName.value != node.functionName)
                {
                    node.owner.owner.RegisterCompleteObjectUndo("Change Function Name");
                    node.functionName = m_FunctionName.value;
                    node.ValidateNode();
                    node.Dirty(ModificationScope.Graph);
                }
            });

            string path = AssetDatabase.GUIDToAssetPath(node.functionSource);

            m_FunctionSource = new ObjectField()
            {
                value = AssetDatabase.LoadAssetAtPath <ShaderInclude>(path), objectType = typeof(ShaderInclude)
            };
            m_FunctionSource.RegisterValueChangedCallback(s =>
            {
                long localId;
                string guidString = string.Empty;
                if (s.newValue != null)
                {
                    AssetDatabase.TryGetGUIDAndLocalFileIdentifier((ShaderInclude)s.newValue, out guidString, out localId);
                }

                if (guidString != node.functionSource)
                {
                    node.owner.owner.RegisterCompleteObjectUndo("Change Function Source");
                    node.functionSource = guidString;
                    node.ValidateNode();
                    node.Dirty(ModificationScope.Graph);
                }
            });

            m_FunctionBody = new TextField {
                value = node.functionBody, multiline = true
            };
            m_FunctionBody.RegisterCallback <FocusInEvent>(s =>
            {
                if (m_FunctionBody.value == CustomFunctionNode.defaultFunctionBody)
                {
                    m_FunctionBody.value = "";
                }
            });
            m_FunctionBody.RegisterCallback <FocusOutEvent>(s =>
            {
                if (m_FunctionBody.value == "")
                {
                    m_FunctionBody.value = CustomFunctionNode.defaultFunctionBody;
                }

                if (m_FunctionBody.value != node.functionBody)
                {
                    node.owner.owner.RegisterCompleteObjectUndo("Change Function Body");
                    node.functionBody = m_FunctionBody.value;
                    node.ValidateNode();
                    node.Dirty(ModificationScope.Graph);
                }
            });

            VisualElement typeRow = new VisualElement()
            {
                name = "Row"
            };

            {
                typeRow.Add(new Label("Type"));
                typeRow.Add(m_Type);
            }
            Add(typeRow);
            VisualElement nameRow = new VisualElement()
            {
                name = "Row"
            };

            {
                nameRow.Add(new Label("Name"));
                nameRow.Add(m_FunctionName);
            }
            Add(nameRow);
            switch (node.sourceType)
            {
            case HlslSourceType.File:
                VisualElement sourceRow = new VisualElement()
                {
                    name = "Row"
                };
                {
                    sourceRow.Add(new Label("Source"));
                    sourceRow.Add(m_FunctionSource);
                }
                Add(sourceRow);
                break;

            case HlslSourceType.String:
                VisualElement bodyRow = new VisualElement()
                {
                    name = "Row"
                };
                {
                    bodyRow.Add(new Label("Body"));
                    bodyRow.style.height = 200;
                    bodyRow.Add(m_FunctionBody);
                }
                Add(bodyRow);
                break;
            }
        }
Beispiel #26
0
        public override void BuildCustomFields(ShaderInput input)
        {
            AbstractShaderProperty property = input as AbstractShaderProperty;

            if (property == null)
            {
                return;
            }

            switch (input)
            {
            case Vector1ShaderProperty vector1Property:
                BuildVector1PropertyField(vector1Property);
                break;

            case Vector2ShaderProperty vector2Property:
                BuildVector2PropertyField(vector2Property);
                break;

            case Vector3ShaderProperty vector3Property:
                BuildVector3PropertyField(vector3Property);
                break;

            case Vector4ShaderProperty vector4Property:
                BuildVector4PropertyField(vector4Property);
                break;

            case ColorShaderProperty colorProperty:
                BuildColorPropertyField(colorProperty);
                break;

            case TextureShaderProperty texture2DProperty:
                BuildTexture2DPropertyField(texture2DProperty);
                break;

            case Texture2DArrayShaderProperty texture2DArrayProperty:
                BuildTexture2DArrayPropertyField(texture2DArrayProperty);
                break;

            case Texture3DShaderProperty texture3DProperty:
                BuildTexture3DPropertyField(texture3DProperty);
                break;

            case CubemapShaderProperty cubemapProperty:
                BuildCubemapPropertyField(cubemapProperty);
                break;

            case BooleanShaderProperty booleanProperty:
                BuildBooleanPropertyField(booleanProperty);
                break;

            case Matrix2ShaderProperty matrix2Property:
                BuildMatrix2PropertyField(matrix2Property);
                break;

            case Matrix3ShaderProperty matrix3Property:
                BuildMatrix3PropertyField(matrix3Property);
                break;

            case Matrix4ShaderProperty matrix4Property:
                BuildMatrix4PropertyField(matrix4Property);
                break;

            case SamplerStateShaderProperty samplerStateProperty:
                BuildSamplerStatePropertyField(samplerStateProperty);
                break;

            case GradientShaderProperty gradientProperty:
                BuildGradientPropertyField(gradientProperty);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            // Precision
            var precisionField = new EnumField((Enum)property.precision);

            precisionField.RegisterValueChangedCallback(evt =>
            {
                graph.owner.RegisterCompleteObjectUndo("Change Precision");
                if (property.precision == (Precision)evt.newValue)
                {
                    return;
                }

                property.precision = (Precision)evt.newValue;
                graph.ValidateGraph();
                precisionField.MarkDirtyRepaint();
                DirtyNodes();
            });
            AddRow("Precision", precisionField);
            if (property.isGpuInstanceable)
            {
                Toggle gpuInstancedToogle = new Toggle {
                    value = property.gpuInstanced
                };
                gpuInstancedToogle.OnToggleChanged(evt =>
                {
                    graph.owner.RegisterCompleteObjectUndo("Change Hybrid Instanced Toggle");
                    property.gpuInstanced = evt.newValue;
                    DirtyNodes(ModificationScope.Graph);
                });
                AddRow("Hybrid Instanced (experimental)", gpuInstancedToogle);
            }
        }
        public BlackboardFieldPropertyView(BlackboardField blackboardField, GraphData graph, AbstractShaderProperty property)
        {
            styleSheets.Add(Resources.Load <StyleSheet>("Styles/ShaderGraphBlackboard"));
            m_BlackboardField = blackboardField;
            m_Graph           = graph;
            m_Property        = property;

            if (!m_Graph.isSubGraph)
            {
                if (property.isExposable)
                {
                    m_ExposedToogle = new Toggle();
                    m_ExposedToogle.OnToggleChanged(evt =>
                    {
                        m_Graph.owner.RegisterCompleteObjectUndo("Change Exposed Toggle");
                        if (m_OnExposedToggle != null)
                        {
                            m_OnExposedToggle();
                        }
                        property.generatePropertyBlock = evt.newValue;
                        if (property.generatePropertyBlock)
                        {
                            m_BlackboardField.icon = BlackboardProvider.exposedIcon;
                        }
                        else
                        {
                            m_BlackboardField.icon = null;
                        }
                        DirtyNodes(ModificationScope.Graph);
                    });
                    m_ExposedToogle.value = property.generatePropertyBlock;
                    AddRow("Exposed", m_ExposedToogle);
                }

                m_ReferenceNameField = new TextField(512, false, false, ' ');
                m_ReferenceNameField.styleSheets.Add(Resources.Load <StyleSheet>("Styles/PropertyNameReferenceField"));
                AddRow("Reference", m_ReferenceNameField);
                m_ReferenceNameField.value     = property.referenceName;
                m_ReferenceNameField.isDelayed = true;
                m_ReferenceNameField.RegisterValueChangedCallback(newName =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Reference Name");
                    if (m_ReferenceNameField.value != m_Property.referenceName)
                    {
                        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");
                }
            }

            // Key Undo callbacks for input fields
            EventCallback <KeyDownEvent> keyDownCallback = new EventCallback <KeyDownEvent>(evt =>
            {
                // Record Undo for input field edit
                if (m_UndoGroup == -1)
                {
                    m_UndoGroup = Undo.GetCurrentGroup();
                    m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                }
                // 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();
            });
            EventCallback <FocusOutEvent> focusOutCallback = new EventCallback <FocusOutEvent>(evt =>
            {
                // Reset UndoGroup when done editing input field
                m_UndoGroup = -1;
            });

            if (property is Vector1ShaderProperty)
            {
                var floatProperty = (Vector1ShaderProperty)property;
                BuildVector1PropertyView(floatProperty);
            }
            else if (property is Vector2ShaderProperty)
            {
                var vectorProperty = (Vector2ShaderProperty)property;
                var field          = new Vector2Field {
                    value = vectorProperty.value
                };

                field.Q("unity-x-input").Q("unity-text-input").RegisterCallback <KeyDownEvent>(keyDownCallback);
                field.Q("unity-x-input").Q("unity-text-input").RegisterCallback <FocusOutEvent>(focusOutCallback);
                field.Q("unity-y-input").Q("unity-text-input").RegisterCallback <KeyDownEvent>(keyDownCallback);
                field.Q("unity-y-input").Q("unity-text-input").RegisterCallback <FocusOutEvent>(focusOutCallback);

                // Called after KeyDownEvent
                field.RegisterValueChangedCallback(evt =>
                {
                    // Only true when setting value via FieldMouseDragger
                    // Undo recorded once per dragger release
                    if (m_UndoGroup == -1)
                    {
                        m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    }
                    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.Q("unity-x-input").Q("unity-text-input").RegisterCallback <KeyDownEvent>(keyDownCallback);
                field.Q("unity-x-input").Q("unity-text-input").RegisterCallback <FocusOutEvent>(focusOutCallback);
                field.Q("unity-y-input").Q("unity-text-input").RegisterCallback <KeyDownEvent>(keyDownCallback);
                field.Q("unity-y-input").Q("unity-text-input").RegisterCallback <FocusOutEvent>(focusOutCallback);
                field.Q("unity-z-input").Q("unity-text-input").RegisterCallback <KeyDownEvent>(keyDownCallback);
                field.Q("unity-z-input").Q("unity-text-input").RegisterCallback <FocusOutEvent>(focusOutCallback);

                // Called after KeyDownEvent
                field.RegisterValueChangedCallback(evt =>
                {
                    // Only true when setting value via FieldMouseDragger
                    // Undo recorded once per dragger release
                    if (m_UndoGroup == -1)
                    {
                        m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    }
                    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.Q("unity-x-input").Q("unity-text-input").RegisterCallback <KeyDownEvent>(keyDownCallback);
                field.Q("unity-x-input").Q("unity-text-input").RegisterCallback <FocusOutEvent>(focusOutCallback);
                field.Q("unity-y-input").Q("unity-text-input").RegisterCallback <KeyDownEvent>(keyDownCallback);
                field.Q("unity-y-input").Q("unity-text-input").RegisterCallback <FocusOutEvent>(focusOutCallback);
                field.Q("unity-z-input").Q("unity-text-input").RegisterCallback <KeyDownEvent>(keyDownCallback);
                field.Q("unity-z-input").Q("unity-text-input").RegisterCallback <FocusOutEvent>(focusOutCallback);
                field.Q("unity-w-input").Q("unity-text-input").RegisterCallback <KeyDownEvent>(keyDownCallback);
                field.Q("unity-w-input").Q("unity-text-input").RegisterCallback <FocusOutEvent>(focusOutCallback);

                // Called after KeyDownEvent
                field.RegisterValueChangedCallback(evt =>
                {
                    // Only true when setting value via FieldMouseDragger
                    // Undo recorded once per dragger release
                    if (m_UndoGroup == -1)
                    {
                        m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    }
                    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.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    colorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", colorField);
                if (!m_Graph.isSubGraph)
                {
                    var colorModeField = new EnumField((Enum)colorProperty.colorMode);
                    colorModeField.RegisterValueChangedCallback(evt =>
                    {
                        m_Graph.owner.RegisterCompleteObjectUndo("Change Color Mode");
                        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.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    textureProperty.value.texture = (Texture)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
                if (!m_Graph.isSubGraph)
                {
                    var defaultModeField = new EnumField((Enum)textureProperty.defaultType);
                    defaultModeField.RegisterValueChangedCallback(evt =>
                    {
                        m_Graph.owner.RegisterCompleteObjectUndo("Change Texture Mode");
                        if (textureProperty.defaultType == (TextureShaderProperty.DefaultType)evt.newValue)
                        {
                            return;
                        }
                        textureProperty.defaultType = (TextureShaderProperty.DefaultType)evt.newValue;
                        DirtyNodes(ModificationScope.Graph);
                    });
                    void ToggleDefaultModeFieldEnabled()
                    {
                        defaultModeField.SetEnabled(!defaultModeField.enabledSelf);
                    }

                    m_OnExposedToggle += ToggleDefaultModeFieldEnabled;
                    AddRow("Mode", defaultModeField);
                }
            }
            else if (property is Texture2DArrayShaderProperty)
            {
                var textureProperty = (Texture2DArrayShaderProperty)property;
                var field           = new ObjectField {
                    value = textureProperty.value.textureArray, objectType = typeof(Texture2DArray)
                };
                field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    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.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    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.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    cubemapProperty.value.cubemap = (Cubemap)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is BooleanShaderProperty)
            {
                var booleanProperty = (BooleanShaderProperty)property;
                EventCallback <ChangeEvent <bool> > onBooleanChanged = evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    booleanProperty.value = evt.newValue;
                    DirtyNodes();
                };
                var field = new Toggle();
                field.OnToggleChanged(onBooleanChanged);
                field.value = booleanProperty.value;
                AddRow("Default", field);
            }
            else if (property is Matrix2ShaderProperty)
            {
                var matrix2Property = (Matrix2ShaderProperty)property;
                var row0Field       = new Vector2Field {
                    value = matrix2Property.value.GetRow(0)
                };
                row0Field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                    Vector2 row1          = matrix2Property.value.GetRow(1);
                    matrix2Property.value = new Matrix4x4()
                    {
                        m00 = evt.newValue.x,
                        m01 = evt.newValue.y,
                        m02 = 0,
                        m03 = 0,
                        m10 = row1.x,
                        m11 = row1.y,
                        m12 = 0,
                        m13 = 0,
                        m20 = 0,
                        m21 = 0,
                        m22 = 0,
                        m23 = 0,
                        m30 = 0,
                        m31 = 0,
                        m32 = 0,
                        m33 = 0,
                    };
                    DirtyNodes();
                });
                AddRow("Default", row0Field);
                var row1Field = new Vector2Field {
                    value = matrix2Property.value.GetRow(1)
                };
                row1Field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                    Vector2 row0          = matrix2Property.value.GetRow(0);
                    matrix2Property.value = new Matrix4x4()
                    {
                        m00 = row0.x,
                        m01 = row0.y,
                        m02 = 0,
                        m03 = 0,
                        m10 = evt.newValue.x,
                        m11 = evt.newValue.y,
                        m12 = 0,
                        m13 = 0,
                        m20 = 0,
                        m21 = 0,
                        m22 = 0,
                        m23 = 0,
                        m30 = 0,
                        m31 = 0,
                        m32 = 0,
                        m33 = 0,
                    };
                    DirtyNodes();
                });
                AddRow("", row1Field);
            }
            else if (property is Matrix3ShaderProperty)
            {
                var matrix3Property = (Matrix3ShaderProperty)property;
                var row0Field       = new Vector3Field {
                    value = matrix3Property.value.GetRow(0)
                };
                row0Field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                    Vector3 row1          = matrix3Property.value.GetRow(1);
                    Vector3 row2          = matrix3Property.value.GetRow(2);
                    matrix3Property.value = new Matrix4x4()
                    {
                        m00 = evt.newValue.x,
                        m01 = evt.newValue.y,
                        m02 = evt.newValue.z,
                        m03 = 0,
                        m10 = row1.x,
                        m11 = row1.y,
                        m12 = row1.z,
                        m13 = 0,
                        m20 = row2.x,
                        m21 = row2.y,
                        m22 = row2.z,
                        m23 = 0,
                        m30 = 0,
                        m31 = 0,
                        m32 = 0,
                        m33 = 0,
                    };
                    DirtyNodes();
                });
                AddRow("Default", row0Field);
                var row1Field = new Vector3Field {
                    value = matrix3Property.value.GetRow(1)
                };
                row1Field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                    Vector3 row0          = matrix3Property.value.GetRow(0);
                    Vector3 row2          = matrix3Property.value.GetRow(2);
                    matrix3Property.value = new Matrix4x4()
                    {
                        m00 = row0.x,
                        m01 = row0.y,
                        m02 = row0.z,
                        m03 = 0,
                        m10 = evt.newValue.x,
                        m11 = evt.newValue.y,
                        m12 = evt.newValue.z,
                        m13 = 0,
                        m20 = row2.x,
                        m21 = row2.y,
                        m22 = row2.z,
                        m23 = 0,
                        m30 = 0,
                        m31 = 0,
                        m32 = 0,
                        m33 = 0,
                    };
                    DirtyNodes();
                });
                AddRow("", row1Field);
                var row2Field = new Vector3Field {
                    value = matrix3Property.value.GetRow(2)
                };
                row2Field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                    Vector3 row0          = matrix3Property.value.GetRow(0);
                    Vector3 row1          = matrix3Property.value.GetRow(1);
                    matrix3Property.value = new Matrix4x4()
                    {
                        m00 = row0.x,
                        m01 = row0.y,
                        m02 = row0.z,
                        m03 = 0,
                        m10 = row1.x,
                        m11 = row1.y,
                        m12 = row1.z,
                        m13 = 0,
                        m20 = evt.newValue.x,
                        m21 = evt.newValue.y,
                        m22 = evt.newValue.z,
                        m23 = 0,
                        m30 = 0,
                        m31 = 0,
                        m32 = 0,
                        m33 = 0,
                    };
                    DirtyNodes();
                });
                AddRow("", row2Field);
            }
            else if (property is Matrix4ShaderProperty)
            {
                var matrix4Property = (Matrix4ShaderProperty)property;
                var row0Field       = new Vector4Field {
                    value = matrix4Property.value.GetRow(0)
                };
                row0Field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                    Vector4 row1          = matrix4Property.value.GetRow(1);
                    Vector4 row2          = matrix4Property.value.GetRow(2);
                    Vector4 row3          = matrix4Property.value.GetRow(3);
                    matrix4Property.value = new Matrix4x4()
                    {
                        m00 = evt.newValue.x,
                        m01 = evt.newValue.y,
                        m02 = evt.newValue.z,
                        m03 = evt.newValue.w,
                        m10 = row1.x,
                        m11 = row1.y,
                        m12 = row1.z,
                        m13 = row1.w,
                        m20 = row2.x,
                        m21 = row2.y,
                        m22 = row2.z,
                        m23 = row2.w,
                        m30 = row3.x,
                        m31 = row3.y,
                        m32 = row3.z,
                        m33 = row3.w,
                    };
                    DirtyNodes();
                });
                AddRow("Default", row0Field);
                var row1Field = new Vector4Field {
                    value = matrix4Property.value.GetRow(1)
                };
                row1Field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                    Vector4 row0          = matrix4Property.value.GetRow(0);
                    Vector4 row2          = matrix4Property.value.GetRow(2);
                    Vector4 row3          = matrix4Property.value.GetRow(3);
                    matrix4Property.value = new Matrix4x4()
                    {
                        m00 = row0.x,
                        m01 = row0.y,
                        m02 = row0.z,
                        m03 = row0.w,
                        m10 = evt.newValue.x,
                        m11 = evt.newValue.y,
                        m12 = evt.newValue.z,
                        m13 = evt.newValue.w,
                        m20 = row2.x,
                        m21 = row2.y,
                        m22 = row2.z,
                        m23 = row2.w,
                        m30 = row3.x,
                        m31 = row3.y,
                        m32 = row3.z,
                        m33 = row3.w,
                    };
                    DirtyNodes();
                });
                AddRow("", row1Field);
                var row2Field = new Vector4Field {
                    value = matrix4Property.value.GetRow(2)
                };
                row2Field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                    Vector4 row0          = matrix4Property.value.GetRow(0);
                    Vector4 row1          = matrix4Property.value.GetRow(1);
                    Vector4 row3          = matrix4Property.value.GetRow(3);
                    matrix4Property.value = new Matrix4x4()
                    {
                        m00 = row0.x,
                        m01 = row0.y,
                        m02 = row0.z,
                        m03 = row0.w,
                        m10 = row1.x,
                        m11 = row1.y,
                        m12 = row1.z,
                        m13 = row1.w,
                        m20 = evt.newValue.x,
                        m21 = evt.newValue.y,
                        m22 = evt.newValue.z,
                        m23 = evt.newValue.w,
                        m30 = row3.x,
                        m31 = row3.y,
                        m32 = row3.z,
                        m33 = row3.w,
                    };
                    DirtyNodes();
                });
                AddRow("", row2Field);
                var row3Field = new Vector4Field {
                    value = matrix4Property.value.GetRow(3)
                };
                row3Field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                    Vector4 row0          = matrix4Property.value.GetRow(0);
                    Vector4 row1          = matrix4Property.value.GetRow(1);
                    Vector4 row2          = matrix4Property.value.GetRow(2);
                    matrix4Property.value = new Matrix4x4()
                    {
                        m00 = row0.x,
                        m01 = row0.y,
                        m02 = row0.z,
                        m03 = row0.w,
                        m10 = row1.x,
                        m11 = row1.y,
                        m12 = row1.z,
                        m13 = row1.w,
                        m20 = row2.x,
                        m21 = row2.y,
                        m22 = row2.z,
                        m23 = row2.w,
                        m30 = evt.newValue.x,
                        m31 = evt.newValue.y,
                        m32 = evt.newValue.z,
                        m33 = evt.newValue.w,
                    };
                    DirtyNodes();
                });
                AddRow("", row3Field);
            }
            else if (property is SamplerStateShaderProperty)
            {
                var samplerStateProperty = (SamplerStateShaderProperty)property;
                var filterField          = new EnumField(samplerStateProperty.value.filter);
                filterField.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                    samplerStateProperty.value.filter = (TextureSamplerState.FilterMode)evt.newValue;
                    DirtyNodes(ModificationScope.Graph);
                });
                AddRow("Filter", filterField);
                var wrapField = new EnumField(samplerStateProperty.value.wrap);
                wrapField.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                    samplerStateProperty.value.wrap = (TextureSamplerState.WrapMode)evt.newValue;
                    DirtyNodes(ModificationScope.Graph);
                });
                AddRow("Wrap", wrapField);
            }
            else if (property is GradientShaderProperty)
            {
                var gradientProperty = (GradientShaderProperty)property;
                var field            = new GradientField {
                    value = gradientProperty.value
                };
                field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                    gradientProperty.value = evt.newValue;
                    DirtyNodes();
                });
                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();
        }
        BuilderStyleRow CreateAttributeRow(UxmlAttributeDescription attribute)
        {
            var attributeType = attribute.GetType();

            // Generate field label.
            var             fieldLabel = BuilderNameUtilities.ConvertDashToHuman(attribute.name);
            BindableElement fieldElement;

            if (attribute is UxmlStringAttributeDescription)
            {
                var uiField = new TextField(fieldLabel);
                if (attribute.name.Equals("name") || attribute.name.Equals("view-data-key"))
                {
                    uiField.RegisterValueChangedCallback(e =>
                    {
                        OnValidatedAttributeValueChange(e, BuilderNameUtilities.AttributeRegex, BuilderConstants.AttributeValidationSpacialCharacters);
                    });
                }
                else if (attribute.name.Equals("binding-path"))
                {
                    uiField.RegisterValueChangedCallback(e =>
                    {
                        OnValidatedAttributeValueChange(e, BuilderNameUtilities.BindingPathAttributeRegex, BuilderConstants.BindingPathAttributeValidationSpacialCharacters);
                    });
                }
                else
                {
                    uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                }

                if (attribute.name.Equals("text"))
                {
                    uiField.multiline = true;
                    uiField.AddToClassList(BuilderConstants.InspectorMultiLineTextFieldClassName);
                }

                fieldElement = uiField;
            }
            else if (attribute is UxmlFloatAttributeDescription)
            {
                var uiField = new FloatField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attribute is UxmlDoubleAttributeDescription)
            {
                var uiField = new DoubleField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attribute is UxmlIntAttributeDescription)
            {
                var uiField = new IntegerField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attribute is UxmlLongAttributeDescription)
            {
                var uiField = new LongField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attribute is UxmlBoolAttributeDescription)
            {
                var uiField = new Toggle(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attribute is UxmlColorAttributeDescription)
            {
                var uiField = new ColorField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attributeType.IsGenericType &&
                     !attributeType.GetGenericArguments()[0].IsEnum &&
                     attributeType.GetGenericArguments()[0] is Type)
            {
                var uiField = new TextField(fieldLabel);
                uiField.isDelayed = true;
                uiField.RegisterValueChangedCallback(e =>
                {
                    OnValidatedTypeAttributeChange(e, attributeType.GetGenericArguments()[0]);
                });
                fieldElement = uiField;
            }
            else if (attributeType.IsGenericType && attributeType.GetGenericArguments()[0].IsEnum)
            {
                var propInfo  = attributeType.GetProperty("defaultValue");
                var enumValue = propInfo.GetValue(attribute, null) as Enum;

                // Create and initialize the EnumField.
                var uiField = new EnumField(fieldLabel);
                uiField.Init(enumValue);

                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else
            {
                var uiField = new TextField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }

            // Create row.
            var styleRow = new BuilderStyleRow();

            styleRow.Add(fieldElement);

            // Link the field.
            fieldElement.SetProperty(BuilderConstants.InspectorLinkedStyleRowVEPropertyName, styleRow);
            fieldElement.SetProperty(BuilderConstants.InspectorLinkedAttributeDescriptionVEPropertyName, attribute);

            // Set initial value.
            RefreshAttributeField(fieldElement);

            // Setup field binding path.
            fieldElement.bindingPath = attribute.name;

            // Tooltip.
            var label = fieldElement.Q <Label>();

            if (label != null)
            {
                label.tooltip = attribute.name;
            }
            else
            {
                fieldElement.tooltip = attribute.name;
            }

            // Context menu.
            fieldElement.AddManipulator(new ContextualMenuManipulator(BuildAttributeFieldContextualMenu));

            return(styleRow);
        }
    private void GenerateCustomField(DrawNodeViewGraph drawNode)
    {
        var so = new SerializedObject(drawNode.InnerNode);

        if (drawNode.InnerNode != null)
        {
            foreach (var m in drawNode.InnerNode.GetType().GetMembers())
            {
                foreach (var a in m.GetCustomAttributes())
                {
                    if (a is SerializeField)
                    {
                        var field = m as FieldInfo;

                        if (field.FieldType == typeof(int))
                        {
                            var intField = new IntegerField(m.Name + ":");
                            intField.value = (int)(m as FieldInfo).GetValue(drawNode.InnerNode);

                            intField.RegisterValueChangedCallback((evt) => IntChangeReact(evt, m as FieldInfo, drawNode.InnerNode));
                            drawNode.contentContainer.Add(intField);
                        }

                        if (field.FieldType == typeof(Strategy))
                        {
                            var objectField = new ObjectField(m.Name + ":")
                            {
                                objectType = typeof(Strategy)
                            };
                            objectField.value = (m as FieldInfo).GetValue(drawNode.InnerNode) as Strategy;

                            objectField.RegisterValueChangedCallback((evt) => ChangeStrategy(evt, m as FieldInfo, drawNode.InnerNode));

                            drawNode.contentContainer.Add(objectField);
                        }

                        if (field.FieldType.BaseType == typeof(Enum))
                        {
                            var enumField = new EnumField(m.Name + ":");
                            var property  = so.FindProperty(m.Name);
                            enumField.value = (Enum)Enum.ToObject(field.FieldType, field.GetValue(drawNode.InnerNode));
                            enumField.Init((Enum)Enum.ToObject(field.FieldType, field.GetValue(drawNode.InnerNode)));

                            enumField.RegisterValueChangedCallback((evt) => EnumChangeReact(evt, field, drawNode.InnerNode));
                            drawNode.contentContainer.Add(enumField);
                        }

                        if (field.FieldType == typeof(float))
                        {
                            var floatField = new FloatField(m.Name + ":");
                            floatField.value = (float)field.GetValue(drawNode.InnerNode);
                            floatField.RegisterValueChangedCallback((evt) => FloatFieldReact(evt, field, drawNode.InnerNode));
                            drawNode.contentContainer.Add(floatField);
                        }

                        if (field.FieldType == typeof(bool))
                        {
                            var boolField = new Toggle(m.Name + ":");
                            boolField.value = (bool)field.GetValue(drawNode.InnerNode);
                            boolField.RegisterValueChangedCallback((evt) => BoolFieldReact(evt, field, drawNode.InnerNode));
                            drawNode.contentContainer.Add(boolField);
                        }

                        drawNode.RefreshPorts();
                        drawNode.RefreshExpandedState();
                    }
                }
            }
        }
    }