AddNewShaderToCollection() private method

private AddNewShaderToCollection ( Shader shader, ShaderVariantCollection collection ) : bool
shader UnityEngine.Shader
collection UnityEngine.ShaderVariantCollection
return bool
Esempio n. 1
0
 public override void OnInspectorGUI()
 {
     base.serializedObject.Update();
     for (int i = 0; i < this.m_Shaders.arraySize; i++)
     {
         this.DrawShaderEntry(i);
     }
     if (GUILayout.Button("Add shader", new GUILayoutOption[0]))
     {
         ObjectSelector.get.Show(null, typeof(Shader), null, false);
         ObjectSelector.get.objectSelectorID = "ShaderVariantSelector".GetHashCode();
         GUIUtility.ExitGUI();
     }
     if (Event.current.type == EventType.ExecuteCommand)
     {
         if (Event.current.commandName == "ObjectSelectorClosed" && ObjectSelector.get.objectSelectorID == "ShaderVariantSelector".GetHashCode())
         {
             Shader shader = ObjectSelector.GetCurrentObject() as Shader;
             if (shader != null)
             {
                 ShaderUtil.AddNewShaderToCollection(shader, base.target as ShaderVariantCollection);
             }
             Event.current.Use();
             GUIUtility.ExitGUI();
         }
     }
     base.serializedObject.ApplyModifiedProperties();
 }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            for (var i = 0; i < m_Shaders.arraySize; ++i)
            {
                DrawShaderEntry(i);
            }

            // Button to add a new shader to collection
            if (GUILayout.Button("Add shader"))
            {
                // Show object selector
                ObjectSelector.get.Show(null, typeof(Shader), null, false);
                ObjectSelector.get.objectSelectorID = "ShaderVariantSelector".GetHashCode();
                GUIUtility.ExitGUI();
            }
            if (Event.current.type == EventType.ExecuteCommand)
            {
                // New shader picked in object selector; add it to the collection
                if (Event.current.commandName == ObjectSelector.ObjectSelectorClosedCommand && ObjectSelector.get.objectSelectorID == "ShaderVariantSelector".GetHashCode())
                {
                    var newShader = ObjectSelector.GetCurrentObject() as Shader;
                    if (newShader != null)
                    {
                        ShaderUtil.AddNewShaderToCollection(newShader, target as ShaderVariantCollection);
                    }
                    Event.current.Use();
                    GUIUtility.ExitGUI();
                }
            }

            serializedObject.ApplyModifiedProperties();
        }
Esempio n. 3
0
 public override void OnInspectorGUI()
 {
     this.serializedObject.Update();
     for (int shaderIndex = 0; shaderIndex < this.m_Shaders.arraySize; ++shaderIndex)
     {
         this.DrawShaderEntry(shaderIndex);
     }
     if (GUILayout.Button("Add shader"))
     {
         ObjectSelector.get.Show((Object)null, typeof(Shader), (SerializedProperty)null, false);
         ObjectSelector.get.objectSelectorID = "ShaderVariantSelector".GetHashCode();
         GUIUtility.ExitGUI();
     }
     if (Event.current.type == EventType.ExecuteCommand && Event.current.commandName == "ObjectSelectorClosed" && ObjectSelector.get.objectSelectorID == "ShaderVariantSelector".GetHashCode())
     {
         Shader currentObject = ObjectSelector.GetCurrentObject() as Shader;
         if ((Object)currentObject != (Object)null)
         {
             ShaderUtil.AddNewShaderToCollection(currentObject, this.target as ShaderVariantCollection);
         }
         Event.current.Use();
         GUIUtility.ExitGUI();
     }
     this.serializedObject.ApplyModifiedProperties();
 }