Exemplo n.º 1
0
    public override void OnInspectorGUI()
    {
        var myTarget = (AtlasGenerator)target;

        EditorGUI.BeginChangeCheck();
        textureSize = (TextureSizes)EditorGUILayout.EnumPopup("Texture Size", textureSize);
        if (EditorGUI.EndChangeCheck())
        {
            myTarget.textureSize = (int)textureSize;
        }

        EditorGUILayout.BeginVertical();
        var index = 0;
        var width = EditorGUIUtility.currentViewWidth / 10;

        for (int y = 0; y < 8; y++)
        {
            EditorGUILayout.BeginHorizontal();
            for (int x = 0; x < 8; x++)
            {
                EditorGUI.BeginChangeCheck();
                var newCol = EditorGUILayout.ColorField(GUIContent.none, myTarget.colors[index], false, false, false, GUILayout.Width(width));
                if (EditorGUI.EndChangeCheck())
                {
                    myTarget.colors[index] = newCol;
                }
                index++;
            }
            EditorGUILayout.EndHorizontal();
        }
        EditorGUILayout.EndVertical();

        EditorGUILayout.Space();
        if (GUILayout.Button("Generate Atlas"))
        {
            myTarget.MakeTexture();
        }

        EditorGUILayout.Space();
    }
Exemplo n.º 2
0
    private void GradientCreator()
    {
        GUILayout.Label("Gradient Creator", bigLabel);
        GUILayout.Space(20);
        GUILayout.Label("This feature can be used to create textures for the Color Ramp Effect", EditorStyles.boldLabel);

        EditorGUILayout.GradientField("Gradient", gradient, GUILayout.Height(25));

        EditorGUILayout.BeginHorizontal();
        {
            GUILayout.Label("Texture Size:", GUILayout.MaxWidth(145));
            textureSizes = (TextureSizes)EditorGUILayout.EnumPopup(textureSizes, GUILayout.MaxWidth(200));
        }
        EditorGUILayout.EndHorizontal();

        int       textureSize = (int)textureSizes;
        Texture2D gradTex     = new Texture2D(textureSize, 1, TextureFormat.RGBA32, false);

        for (int i = 0; i < textureSize; i++)
        {
            gradTex.SetPixel(i, 0, gradient.Evaluate((float)i / (float)textureSize));
        }
        gradTex.Apply();

        GUILayout.Space(20);
        GUILayout.Label("Select the folder where new Gradient Textures will be saved", EditorStyles.boldLabel);
        HandleSaveFolderEditorPref("All1ShaderGradients", "Assets/AllIn1SpriteShader/Textures/GradientTextures", "Gradient");

        string prefSavedPath = PlayerPrefs.GetString("All1ShaderGradients") + "/";

        if (Directory.Exists(prefSavedPath))
        {
            EditorGUILayout.BeginHorizontal();
            {
                GUILayout.Label("Gradient Texture Filtering: ", GUILayout.MaxWidth(170));
                gradientFiltering = (FilterMode)EditorGUILayout.EnumPopup(gradientFiltering, GUILayout.MaxWidth(200));
            }
            EditorGUILayout.EndHorizontal();

            if (GUILayout.Button("Save Gradient Texture"))
            {
                string path = EditorUtility.SaveFilePanel("Save texture as PNG", prefSavedPath, "gradientTexture_1.png", "png");
                if (path.Length != 0)
                {
                    byte[] pngData = gradTex.EncodeToPNG();
                    if (pngData != null)
                    {
                        File.WriteAllBytes(path, pngData);
                    }
                    AssetDatabase.Refresh();

                    if (path.IndexOf("Assets/") >= 0)
                    {
                        string          subPath  = path.Substring(path.IndexOf("Assets/"));
                        TextureImporter importer = AssetImporter.GetAtPath(subPath) as TextureImporter;
                        if (importer != null)
                        {
                            Debug.Log("Gradient saved inside the project: " + subPath);
                            importer.filterMode = gradientFiltering;
                            importer.SaveAndReimport();
                            EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath(subPath, typeof(Texture)));
                        }
                    }
                    else
                    {
                        Debug.Log("Gradient saved outside the project: " + path);
                    }
                }
            }
        }
    }