Beispiel #1
0
 // Add a warning to the node if the ShaderGUI is not found by Unity.
 private void AddWarningIfNeeded(ShaderGUIOverrideInfo shaderGuiOverrideInfo)
 {
     if (shaderGuiOverrideInfo.OverrideEnabled && shaderGuiOverrideInfo.ShaderGUIOverride != null &&
         !ValidCustomEditorType(shaderGuiOverrideInfo.ShaderGUIOverride))
     {
         m_MasterNode.owner.messageManager?.ClearNodesFromProvider(m_MasterNode,
                                                                   m_MasterNode.ToEnumerable());
         m_MasterNode.owner.messageManager?.AddOrAppendError(m_MasterNode, m_MasterNode.objectId,
                                                             new ShaderMessage(string.Format(k_InvalidShaderGUI, shaderGuiOverrideInfo.ShaderGUIOverride),
                                                                               ShaderCompilerMessageSeverity.Warning));
     }
     else
     {
         m_MasterNode.owner.messageManager?.ClearNodesFromProvider(m_MasterNode,
                                                                   m_MasterNode.ToEnumerable());
     }
 }
Beispiel #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);
        }