static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    {
        if (xsFilePath == null)
        {
            xsFilePath = XSStyles.findAssetPath("");
        }
        foreach (string str in importedAssets)
        {
            if (str.StartsWith(xsFilePath + "/Main/CGIncludes"))
            {
                Debug.Log("XS CGInclude updated: " + str.Replace(xsFilePath + "/Main/CGIncludes/", ""));
                string[] files = Directory.GetFiles(xsFilePath + "/Main/Shaders", "*.shader");
                foreach (string file in files)
                {
                    AssetDatabase.ImportAsset(file, ImportAssetOptions.ForceUpdate);
                }
            }

            if (str.StartsWith(xsFilePath + "/Main/Patreon/CGIncludes"))
            {
                Debug.Log("XS CGInclude updated: " + str.Replace(xsFilePath + "/Main/Patreon/CGIncludes/", ""));
                string[] files = Directory.GetFiles(xsFilePath + "/Main/Patreon/Shaders", "*.shader");
                foreach (string file in files)
                {
                    AssetDatabase.ImportAsset(file, ImportAssetOptions.ForceUpdate);
                }
            }
        }
    }
Пример #2
0
 public static void setupIcons()
 {
     if (skin == null)
     {
         uiPath = XSStyles.findAssetPath(uiPath) + "/Editor/Resources/";
         skin   = (GUISkin)AssetDatabase.LoadAssetAtPath <GUISkin>(uiPath + "XSGuiSkin.guiskin");
     }
 }
Пример #3
0
    private static void setupIconsOnReload()
    {
        uiPath = XSStyles.findAssetPath(uiPath) + "/Editor/Resources/";
        //-----

        skin = (GUISkin)AssetDatabase.LoadAssetAtPath <GUISkin>(uiPath + "XSGuiSkin.guiskin");

        if (skin == null)
        {
            skin = (GUISkin)AssetDatabase.LoadAssetAtPath <GUISkin>(uiPath + "XSGuiSkin.guiskin");
        }
    }
    void drawMGInputOutput()
    {
        GUILayout.BeginHorizontal();
        XSMultiGradient old_xsmg = xsmg;

        xsmg = (XSMultiGradient)EditorGUILayout.ObjectField("MultiGradient Preset", xsmg, typeof(XSMultiGradient), false, null);
        if (xsmg != old_xsmg)
        {
            if (xsmg != null)
            {
                this.gradients       = xsmg.gradients;
                this.gradients_index = xsmg.order;
                makeReorderedList();
            }
            else
            {
                List <Gradient> new_Grads = new List <Gradient>();
                for (int i = 0; i < this.gradients.Count; i++)
                {
                    new_Grads.Add(reflessGradient(this.gradients[i]));
                }
                this.gradients       = new_Grads;
                this.gradients_index = reflessIndexes(this.gradients_index);
                makeReorderedList();
            }
            changed = true;
        }

        if (GUILayout.Button("Save New", EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
        {
            finalFilePath = XSStyles.findAssetPath(finalFilePath);
            string path = EditorUtility.SaveFilePanel("Save MultiGradient", (finalFilePath + "/Textures/Shadow Ramps/MGPresets"), "MultiGradient", "asset");
            if (path.Length != 0)
            {
                path = path.Substring(Application.dataPath.Length - "Assets".Length);
                XSMultiGradient _xsmg = ScriptableObject.CreateInstance <XSMultiGradient>();
                _xsmg.uniqueName = Path.GetFileNameWithoutExtension(path);
                foreach (Gradient grad in gradients)
                {
                    _xsmg.gradients.Add(reflessGradient(grad));
                }
                _xsmg.order.AddRange(gradients_index.ToArray());
                xsmg = _xsmg;
                AssetDatabase.CreateAsset(_xsmg, path);
                this.gradients       = xsmg.gradients;
                this.gradients_index = xsmg.order;
                makeReorderedList();
                AssetDatabase.SaveAssets();
            }
        }
        GUILayout.EndHorizontal();
    }
    public void OnGUI()
    {
        scrollPos = EditorGUILayout.BeginScrollView(scrollPos);

        GUILayout.BeginHorizontal();
        GUILayout.Space(105);
        XSStyles.doLabel("1");
        GUILayout.Space(105);
        XSStyles.doLabel("2");
        GUILayout.Space(105);
        XSStyles.doLabel("3");
        GUILayout.Space(105);
        XSStyles.doLabel("4");
        GUILayout.EndHorizontal();

        XSStyles.SeparatorThin();
        GUILayout.BeginHorizontal();
        for (int i = 0; i < 4; i++)
        {
            EditorGUIUtility.labelWidth = 0.01f;
            textures[i] = (Texture2D)EditorGUILayout.ObjectField(new GUIContent("", ""), textures[i], typeof(Texture2D), true);
        }
        GUILayout.EndHorizontal();

        float oldLabelWidth = EditorGUIUtility.labelWidth;

        EditorGUIUtility.labelWidth = 40;
        GUIStyle headerStyle = EditorStyles.boldLabel;

        headerStyle.alignment    = TextAnchor.UpperLeft;
        headerStyle.fontStyle    = FontStyle.Bold;
        headerStyle.stretchWidth = true;

        XSStyles.SeparatorThin();
        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Output Channel:", headerStyle);

        GUILayout.Label("R", headerStyle);
        GUILayout.Label("G", headerStyle);
        GUILayout.Label("B", headerStyle);
        GUILayout.Label("A", headerStyle);
        EditorGUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.Label("Src Texture:");
        GUILayout.Space(20);
        for (int i = 0; i < 4; i++)
        {
            pickTexture[i] = (ETextures)EditorGUILayout.EnumPopup("", pickTexture[i]);
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.Label("Src Channel:");
        GUILayout.Space(17);
        for (int i = 0; i < 4; i++)
        {
            texChannels[i] = (EChannels)EditorGUILayout.EnumPopup("", texChannels[i]);
        }
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        GUILayout.Label("Invert Channel:");
        for (int i = 0; i < 4; i++)
        {
            invertChannel[i] = EditorGUILayout.Toggle("", invertChannel[i]);
        }
        GUILayout.EndHorizontal();

        GUILayout.Space(20);
        EditorGUILayout.EndScrollView();

        //Button and Resolution
        GUILayout.BeginVertical();
        XSStyles.doLabel("Resolution");

        GUILayout.BeginHorizontal();
        GUILayout.Space(175);
        res = (resolutions)EditorGUILayout.EnumPopup("", res);
        GUILayout.Space(175);
        GUILayout.EndHorizontal();

        if (GUILayout.Button("Merge Channels"))
        {
            //Set target textures to be ReadWriteable

            for (int i = 0; i < textures.Length; i++)
            {
                if (textures[i] == null)
                {
                    break;
                }

                string          texturePath = AssetDatabase.GetAssetPath(textures[i]);
                TextureImporter texture     = (TextureImporter)TextureImporter.GetAtPath(texturePath);
                if (texture != null)
                {
                    texture.isReadable = true;
                    texture.SaveAndReimport();
                }
            }

            switch (res)
            {
            case resolutions.Tiny_256x256:
                resolution = 256;
                break;

            case resolutions.Small_512x512:
                resolution = 512;
                break;

            case resolutions.Medium_1024x1024:
                resolution = 1024;
                break;

            case resolutions.Large_2048x2048:
                resolution = 2048;
                break;

            case resolutions.VeryLarge_4096x4096:
                resolution = 4096;
                break;

            case resolutions.Why_8192x8192:
                resolution = 8192;
                break;
            }

            XSStyles.findAssetPath(finalFilePath);
            finalFilePath = EditorUtility.SaveFilePanel("Save Merged Texture", finalFilePath + "/Textures/", "mergedTex.png", "png");

            Texture2D newTexture = new Texture2D(resolution, resolution, TextureFormat.RGBA32, false);

            //Get Colors textures and write them to the proper channel

            for (int y = 0; y < resolution; y++)
            {
                for (int x = 0; x < resolution; x++)
                {
                    float u = x / (float)resolution;
                    float v = y / (float)resolution;

                    // Grab out the texture values into an array for later lookup. Could probably just be done at the moment the texture color is needed.
                    for (int i = 0; i < textures.Length; i++)
                    {
                        if (textures[i] != null)
                        {
                            texColors[i] = textures[i].GetPixelBilinear(u, v);
                        }
                        else
                        {
                            texColors[i] = new Color(0, 0, 0, 1);
                        }
                    }

                    Color outputColor = new Color(0, 0, 0, 1);

                    // Iterate the output RGBA channels
                    for (int i = 0; i < 4; i++)
                    {
                        // Convert the enums to indices we can use. 'None' will turn into -1 which will be discarded as invalid.
                        int srcTexIdx     = ((int)pickTexture[i]) - 1;
                        int srcChannelIdx = ((int)texChannels[i]) - 1;

                        // Go through each channel in the output color and assign it
                        if (srcTexIdx >= 0 && srcChannelIdx >= 0)
                        {
                            outputColor[i] = texColors[srcTexIdx][srcChannelIdx];

                            //Allow you to invert specific channels.
                            if (invertChannel[i])
                            {
                                outputColor[i] = 1f - outputColor[i];
                            }
                        }
                    }

                    newTexture.SetPixel(x, y, outputColor);
                }
            }
            newTexture.Apply();
            ExportTexture(newTexture);
        }

        GUILayout.Space(10);
        GUILayout.EndVertical();

        EditorGUIUtility.labelWidth = oldLabelWidth;
    }
Пример #6
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()
    {
        changed = false;
        if (focusedMat != null)
        {
            XSStyles.ShurikenHeader("Current Material: " + focusedMat.name);
        }
        else
        {
            XSStyles.ShurikenHeader("Current Material: None");
        }

        if (preButton == null)
        {
            iconToolbarPlus  = EditorGUIUtility.IconContent("Toolbar Plus", "Add Gradient");
            iconToolbarMinus = EditorGUIUtility.IconContent("Toolbar Minus", "Remove Gradient");
            preButton        = new GUIStyle("RL FooterButton");
            buttonBackground = new GUIStyle("RL Header");
        }

        if (gradients.Count == 0)
        {
            gradients.Add(new Gradient());
            gradients.Add(new Gradient());
            gradients.Add(new Gradient());
            gradients.Add(new Gradient());
            gradients.Add(new Gradient());
        }

        if (grad_index_reorderable == null)
        {
            makeReorderedList();
        }

        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        Rect  r         = EditorGUILayout.GetControlRect();
        float rightEdge = r.xMax;
        float leftEdge  = rightEdge - 48f;

        r = new Rect(leftEdge, r.y, rightEdge - leftEdge, r.height);
        if (Event.current.type == EventType.Repaint)
        {
            buttonBackground.Draw(r, false, false, false, false);
        }
        leftEdge += 18f;
        EditorGUI.BeginDisabledGroup(gradients_index.Count == 5);
        bool addE = GUI.Button(new Rect(leftEdge + 4, r.y, 25, 13), iconToolbarPlus, preButton);

        EditorGUI.EndDisabledGroup();
        EditorGUI.BeginDisabledGroup(gradients_index.Count == 1);
        bool removeE = GUI.Button(new Rect(leftEdge - 19, r.y, 25, 13), iconToolbarMinus, preButton);

        EditorGUI.EndDisabledGroup();

        if (addE)
        {
            grad_index_reorderable.index++;
            int wat = 0;
            for (int i = 0; i < 5; i++)
            {
                if (!gradients_index.Contains(i))
                {
                    wat = i;
                    break;
                }
            }
            gradients_index.Add(wat);
            changed = true;
        }
        if (removeE)
        {
            gradients_index.Remove(gradients_index[gradients_index.Count - 1]);
            grad_index_reorderable.index--;
            changed = true;
        }

        GUIStyle button = new GUIStyle(EditorStyles.miniButton);

        button.normal = !reorder ? EditorStyles.miniButton.normal : EditorStyles.miniButton.onNormal;
        if (GUILayout.Button(new GUIContent("Reorder", "Don't use Reorder if you want to undo a gradient change"), button, GUILayout.ExpandWidth(false)))
        {
            reorder = !reorder;
        }
        GUILayout.EndHorizontal();

        SerializedObject serializedObject = new SerializedObject(this);

        if (reorder)
        {
            grad_index_reorderable.DoLayoutList();
        }
        else
        {
            SerializedProperty colorGradients = serializedObject.FindProperty("gradients");
            if (colorGradients.arraySize == 5)
            {
                for (int i = 0; i < gradients_index.Count; i++)
                {
                    Rect _r = EditorGUILayout.GetControlRect();
                    _r.x      += 16f;
                    _r.width  -= 2f + 16f;
                    _r.height += 5f;
                    _r.y      += 2f + (3f * i);
                    EditorGUI.PropertyField(_r, colorGradients.GetArrayElementAtIndex(gradients_index[i]), new GUIContent(""));
                }
                GUILayout.Space(Mathf.Lerp(9f, 24f, gradients_index.Count / 5f));
            }
        }
        if (serializedObject.ApplyModifiedProperties())
        {
            changed = true;
        }

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

        Resolutions oldRes = res;

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

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

        if (gradients_index.Count == 1)
        {
            height = 8;
        }
        else
        {
            height = 150;
        }
        if (tex == null)
        {
            tex = new Texture2D(width, height, TextureFormat.RGBA32, false);
        }

        bool old_isLinear = isLinear;

        drawAdvancedOptions();
        if (old_isLinear != isLinear)
        {
            changed = true;
        }

        if (manualMaterial)
        {
            focusedMat = (Material)EditorGUILayout.ObjectField(new GUIContent("", ""), focusedMat, typeof(Material), true);
        }

        if (focusedMat != null)
        {
            if (focusedMat.HasProperty("_Ramp"))
            {
                rampProperty = "_Ramp";
            }
            else
            {
                rampProperty = EditorGUILayout.TextField("Ramp Property Name", rampProperty);
                if (!focusedMat.HasProperty(rampProperty))
                {
                    GUILayout.Label("Property not found!");
                }
            }
        }

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

        XSStyles.Separator();
        drawMGInputOutput();


        if (GUILayout.Button("Save Ramp"))
        {
            finalFilePath = XSStyles.findAssetPath(finalFilePath);
            string path = EditorUtility.SaveFilePanel("Save Ramp as PNG", finalFilePath + "/Textures/Shadow Ramps/Generated", "gradient", "png");
            if (path.Length != 0)
            {
                updateTexture(width, height);
                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(rampProperty, ramp);
                            this.oldTexture = null;
                        }
                    }
                }
            }
        }
        drawHelpText();
    }