コード例 #1
0
ファイル: Settings.cs プロジェクト: SuperiorJacob/Unable
        //---------------------Stuff checkers and fixers-------------------

        //checks if slected shaders is using editor
        private void OnSelectionChange()
        {
            string[] selectedAssets = Selection.assetGUIDs;
            if (selectedAssets.Length == 1)
            {
                UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(AssetDatabase.GUIDToAssetPath(selectedAssets[0]));
                if (obj.GetType() == typeof(Shader))
                {
                    Shader shader = (Shader)obj;
                    if (ShaderHelper.IsShaderUsingThryEditor(shader))
                    {
                        Mediator.SetActiveShader(shader, new Material(shader));
                    }
                }
            }
            this.Repaint();
        }
コード例 #2
0
        void OnGUI()
        {
            scrollPos = GUILayout.BeginScrollView(scrollPos);

            bool init = false;

            if (paths == null)
            {
                paths   = new List <string>();
                shaders = new List <Shader>();
                differentQueueShaderPaths = new Dictionary <string, List <string> >();
                string[] shaderGuids = AssetDatabase.FindAssets("t:shader");

                for (int sguid = 0; sguid < shaderGuids.Length; sguid++)
                {
                    string path   = AssetDatabase.GUIDToAssetPath(shaderGuids[sguid]);
                    Shader shader = AssetDatabase.LoadAssetAtPath <Shader>(path);
                    if (!path.Contains("_differentQueues/"))
                    {
                        paths.Add(path);
                        shaders.Add(shader);
                    }
                    else
                    {
                        List <string> differentQueueShaderPaths;
                        this.differentQueueShaderPaths.TryGetValue(ShaderHelper.getDefaultShaderName(shader.name), out differentQueueShaderPaths);
                        if (differentQueueShaderPaths == null)
                        {
                            differentQueueShaderPaths = new List <string>();
                            this.differentQueueShaderPaths.Add(ShaderHelper.getDefaultShaderName(shader.name), differentQueueShaderPaths);
                        }
                        differentQueueShaderPaths.Add(path);
                    }
                }

                if (setEditor == null || setEditor.Length != shaderGuids.Length)
                {
                    setEditor = new bool[paths.Count];
                    wasEditor = new bool[paths.Count];
                }
                init = true;
            }

            for (int p = 0; p < paths.Count; p++)
            {
                if (init)
                {
                    EditorUtility.DisplayProgressBar("Load all shaders...", "", (float)p / paths.Count);
                    setEditor[p] = ShaderHelper.IsShaderUsingThryEditor(shaders[p]);
                    wasEditor[p] = setEditor[p];
                }
                setEditor[p] = GUILayout.Toggle(setEditor[p], shaders[p].name);
            }
            if (init)
            {
                EditorUtility.ClearProgressBar();
            }

            GUILayout.EndScrollView();

            if (GUILayout.Button("Apply"))
            {
                for (int i = 0; i < paths.Count; i++)
                {
                    if (wasEditor[i] != setEditor[i])
                    {
                        string path = paths[i];
                        ShaderImportFixer.scriptImportedAssetPaths.Add(path);
                        if (setEditor[i])
                        {
                            addThryEditor(path);
                        }
                        else
                        {
                            removeThryEditor(path);
                        }

                        List <string> differentQueueShaderPaths;
                        this.differentQueueShaderPaths.TryGetValue(shaders[i].name, out differentQueueShaderPaths);
                        if (differentQueueShaderPaths != null)
                        {
                            foreach (string queueShaderPath in differentQueueShaderPaths)
                            {
                                ShaderImportFixer.scriptImportedAssetPaths.Add(queueShaderPath);
                                if (setEditor[i])
                                {
                                    addThryEditor(queueShaderPath);
                                }
                                else
                                {
                                    removeThryEditor(queueShaderPath);
                                }
                            }
                        }
                    }

                    wasEditor[i] = setEditor[i];
                }
                AssetDatabase.Refresh();
                ThryEditor.repaint();
            }
        }
コード例 #3
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();
                }
            }
        }