void DrawUnpackUI()
        {
            EditorGUI.BeginChangeCheck();
            {
                unpackSource =
                    EditorGUILayout.ObjectField("Packed Texture", unpackSource, typeof(Texture2D), true) as Texture2D;
            }
            if (EditorGUI.EndChangeCheck() && unpackSizeAutoSelect)
            {
                // Get biggest texture size from selections and make a selection in our sizes list
                var tempSize = PoiHelpers.GetMaxSizeFromTextures(unpackSource);
                if (tempSize != default)
                {
                    UnpackSize = tempSize.ClosestPowerOfTwo(AUTO_SELECT_CEILING);
                }
            }

            PoiHelpers.DrawLine();

            EditorGUI.BeginDisabledGroup(!unpackSource);
            {
                unpackedName = EditorGUILayout.TextField("File name", unpackedName);

                EditorGUILayout.Space();

                UnpackSize = PoiHelpers.DrawResolutionPicker(UnpackSize, ref unpackSizeIsLinked, ref unpackSizeAutoSelect, SizePresets,
                                                             SizePresetNames);

                PoiHelpers.DrawLine();

                if (GUILayout.Button("Unpack"))
                {
                    var    output   = UnpackTextureToChannels(unpackSource, UnpackSize);
                    string pingPath = null;
                    try
                    {
                        AssetDatabase.StartAssetEditing();
                        foreach (var kv in output)
                        {
                            if (string.IsNullOrWhiteSpace(pingPath))
                            {
                                pingPath = $"{savePath}/Unpacked/{unpackedName}_{kv.Key}.png";
                            }
                            kv.Value?.SaveTextureAsset($"{savePath}/Unpacked/{unpackedName}_{kv.Key}.png", true);
                        }
                    }
                    catch {}
                    finally
                    {
                        AssetDatabase.StopAssetEditing();
                    }

                    Debug.Log(log_prefix + "Finished unpacking texture at " + pingPath);
                    PoiHelpers.PingAssetAtPath(pingPath);
                }
            }
            EditorGUI.EndDisabledGroup();

            PoiHelpers.DrawLine();
        }
        void OnGUI()
        {
            PoiHelpers.DrawLine();
            selectedTab = GUILayout.Toolbar(selectedTab, TabNames);
            PoiHelpers.DrawLine();

            if (selectedTab == (int)Tab.Pack)
            {
                DrawPackUI();
            }
            else
            {
                DrawUnpackUI();
            }
        }
        void DrawPackUI()
        {
            EditorGUI.BeginChangeCheck();
            {
                packRed   = EditorGUILayout.ObjectField("Red", packRed, typeof(Texture2D), true) as Texture2D;
                packGreen = EditorGUILayout.ObjectField("Green", packGreen, typeof(Texture2D), true) as Texture2D;
                packBlue  = EditorGUILayout.ObjectField("Blue", packBlue, typeof(Texture2D), true) as Texture2D;
                packAlpha = EditorGUILayout.ObjectField("Alpha", packAlpha, typeof(Texture2D), true) as Texture2D;
            }
            if (EditorGUI.EndChangeCheck() && packSizeAutoSelect)
            {
                // Get biggest texture size from selections and make a selection in our sizes list
                var tempSize = PoiHelpers.GetMaxSizeFromTextures(packRed, packGreen, packBlue, packAlpha);
                if (tempSize != default)
                {
                    PackSize = tempSize.ClosestPowerOfTwo(AUTO_SELECT_CEILING);
                }
            }

            PoiHelpers.DrawLine();

            bool disabled = new bool[] { packRed, packGreen, packBlue, packAlpha }.Count(b => b) < 2;

            EditorGUI.BeginDisabledGroup(disabled);
            {
                packedName = EditorGUILayout.TextField("File name", packedName);

                EditorGUILayout.Space();

                PackSize = PoiHelpers.DrawResolutionPicker(PackSize, ref packSizeIsLinked, ref packSizeAutoSelect, SizePresets, SizePresetNames);

                EditorGUILayout.Space();
                PoiHelpers.DrawLine();

                if (GUILayout.Button("Pack"))
                {
                    var packResult = PackTexture(PackSize, packRed, packGreen, packBlue, packAlpha);
                    if (packResult)
                    {
                        string path = $"{savePath}/Packed/{packedName}.png";
                        packResult.SaveTextureAsset(path, true);
                        Debug.Log(log_prefix + "Finished packing texture at " + path);
                        PoiHelpers.PingAssetAtPath(path);
                    }
                }
            }
            PoiHelpers.DrawLine();
        }
Exemplo n.º 4
0
        void OnGUI()
        {
            EditorGUILayout.LabelField("Poi Texture Packer", PoiStyles.TitleLabel);
            EditorGUILayout.LabelField(SubTitle);

            PoiHelpers.DrawLine();

            selectedTab = GUILayout.Toolbar(selectedTab, TabNames);

            if (selectedTab == (int)Tab.Pack)
            {
                DrawPackUI();
            }
            else
            {
                DrawUnpackUI();
            }
        }