コード例 #1
0
        private void ProcessOverrideEnabledToggle(bool newValue)
        {
            string storedValue  = m_CanChangeShaderGUI.ShaderGUIOverride;
            string preferredGUI = GraphUtil.CurrentPipelinePreferredShaderGUI(m_MasterNode as IMasterNode);

            m_CanChangeShaderGUI.OverrideEnabled = newValue;

            // Display the ShaderGUI text field only when the override is enabled
            if (m_CanChangeShaderGUI.OverrideEnabled)
            {
                m_PropertySheet.Add(m_OverrideFieldRow);

                // 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, false);
                }
                else
                {
                    ProcessShaderGUIField(storedValue, false);
                }
            }
            else if (m_PropertySheet.Contains(m_OverrideFieldRow))
            {
                m_PropertySheet.Remove(m_OverrideFieldRow);

                // Upon disable, set the value back to null (for pipeline switching reasons, among other reasons)
                if (storedValue == preferredGUI)
                {
                    m_CanChangeShaderGUI.ShaderGUIOverride = null;
                }
            }

            AddWarningIfNeeded();
        }
コード例 #2
0
        private void ProcessShaderGUIField(string newValue, bool recordUndo)
        {
            if (newValue == null)
            {
                newValue = "";
            }

            string sanitizedInput = Regex.Replace(newValue, @"(?:[^A-Za-z0-9._])|(?:\s)", "");

            if (sanitizedInput != m_CanChangeShaderGUI.ShaderGUIOverride)
            {
                if (recordUndo)
                {
                    m_MasterNode.owner.owner.RegisterCompleteObjectUndo("ShaderGUI Change");
                }

                // Reset to default when the field is wiped out
                if (HasPreferredGUI() && string.IsNullOrEmpty(sanitizedInput))
                {
                    m_CanChangeShaderGUI.ShaderGUIOverride = GraphUtil.CurrentPipelinePreferredShaderGUI(m_MasterNode as IMasterNode);
                }
                else
                {
                    m_CanChangeShaderGUI.ShaderGUIOverride = sanitizedInput;
                }
            }

            m_ShaderGUITextField.value = m_CanChangeShaderGUI.ShaderGUIOverride;

            AddWarningIfNeeded();
        }
コード例 #3
0
        void ProcessShaderGUIField(string newValue)
        {
            string sanitizedInput = Regex.Replace(newValue, @"(?:[^A-Za-z0-9._])|(?:\s)", "");

            if (HasPreferredGUI() && string.IsNullOrEmpty(sanitizedInput))
            {
                var defaultGUI = GraphUtil.CurrentPipelinePreferredShaderGUI(m_MasterNode as IMasterNode);
                m_ShaderGUIOverrideInfo.ShaderGUIOverride = defaultGUI;
            }
            else
            {
                m_ShaderGUIOverrideInfo.ShaderGUIOverride = sanitizedInput;
            }
        }
コード例 #4
0
 private bool HasPreferredGUI()
 {
     return(!string.IsNullOrEmpty(GraphUtil.CurrentPipelinePreferredShaderGUI(m_MasterNode as IMasterNode)));
 }
コード例 #5
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);
        }