Exemplo n.º 1
0
        //---------------------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.IsShaderUsingShaderEditor(shader))
                    {
                        Mediator.SetActiveShader(shader, new Material(shader));
                    }
                }
            }
            this.Repaint();
        }
Exemplo n.º 2
0
        void OnGUI()
        {
            scrollPos = GUILayout.BeginScrollView(scrollPos);

            bool init = false;

            if (paths == null)
            {
                paths   = new List <string>();
                shaders = new List <Shader>();
                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);
                    paths.Add(path);
                    shaders.Add(shader);
                }

                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.IsShaderUsingShaderEditor(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];
                        if (setEditor[i])
                        {
                            addShaderEditor(path);
                        }
                        else
                        {
                            removeShaderEditor(path);
                        }
                    }

                    wasEditor[i] = setEditor[i];
                }
                AssetDatabase.Refresh();
                ShaderEditor.RepaintActive();
            }
        }