void BuildReferenceNameField(PropertySheet propertySheet)
        {
            if (!isSubGraph || shaderInput is ShaderKeyword)
            {
                var textPropertyDrawer = new TextPropertyDrawer();
                propertySheet.Add(textPropertyDrawer.CreateGUI(
                                      null,
                                      (string)shaderInput.referenceName,
                                      "Reference",
                                      out var propertyVisualElement));

                m_ReferenceNameField = (TextField)propertyVisualElement;
                m_ReferenceNameField.RegisterValueChangedCallback(
                    evt =>
                {
                    this._preChangeValueCallback("Change Reference Name");
                    this._referenceNameChangedCallback(evt.newValue);

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

                    this._postChangeValueCallback(true, ModificationScope.Graph);
                });

                _resetReferenceNameCallback = newValue =>
                {
                    m_ReferenceNameField.value = newValue;
                    m_ReferenceNameField.RemoveFromClassList("modified");
                };

                if (!string.IsNullOrEmpty(shaderInput.overrideReferenceName))
                {
                    propertyVisualElement.AddToClassList("modified");
                }
                propertyVisualElement.SetEnabled(shaderInput.isRenamable);
                propertyVisualElement.styleSheets.Add(Resources.Load <StyleSheet>("Styles/PropertyNameReferenceField"));
            }
        }
示例#2
0
        private VisualElement CreateGUI(
            ChangeValueCallback valueChangedCallback,
            ShaderGUIOverrideInfo actualObject,
            out VisualElement shaderGUIOverrideField)
        {
            m_ShaderGUIOverrideInfo = actualObject;
            var propertySheet = new PropertySheet();

            shaderGUIOverrideField = null;

            string storedValue  = actualObject.ShaderGUIOverride;
            string preferredGUI = GraphUtil.CurrentPipelinePreferredShaderGUI(m_MasterNode as IMasterNode);

            var boolPropertyDrawer = new BoolPropertyDrawer();

            propertySheet.Add(boolPropertyDrawer.CreateGUI(
                                  newValue =>
            {
                m_ShaderGUIOverrideInfo.OverrideEnabled = newValue;
                if (m_ShaderGUIOverrideInfo.OverrideEnabled)
                {
                    // Display the pipeline's default upon activation, if it has one. Otherwise set up field to display user setting.
                    if (string.IsNullOrEmpty(storedValue) && !string.IsNullOrEmpty(preferredGUI))
                    {
                        ProcessShaderGUIField(preferredGUI);
                    }
                    else
                    {
                        ProcessShaderGUIField(storedValue);
                    }
                }

                valueChangedCallback(m_ShaderGUIOverrideInfo);
                AddWarningIfNeeded(m_ShaderGUIOverrideInfo);
                // Update the inspector after this value is changed as it needs to trigger a re-draw to expose the ShaderGUI text field
                this.inspectorUpdateDelegate();
            },
                                  m_ShaderGUIOverrideInfo.OverrideEnabled,
                                  "Override ShaderGUI",
                                  out var boolKeywordField));


            if (actualObject.OverrideEnabled)
            {
                var textPropertyDrawer = new TextPropertyDrawer();
                propertySheet.Add(textPropertyDrawer.CreateGUI(
                                      newValue =>
                {
                    if (m_ShaderGUIOverrideInfo.ShaderGUIOverride == newValue)
                    {
                        return;
                    }

                    ProcessShaderGUIField(newValue);
                    valueChangedCallback(m_ShaderGUIOverrideInfo);
                    AddWarningIfNeeded(m_ShaderGUIOverrideInfo);
                },
                                      m_ShaderGUIOverrideInfo.ShaderGUIOverride,
                                      "ShaderGUI",
                                      out var propertyTextField
                                      ));

                // Reset to default if the value is ever set to null and override is enabled
                if (string.IsNullOrEmpty(storedValue))
                {
                    m_ShaderGUIOverrideInfo.ShaderGUIOverride = preferredGUI;
                }

                var textField = (TextField)propertyTextField;
                textField.value        = m_ShaderGUIOverrideInfo.ShaderGUIOverride;
                shaderGUIOverrideField = textField;
                textField.isDelayed    = true;
            }
            else
            {
                // Upon disable, set the value back to null (for pipeline switching reasons, among other reasons)
                if (storedValue == preferredGUI)
                {
                    m_ShaderGUIOverrideInfo.ShaderGUIOverride = null;
                    valueChangedCallback(m_ShaderGUIOverrideInfo);
                    AddWarningIfNeeded(m_ShaderGUIOverrideInfo);
                }
            }

            propertySheet.styleSheets.Add(Resources.Load <StyleSheet>("Styles/PropertyRow"));
            return(propertySheet);
        }