Example #1
0
        void DoPack()
        {
            if (PackerShadersExist)
            {
                Texture2D red   = packRed;
                Texture2D green = packGreen;
                Texture2D blue  = packBlue;
                Texture2D alpha = packAlpha;

                if (showChannelPicker)
                {
                    red   = packRed.GetChannelAsTexture(redTexChan);
                    green = packRed.GetChannelAsTexture(greenTexChan);
                    blue  = packRed.GetChannelAsTexture(blueTexChan);
                    alpha = packRed.GetChannelAsTexture(alphaTexChan);
                }

                Texture2D packResult = PoiHelpers.PackTextures(PackSize, red, green, blue, alpha);
                if (packResult)
                {
                    string path = $"{savePath}/Packed/{packedName}.png";
                    packResult.SaveTextureAsset(path, true);
                    Debug.Log(LOG_PREFIX + "Finished packing texture at " + path);
                    PoiHelpers.PingAssetAtPath(path);
                }
            }
        }
        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();
        }
Example #3
0
        void DoUnpack(TextureChannel singleChannel = TextureChannel.RGBA)
        {
            if (!PackerShadersExist)
            {
                return;
            }

            var channelTextures = new Dictionary <string, Texture2D>();

            if (singleChannel == TextureChannel.RGBA)
            {
                channelTextures = PoiHelpers.UnpackTextureToChannels(unpackSource, unpackInvert, UnpackSize);
            }
            else
            {
                channelTextures[singleChannel.ToString().ToLower()] = unpackSource.GetChannelAsTexture(singleChannel, unpackInvert, UnpackSize);
            }


            string pingPath = null;

            pingPath = SaveTextures(channelTextures, pingPath);

            Debug.Log(LOG_PREFIX + "Finished unpacking texture at " + pingPath);
            PoiHelpers.PingAssetAtPath(pingPath);
        }
        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();
        }
Example #5
0
        void DrawUnpackUI()
        {
            EditorGUI.BeginChangeCheck();
            {
                DrawTextureSelector("Packed Texture", ref unpackSource);
            }
            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);
                }
            }

            EditorGUI.BeginDisabledGroup(!unpackSource);
            {
                UnpackSize = DrawTextureSizeSettings(UnpackSize, ref unpackedName, ref unpackSizeIsLinked, ref unpackSizeAutoSelect);

                if (GUILayout.Button("Unpack", PoiStyles.BigButton))
                {
                    if (PackerShadersExist)
                    {
                        var    channelTextures = PoiHelpers.UnpackTextureToChannels(unpackSource, UnpackSize);
                        string pingPath        = null;
                        pingPath = SaveTextures(channelTextures, pingPath);

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

            EditorGUILayout.Space();
        }