public AdvancedShader GetShader(string _shaderName)
        {
            for (int _iter = 0; _iter < m_shaderList.Count; _iter++)
            {
                AdvancedShader _curShader = m_shaderList[_iter];

                if (_shaderName.Equals(_curShader.ShaderName))
                {
                    return(_curShader);
                }
            }

            return(null);
        }
Пример #2
0
    void FindShaderFromCurrentOptions()
    {
        Setup();

        exactMatchShader     = null;
        exactEffectConflicts = "";

        //List<AdvancedShader.ShaderEffect> selectedEffectsList = new List<AdvancedShader.ShaderEffect>();
        //int[] selectedEffectsIndices = new int[selectedEffects.Count];
        List <int> selectedEffectsIndicesList = new List <int>();

        for (int i = 0; i < allEffectsArray.Length; i++)
        {
            //if (selectedEffects[i]) selectedEffectsList.Add(allEffectsArray[i]);
            if (selectedEffects[i])
            {
                //selectedEffectsIndices[c] = i;
                selectedEffectsIndicesList.Add(i);
            }
        }
        int[] selectedEffectsIndices = selectedEffectsIndicesList.ToArray();

        bool valid = true;

        for (int i = 0; i < selectedEffectsIndices.Length; i++)
        {
            AdvancedShader.ShaderEffect effectI = allEffectsArray[selectedEffectsIndices[i]];
            if (ignoreEffects.Contains(effectI))
            {
                valid = false;
                break;
            }

            for (int j = 0; j < selectedEffectsIndices.Length; j++)
            {
                AdvancedShader.ShaderEffect effectJ = allEffectsArray[selectedEffectsIndices[j]];

                if (i == j)
                {
                    continue;
                }
                if (cantCombineEffects[effectI].Contains(effectJ))
                {
                    exactEffectConflicts = AdvancedShader.shaderEffectNames[selectedEffectsIndices[i]] + " with " + AdvancedShader.shaderEffectNames[selectedEffectsIndices[j]];
                    valid = false;
                    break;
                }
                if (cantCombineEffects[effectJ].Contains(effectI))
                {
                    exactEffectConflicts = AdvancedShader.shaderEffectNames[selectedEffectsIndices[i]] + " with " + AdvancedShader.shaderEffectNames[selectedEffectsIndices[j]];
                    valid = false;
                    break;
                }
                if (ignoreEffects.Contains(effectJ))
                {
                    valid = false;
                    break;
                }
            }

            if (!valid)
            {
                break;
            }
        }

        if (valid && selectedEffectsIndices.Length > 0)
        {
            exactMatchShader = new AdvancedShader();

            for (int k = 0; k < selectedEffectsIndices.Length; k++)
            {
                exactMatchShader.shaderEffects.Add(allEffectsArray[selectedEffectsIndices[k]]);
            }
        }
    }
Пример #3
0
    void OnGUI()
    {
        bool hasChanged = false;
        bool current    = false;

        Color previousColour = GUI.contentColor;

        GUI.contentColor = new Color(0.7f, 0.7f, 0.7f, 1f);
        GUILayout.Label("Select Required Shader Effects");
        GUI.contentColor = previousColour;

        GUILayout.Space(5f);

        GUIStyle scrollViewStyle = new GUIStyle(GUI.skin.GetStyle("ScrollView"));

        scrollViewStyle.margin = new RectOffset(5, 5, 5, 5);

        effectsScrollPosition = EditorGUILayout.BeginScrollView(effectsScrollPosition, scrollViewStyle);
        int numSelectedEffects = 0;

        for (int i = 0; i < allEffectsArray.Length; i++)
        {
            if (!selectedEffects.ContainsKey(i))
            {
                PreSetup();
                return;
            }
            current = selectedEffects[i];
            if (mobile && nonMobileEffects.Contains(allEffectsArray[i]))
            {
                selectedEffects[i] = false;
                if (current)
                {
                    hasChanged = true;
                }
                EditorGUI.BeginDisabledGroup(true);
            }
            selectedEffects[i] = GUILayout.Toggle(selectedEffects[i], AdvancedShader.shaderEffectNames[i]);
            if (current != selectedEffects[i])
            {
                hasChanged = true;
            }
            if (selectedEffects[i])
            {
                numSelectedEffects++;
            }
            if (mobile && nonMobileEffects.Contains(allEffectsArray[i]))
            {
                selectedEffects[i] = false;
                EditorGUI.EndDisabledGroup();
            }
        }
        EditorGUILayout.EndScrollView();

        GUILayout.Space(20f);

        mobile = GUILayout.Toggle(mobile, "Mobile");
        if (exactMatchShader != null && exactMatchShader.mobile != mobile)
        {
            if (exactMatchShader != null)
            {
                exactMatchShader.mobile = mobile;
            }
        }

        transparent = GUILayout.Toggle(transparent, "Transparent");
        if (exactMatchShader != null && exactMatchShader.transparent != transparent)
        {
            if (exactMatchShader != null)
            {
                exactMatchShader.transparent = transparent;
                if (transparent)
                {
                    exactMatchShader.transparentCutout = false;
                }
                exactMatchShader.SetQueueForTransparency();
            }
        }

        transparentCutout = GUILayout.Toggle(transparentCutout, "Transparent Cutout");
        if (exactMatchShader != null && exactMatchShader.transparentCutout != transparentCutout)
        {
            if (exactMatchShader != null)
            {
                exactMatchShader.transparentCutout = transparentCutout;
                if (transparentCutout)
                {
                    exactMatchShader.transparent = false;
                }
                exactMatchShader.SetQueueForTransparency();
            }
        }

        EditorGUILayout.HelpBox("Leave this as 0 if unsure.", MessageType.Info, true);
        int currentQueueOffset = queueOffset;

        queueOffset = EditorGUILayout.IntField("Queue Offset", queueOffset);
        if (currentQueueOffset != queueOffset)
        {
            exactMatchShader.queueOffset = queueOffset;
        }

        if (hasChanged)
        {
            FindShaderFromCurrentOptions();
            if (numSelectedEffects < 9)
            {
                FindPermutationFromCurrentOptions();
            }
        }

        bool create         = false;
        bool specificShader = false;

        EditorGUILayout.Separator();

        if (exactMatchShader == null && foundPermutations.Count == 0)
        {
            EditorGUILayout.HelpBox("Select shader effects from the list above", MessageType.None, true);
        }
        else
        {
            GUILayout.Label("Generate Exact Shader:");
            if (exactMatchShader == null)
            {
                EditorGUILayout.HelpBox("Can't create this specific shader. Conflicting effects: " + exactEffectConflicts, MessageType.Error, true);
            }
            else
            {
                EditorGUILayout.HelpBox("This will generate the shader \"" + exactMatchShader.ShaderName() + "\"", MessageType.Info, true);

                if (GUILayout.Button("Create \"" + exactMatchShader.ShaderName() + "\" shader"))
                {
                    create         = true;
                    specificShader = true;
                }
            }

            EditorGUILayout.Separator();

            GUILayout.Label("Generate All Selected Shader Effect Permutations:");
            MessageType permMessageType      = MessageType.Info;
            string      permutationStringEnd = foundPermutations.Count.ToString() + " unique shaders.";
            if (foundPermutations.Count == 1)
            {
                permutationStringEnd = foundPermutations.Count.ToString() + " unique shader.";
            }
            if (numSelectedEffects >= 9)
            {
                permutationStringEnd = "over one hundred unique shaders. It may take a few minutes.";
                permMessageType      = MessageType.Warning;
            }

            EditorGUILayout.HelpBox("This will generate " + permutationStringEnd, permMessageType, true);

            if (GUILayout.Button("Create all (" + foundPermutations.Count.ToString() + ") selected shader permutations"))
            {
                create         = true;
                specificShader = false;
            }

            if (create)
            {
                if (specificShader && exactMatchShader != null)
                {
                    exactMatchShader.CreateShaderFile(shaderDirectory);
                }
                else
                {
                    for (int i = 0; i < foundPermutations.Count; i++)
                    {
                        AdvancedShader newShader = new AdvancedShader();

                        newShader.mobile = mobile;

                        for (int j = 0; j < foundPermutations[i].Length; j++)
                        {
                            newShader.shaderEffects.Add(foundPermutations[i][j]);
                        }

                        // Create opaque, alpha and alphatest shaders
                        //newShader.CreateShaderFile(shaderDirectory);

                        newShader.transparentCutout = transparentCutout;
                        newShader.transparent       = transparent;
                        newShader.SetQueueForTransparency();

                        newShader.CreateShaderFile(shaderDirectory);
                    }
                }

                AssetDatabase.Refresh();
            }
        }
    }
Пример #4
0
    void OnGUI()
    {
        bool hasChanged = false;
        bool current = false;

        Color previousColour = GUI.contentColor;
        GUI.contentColor = new Color(0.7f, 0.7f, 0.7f, 1f);
        GUILayout.Label("Select Required Shader Effects");
        GUI.contentColor = previousColour;

        GUILayout.Space(5f);

        GUIStyle scrollViewStyle = new GUIStyle(GUI.skin.GetStyle("ScrollView"));
        scrollViewStyle.margin = new RectOffset(5, 5, 5, 5);

        effectsScrollPosition = EditorGUILayout.BeginScrollView(effectsScrollPosition, scrollViewStyle);
        int numSelectedEffects = 0;
        for (int i = 0; i < allEffectsArray.Length; i++)
        {
            if (!selectedEffects.ContainsKey(i))
            {
                PreSetup();
                return;
            }
            current = selectedEffects[i];
            if (mobile && nonMobileEffects.Contains(allEffectsArray[i]))
            {
                selectedEffects[i] = false;
                if (current) hasChanged = true;
                EditorGUI.BeginDisabledGroup(true);
            }
            selectedEffects[i] = GUILayout.Toggle(selectedEffects[i], AdvancedShader.shaderEffectNames[i]);
            if (current != selectedEffects[i])
            {
                hasChanged = true;
            }
            if (selectedEffects[i]) numSelectedEffects++;
            if (mobile && nonMobileEffects.Contains(allEffectsArray[i]))
            {
                selectedEffects[i] = false;
                EditorGUI.EndDisabledGroup();
            }
        }
        EditorGUILayout.EndScrollView();

        GUILayout.Space(20f);

        mobile = GUILayout.Toggle(mobile, "Mobile");
        if (exactMatchShader != null && exactMatchShader.mobile != mobile)
        {
            if (exactMatchShader != null)
            {
                exactMatchShader.mobile = mobile;
            }
        }

        transparent = GUILayout.Toggle(transparent, "Transparent");
        if (exactMatchShader != null && exactMatchShader.transparent != transparent)
        {
            if (exactMatchShader != null)
            {
                exactMatchShader.transparent = transparent;
                if (transparent)
                {
                    exactMatchShader.transparentCutout = false;
                }
                exactMatchShader.SetQueueForTransparency();
            }
        }

        transparentCutout = GUILayout.Toggle(transparentCutout, "Transparent Cutout");
        if (exactMatchShader != null && exactMatchShader.transparentCutout != transparentCutout)
        {
            if (exactMatchShader != null)
            {

                exactMatchShader.transparentCutout = transparentCutout;
                if (transparentCutout)
                {
                    exactMatchShader.transparent = false;
                }
                exactMatchShader.SetQueueForTransparency();
            }
        }

        EditorGUILayout.HelpBox("Leave this as 0 if unsure.", MessageType.Info, true);
        int currentQueueOffset = queueOffset;
        queueOffset = EditorGUILayout.IntField("Queue Offset", queueOffset);
        if (currentQueueOffset != queueOffset)
        {
            exactMatchShader.queueOffset = queueOffset;
        }

        if (hasChanged)
        {
            FindShaderFromCurrentOptions();
            if (numSelectedEffects < 9) FindPermutationFromCurrentOptions();
        }

        bool create = false;
        bool specificShader = false;

        EditorGUILayout.Separator();

        if (exactMatchShader == null && foundPermutations.Count == 0)
        {
            EditorGUILayout.HelpBox("Select shader effects from the list above", MessageType.None, true);
        }
        else
        {
            GUILayout.Label("Generate Exact Shader:");
            if (exactMatchShader == null)
            {
                EditorGUILayout.HelpBox("Can't create this specific shader. Conflicting effects: " + exactEffectConflicts, MessageType.Error, true);
            }
            else
            {
                EditorGUILayout.HelpBox("This will generate the shader \"" + exactMatchShader.ShaderName() + "\"", MessageType.Info, true);

                if (GUILayout.Button("Create \"" + exactMatchShader.ShaderName() + "\" shader"))
                {
                    create = true;
                    specificShader = true;
                }
            }

            EditorGUILayout.Separator();

            GUILayout.Label("Generate All Selected Shader Effect Permutations:");
            MessageType permMessageType = MessageType.Info;
            string permutationStringEnd = foundPermutations.Count.ToString() + " unique shaders.";
            if (foundPermutations.Count == 1) permutationStringEnd = foundPermutations.Count.ToString() + " unique shader.";
            if (numSelectedEffects >= 9)
            {
                permutationStringEnd = "over one hundred unique shaders. It may take a few minutes.";
                permMessageType = MessageType.Warning;
            }

            EditorGUILayout.HelpBox("This will generate " + permutationStringEnd, permMessageType, true);

            if (GUILayout.Button("Create all (" + foundPermutations.Count.ToString() + ") selected shader permutations"))
            {
                create = true;
                specificShader = false;
            }

            if (create)
            {
                if (specificShader && exactMatchShader != null)
                {
                    exactMatchShader.CreateShaderFile(shaderDirectory);
                }
                else
                {
                    for (int i = 0; i < foundPermutations.Count; i++)
                    {
                        AdvancedShader newShader = new AdvancedShader();

                        newShader.mobile = mobile;

                        for (int j = 0; j < foundPermutations[i].Length; j++)
                        {
                            newShader.shaderEffects.Add(foundPermutations[i][j]);
                        }

                        // Create opaque, alpha and alphatest shaders
                        //newShader.CreateShaderFile(shaderDirectory);

                        newShader.transparentCutout = transparentCutout;
                        newShader.transparent = transparent;
                        newShader.SetQueueForTransparency();

                        newShader.CreateShaderFile(shaderDirectory);
                    }
                }

                AssetDatabase.Refresh();
            }
        }
    }
Пример #5
0
    void FindShaderFromCurrentOptions()
    {
        Setup();

        exactMatchShader = null;
        exactEffectConflicts = "";

        //List<AdvancedShader.ShaderEffect> selectedEffectsList = new List<AdvancedShader.ShaderEffect>();
        //int[] selectedEffectsIndices = new int[selectedEffects.Count];
        List<int> selectedEffectsIndicesList = new List<int>();
        for (int i = 0; i < allEffectsArray.Length; i++)
        {
            //if (selectedEffects[i]) selectedEffectsList.Add(allEffectsArray[i]);
            if (selectedEffects[i])
            {
                //selectedEffectsIndices[c] = i;
                selectedEffectsIndicesList.Add(i);
            }
        }
        int[] selectedEffectsIndices = selectedEffectsIndicesList.ToArray();

        bool valid = true;

        for (int i = 0; i < selectedEffectsIndices.Length; i++)
        {
            AdvancedShader.ShaderEffect effectI = allEffectsArray[selectedEffectsIndices[i]];
            if (ignoreEffects.Contains(effectI))
            {
                valid = false;
                break;
            }

            for (int j = 0; j < selectedEffectsIndices.Length; j++)
            {
                AdvancedShader.ShaderEffect effectJ = allEffectsArray[selectedEffectsIndices[j]];

                if (i == j) continue;
                if (cantCombineEffects[effectI].Contains(effectJ))
                {
                    exactEffectConflicts = AdvancedShader.shaderEffectNames[selectedEffectsIndices[i]] + " with " + AdvancedShader.shaderEffectNames[selectedEffectsIndices[j]];
                    valid = false;
                    break;
                }
                if (cantCombineEffects[effectJ].Contains(effectI))
                {
                    exactEffectConflicts = AdvancedShader.shaderEffectNames[selectedEffectsIndices[i]] + " with " + AdvancedShader.shaderEffectNames[selectedEffectsIndices[j]];
                    valid = false;
                    break;
                }
                if (ignoreEffects.Contains(effectJ))
                {
                    valid = false;
                    break;
                }
            }

            if (!valid) break;
        }

        if (valid && selectedEffectsIndices.Length > 0)
        {
            exactMatchShader = new AdvancedShader();

            for (int k = 0; k < selectedEffectsIndices.Length; k++)
            {
                exactMatchShader.shaderEffects.Add(allEffectsArray[selectedEffectsIndices[k]]);
            }
        }
    }