void DrawTextureSelector(string label, ref Texture2D tex, ref TextureChannel selectedChannel, ref bool invert) { EditorGUILayout.BeginVertical(EditorStyles.helpBox); { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.BeginVertical(); { var labelContent = new GUIContent(label); var size = EditorStyles.boldLabel.CalcSize(labelContent); EditorGUILayout.LabelField(labelContent, EditorStyles.boldLabel, GUILayout.MaxWidth(size.x)); GUILayout.Space(15 * EditorGUIUtility.pixelsPerPoint); GUILayout.FlexibleSpace(); invert = EditorGUILayout.ToggleLeft(INVERT_LABEL, invert, GUILayout.MaxWidth(InvertToggleWidth)); } EditorGUILayout.EndVertical(); tex = EditorGUILayout.ObjectField(GUIContent.none, tex, typeof(Texture2D), true, GUILayout.ExpandHeight(true)) as Texture2D; } EditorGUILayout.EndHorizontal(); if (showChannelPicker) { EditorGUI.BeginDisabledGroup(!tex); selectedChannel = PoiHelpers.DrawChannelSelector(selectedChannel, ChannelLabels); EditorGUI.EndDisabledGroup(); } } EditorGUILayout.EndVertical(); }
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 DoPack() { if (!PackerShadersExist) { return; } Texture2D red = packRed; Texture2D green = packGreen; Texture2D blue = packBlue; Texture2D alpha = packAlpha; if (showChannelPicker) { red = packRed.GetChannelAsTexture(redTexChan, unpackInvert); green = packGreen.GetChannelAsTexture(greenTexChan, unpackInvert); blue = packBlue.GetChannelAsTexture(blueTexChan, unpackInvert); alpha = packAlpha.GetChannelAsTexture(alphaTexChan, unpackInvert); } Texture2D packResult = PoiHelpers.PackTextures(PackSize, red, green, blue, alpha, redInvert, greenInvert, blueInvert, alphaInvert); 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() { _scroll = EditorGUILayout.BeginScrollView(_scroll); { EditorGUI.BeginChangeCheck(); { DrawTextureSelector(PACKED_TEXTURE_LABEL, ref unpackSource, ref unpackChan, ref unpackInvert); } 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); } } DrawShowChannelPicker(ref showChannelPicker); } EditorGUILayout.EndScrollView(); EditorGUI.BeginDisabledGroup(!unpackSource); { UnpackSize = DrawTextureSizeSettings(UnpackSize, ref unpackedName, ref unpackSizeIsLinked, ref unpackSizeAutoSelect); if (GUILayout.Button("Unpack", PoiStyles.BigButton)) { DoUnpack(unpackChan); } } EditorGUI.EndDisabledGroup(); EditorGUILayout.Space(); }
Vector2Int DrawTextureSizeSettings(Vector2Int size, ref string fileName, ref bool sizeIsLinked, ref bool sizeAutoSelect) { EditorGUILayout.BeginVertical(EditorStyles.helpBox); { fileName = EditorGUILayout.TextField("File name", fileName); EditorGUILayout.Space(); size = PoiHelpers.DrawResolutionPicker(size, ref sizeIsLinked, ref sizeAutoSelect, SizePresets, SizePresetNames); } EditorGUILayout.EndVertical(); return(size); }
void DrawPackUI() { _scroll = EditorGUILayout.BeginScrollView(_scroll); { EditorGUI.BeginChangeCheck(); { DrawTextureSelector(RED_TEXTURE_LABEL, ref packRed, ref redTexChan, ref redInvert); DrawTextureSelector(GREEN_TEXTURE_LABEL, ref packGreen, ref greenTexChan, ref greenInvert); DrawTextureSelector(BLUE_TEXTURE_LABEL, ref packBlue, ref blueTexChan, ref blueInvert); DrawTextureSelector(ALPHA_TEXTURE_LABEL, ref packAlpha, ref alphaTexChan, ref alphaInvert); } 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); } } } EditorGUILayout.EndScrollView(); DrawShowChannelPicker(ref showChannelPicker); bool disabled = new bool[] { packRed, packGreen, packBlue, packAlpha }.Count(b => b) < 2; EditorGUI.BeginDisabledGroup(disabled); { PackSize = DrawTextureSizeSettings(PackSize, ref packedName, ref packSizeIsLinked, ref packSizeAutoSelect); if (GUILayout.Button("Pack", PoiStyles.BigButton)) { DoPack(); } EditorGUILayout.Space(); } EditorGUI.EndDisabledGroup(); }