示例#1
0
文件: Helper.cs 项目: bmjoy/qtengine
 public static void UpdateRenderQueue(Material material, Shader defaultShader)
 {
     if (material.shader.renderQueue != material.renderQueue)
     {
         Shader renderQueueShader = defaultShader;
         if (material.renderQueue != renderQueueShader.renderQueue)
         {
             renderQueueShader = ShaderHelper.createRenderQueueShaderIfNotExists(defaultShader, material.renderQueue, true);
         }
         material.shader = renderQueueShader;
     }
 }
示例#2
0
        private void OnGUI()
        {
            if (poiShaders == null || reload)
            {
                string[]      shaderGuids = AssetDatabase.FindAssets("t:shader");
                List <string> poiShaders  = new List <string>();
                foreach (string g in shaderGuids)
                {
                    Shader shader = AssetDatabase.LoadAssetAtPath <Shader>(AssetDatabase.GUIDToAssetPath(g));
                    if (ShaderHelper.IsShaderUsingThryEditor(shader))
                    {
                        string defaultShaderName = ShaderHelper.getDefaultShaderName(shader.name);
                        if (!poiShaders.Contains(defaultShaderName))
                        {
                            poiShaders.Add(defaultShaderName);
                        }
                    }
                }
                this.poiShaders = new string[poiShaders.Count + 1];
                for (int i = 0; i < poiShaders.Count; i++)
                {
                    this.poiShaders[i + 1] = poiShaders[i];
                }
            }

            GUILayout.Label("With thry editor the render queue selection in the material editor creates copies of the shader with different queues to make it work in vrchat. \n With this tool you can pre create those shader files so you don't have to wait.");

            Shader activeShader = Mediator.active_shader;

            if (activeShader != null)
            {
                poiShaders[0] = ShaderHelper.getDefaultShaderName(activeShader.name);
            }
            else
            {
                poiShaders[0] = "None";
            }
            int newSelectShader = EditorGUILayout.Popup(0, poiShaders, GUILayout.MaxWidth(200));

            if (newSelectShader != selectedShader)
            {
                selectedShader = newSelectShader;
                activeShader   = Shader.Find(poiShaders[newSelectShader]);
                Mediator.SetActiveShader(activeShader);
            }

            if (activeShader != null)
            {
                string defaultShaderName = ShaderHelper.getDefaultShaderName(activeShader.name);;
                Shader defaultShader     = Shader.Find(defaultShaderName);

                GUIStyle style = new GUIStyle(GUI.skin.label);
                style.richText = true;
                EditorGUILayout.LabelField("<size=16>" + defaultShaderName + "</size>", style, GUILayout.MinHeight(18));

                GUILayout.Label("Generate Render Queue Shaders", EditorStyles.boldLabel);

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Generate All Queues", GUILayout.MaxWidth(200)))
                {
                    for (int i = createShadersFrom; i <= createShadersTo; i++)
                    {
                        ShaderHelper.createRenderQueueShaderIfNotExists(defaultShader, i, false);
                    }
                    AssetDatabase.Refresh();
                }
                GUILayout.Label("from", GUILayout.MaxWidth(30));
                createShadersFrom = EditorGUILayout.IntField(createShadersFrom, GUILayout.MaxWidth(50));
                GUILayout.Label("to", GUILayout.MaxWidth(15));
                createShadersTo = EditorGUILayout.IntField(createShadersTo, GUILayout.MaxWidth(50));
                GUILayout.EndHorizontal();
                if (GUILayout.Button("Generate most common Queues", GUILayout.MaxWidth(200)))
                {
                    foreach (int i in COMMON_QUEUES)
                    {
                        ShaderHelper.createRenderQueueShaderIfNotExists(defaultShader, i, false);
                    }
                    AssetDatabase.Refresh();
                }
            }
        }