void drawHelpText()
 {
     XSStyles.Separator();
     dHelpText = XSStyles.ShurikenFoldout("Information", dHelpText);
     if (dHelpText)
     {
         scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
         XSStyles.HelpBox("You can use this to create a custom shadow ramp in realtime. \nIf you do not save, the ramp will be reverted back to what it was previously. \n\n - Click the Gradient box. \n - Choose resolution of the texture. \n - Save.", MessageType.Info);
         XSStyles.HelpBox("Ramp textures support up to 5 ramps in one texture. That means you can have up to 5 ramps on a single material. You will need to author a ramp mask to choose which ramp to sample from. \n\nA texture that is fully black would sample from the bottom ramp, a texture that is fully white would sample from the top ramp, and a texture that is half gray would sample from the middle ramp. \n\n A quick tip would be that you can sample from each of the 5 ramps with 0, 0.25, 0.5, 0.75, and 1 on the texture. \n\nThe order of the gradients on the UI is the order that they will be on the texture.", MessageType.Info);
         EditorGUILayout.EndScrollView();
     }
 }
Exemple #2
0
    public void OnGUI()
    {
        if (gradient == null)
        {
            gradient = new Gradient();
        }
        EditorGUI.BeginChangeCheck();
        SerializedObject   serializedGradient = new SerializedObject(this);
        SerializedProperty colorGradient      = serializedGradient.FindProperty("gradient");

        EditorGUILayout.PropertyField(colorGradient, true, null);
        serializedGradient.ApplyModifiedProperties();

        int width  = 128;
        int height = 8;

        res = (resolutions)EditorGUILayout.EnumPopup("Resolution: ", res);

        switch (res)
        {
        case resolutions.Large512x8:
            width = 512;
            break;

        case resolutions.Medium256x8:
            width = 256;
            break;

        case resolutions.Small128x8:
            width = 128;
            break;

        case resolutions.Tiny64x8:
            width = 64;
            break;
        }

        if (gradient != null)
        {
            Texture2D tex = new Texture2D(width, height, TextureFormat.RGBA32, false);


            for (int y = 0; y < tex.height; y++)
            {
                for (int x = 0; x < tex.width; x++)
                {
                    tex.SetPixel(x, y, gradient.Evaluate((float)x / (float)width));
                }
            }


            XSStyles.Separator();
            if (GUILayout.Button("Save Ramp"))
            {
                XSStyles.findAssetPath(finalFilePath);
                string path = EditorUtility.SaveFilePanel("Save Ramp as PNG", finalFilePath + "/Textures/Shadow Ramps/Generated", "gradient.png", "png");
                if (path.Length != 0)
                {
                    GenTexture(tex, path);
                }
            }
        }

        XSStyles.HelpBox("You can use this to create a custom shadow ramp. \nYou must save the asset with the save button to apply changes. \n\n - Click the Gradient box. \n - Choose resolution. \n - Save. \n - Drag texture into slot.", MessageType.Info);
    }
    public void OnGUI()
    {
        if (gradient == null)
        {
            gradient = new Gradient();
        }
        if (oldGradient == null)
        {
            oldGradient = new Gradient();
        }

        if (focusedMat != null && gradient != null)
        {
            XSStyles.ShurikenHeader("Current Material: " + focusedMat.name);
        }
        else
        {
            XSStyles.ShurikenHeader("Current Material: None");
        }

        SerializedObject   serializedGradient = new SerializedObject(this);
        SerializedProperty colorGradient      = serializedGradient.FindProperty("gradient");

        EditorGUILayout.PropertyField(colorGradient, true, null);
        serializedGradient.ApplyModifiedProperties();

        bool changed = !CompareGradients(oldGradient, gradient);

        if (oldFocusedMat != focusedMat)
        {
            changed = true;
            if (this.oldTexture != null)
            {
                if (this.oldTexture == EditorGUIUtility.whiteTexture)
                {
                    this.oldTexture = null;
                }
                oldFocusedMat.SetTexture("_Ramp", this.oldTexture);
                this.oldTexture = null;
            }
            oldFocusedMat = focusedMat;
        }

        if (changed)
        {
            oldGradient.SetKeys(gradient.colorKeys, gradient.alphaKeys);
            oldGradient.mode = gradient.mode;
        }

        Resolutions oldRes = res;

        res = (Resolutions)EditorGUILayout.EnumPopup("Resolution: ", res);
        if (oldRes != res)
        {
            changed = true;
        }

        int width  = (int)res;
        int height = 8;

        isLinear = GUILayout.Toggle(isLinear, "Make Linear Texture");

        if (gradient != null)
        {
            Texture2D tex = new Texture2D(width, height, TextureFormat.RGBA32, false);

            for (int y = 0; y < tex.height; y++)
            {
                for (int x = 0; x < tex.width; x++)
                {
                    tex.SetPixel(x, y, gradient.Evaluate((float)x / (float)width));
                }
            }

            if (focusedMat != null)
            {
                if (changed)
                {
                    if (focusedMat.HasProperty("_Ramp"))
                    {
                        if (this.oldTexture == null)
                        {
                            if (focusedMat.GetTexture("_Ramp") == null)
                            {
                                this.oldTexture = EditorGUIUtility.whiteTexture;
                            }
                            else
                            {
                                this.oldTexture = focusedMat.GetTexture("_Ramp");
                            }
                        }
                        tex.wrapMode = TextureWrapMode.Clamp;
                        tex.Apply(false);
                        focusedMat.SetTexture("_Ramp", tex);
                    }
                }
            }

            XSStyles.Separator();
            if (GUILayout.Button("Save Ramp"))
            {
                finalFilePath = XSStyles.findAssetPath(finalFilePath);
                string path = EditorUtility.SaveFilePanel("Save Ramp as PNG", finalFilePath + "/Textures/Shadow Ramps/Generated", "gradient.png", "png");
                if (path.Length != 0)
                {
                    bool success = GenTexture(tex, path);
                    if (success)
                    {
                        if (focusedMat != null)
                        {
                            string  s    = path.Substring(path.IndexOf("Assets"));
                            Texture ramp = AssetDatabase.LoadAssetAtPath <Texture>(s);
                            if (ramp != null)
                            {
                                focusedMat.SetTexture("_Ramp", ramp);
                                this.oldTexture = null;
                            }
                        }
                    }
                }
            }
        }

        XSStyles.HelpBox("You can use this to create a custom shadow ramp in realtime. \nIf you do not save, the ramp will be reverted back to what it was previously. \n\n - Click the Gradient box. \n - Choose resolution of the texture. \n - Save.", MessageType.Info);
    }
    public void OnGUI()
    {
        tab = GUILayout.Toolbar(tab, new string[] { "Documentation", "Updater", "Social" });
        XSStyles.SeparatorThin();
        switch (tab)
        {
        case 0:
            //show Docs from git
            XSStyles.doLabel("You can find Documentation here.");
            if (GUILayout.Button("Open Documentation"))
            {
                Application.OpenURL(docsURL);
            }

            break;

        case 1:
            EditorGUI.BeginChangeCheck();

            XSStyles.HelpBox("The currently installed version is: v" + XSStyles.ver + "\n\nTo check for updates, use the update button. If you choose to download an update, you will need to manually overwrite the old install by extracting the .zip into the project using the windows explorer. \n\nDo not drag the update directly into Unity - it won't ask to overwrite - it'll just create a duplicate and break.", MessageType.Info);
            XSStyles.SeparatorThin();
            if (GUILayout.Button("Check for Updates"))
            {
                req(updateUrl);
                EditorApplication.update += changelogEditorUpdate;
                showInfo = true;
            }

            if (showInfo)
            {
                scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
                Repaint();
                XSStyles.doLabelLeft("Newest version: ");
                XSStyles.doLabelSmall(curVer);
                XSStyles.SeparatorThin();

                XSStyles.doLabelLeft("Release Date: ");
                XSStyles.doLabelSmall(publishdate);
                XSStyles.SeparatorThin();

                XSStyles.doLabelLeft("Changelog: ");
                XSStyles.doLabelSmall(changelog);

                EditorGUILayout.EndScrollView();
                XSStyles.SeparatorThin();
                if (GUILayout.Button("Download"))
                {
                    Application.OpenURL(downloadLink);
                }
            }
            else
            {
                XSStyles.doLabel("Hit 'Check for Updates' to begin");
            }
            EditorGUI.EndChangeCheck();

            break;

        case 2:
            //show Patrons

            XSStyles.doLabel("Thank you to my patreon supporters, and the people who have helped me along the way, you guys are great!\n Note: You must be in the Discord server to show on this list.");
            XSStyles.SeparatorThin();
            XSStyles.doLabel("Current Patrons");
            XSStyles.SeparatorThin();
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
            if (!hasCalledPatronlist)
            {
                hasCalledPatronlist = true;
                req(patronsURL);
                EditorApplication.update += EditorUpdate;
            }
            for (int i = 0; i < patrons.Length; i++)
            {
                XSStyles.doLabel(" - " + patrons[i]);
            }
            EditorGUILayout.EndScrollView();

            XSStyles.SeparatorThin();
            //show social links
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            XSStyles.discordButton(70, 30);
            XSStyles.patreonButton(70, 30);
            XSStyles.githubButton(70, 30);
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
            break;
        }
    }