summaryrefslogtreecommitdiff
path: root/VRCSDK3Worlds/Assets/MeshBaker/Editor/propertyDrawers/MB_ConvertTextureArrayFormatWizard.cs
blob: b20869d9f6513360f12e9132b611d356540edd06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using UnityEditor;
using UnityEngine;
using DigitalOpus.MB.Core;

namespace DigitalOpus.MB.MBEditor
{
    public class MB_ConvertTextureArrayFormatWizard : ScriptableWizard
    {
        public Texture2DArray textureArray;
        public TextureFormat format = TextureFormat.ARGB32;

        [MenuItem("Window/Mesh Baker/TextureArray Format Converter")]
        static void CreateWizard()
        {
            ScriptableWizard.DisplayWizard<MB_ConvertTextureArrayFormatWizard>("Convert Texture Array Format", "Close", "Convert");
        }

        void OnWizardCreate()
        {

        }

        void OnWizardUpdate()
        {
            helpString = "Please assign a texture array";
        }

        void OnWizardOtherButton()
        {
            helpString = "";
            if (textureArray == null)
            {
                helpString = "Please assign a texture array";
                return;
            }

            MB3_EditorMethods editorMethods = new MB3_EditorMethods();
            if (!editorMethods.TextureImporterFormatExistsForTextureFormat(format))
            {
                helpString = "No ImporterFormat exists for the selected format. Please select a different format.";
                return;
            }

            if (textureArray.format != TextureFormat.ARGB32 &&
                textureArray.format != TextureFormat.RGB24)
            {
                helpString = "Source TextureArray must be in format ARGB32 or RGB24. This will probably be changed in" +
                    "a future version of Mesh Baker.";
                return;
            }

            Texture2DArray outArray = new Texture2DArray(textureArray.width, textureArray.height, textureArray.depth, format, true);
            if (editorMethods.ConvertTexture2DArray(textureArray, outArray, format))
            {
                string pth = UnityEditor.AssetDatabase.GetAssetPath(textureArray);
                if (pth == null) pth = "Assets/TextureArray.asset";
                pth = pth.Replace(".asset", "");
                pth += format.ToString() + ".asset";
                UnityEditor.AssetDatabase.CreateAsset(outArray, pth);
                Debug.Log("Convert success saved asset: " + pth);
            }
        }
    }
}