mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-08 11:46:53 +08:00
Add logic to disable TextureImporter overrides for every platform and enable them again after persisting the new texture size
This commit is contained in:
parent
12e424bee1
commit
acd994d00a
@ -203,6 +203,9 @@ namespace Spine.Unity.Editor {
|
|||||||
importer.SaveAndReimport();
|
importer.SaveAndReimport();
|
||||||
|
|
||||||
if (resizePhysically) {
|
if (resizePhysically) {
|
||||||
|
bool hasOverridesToEnable =
|
||||||
|
TextureImporterUtils.TryDisableOverrides(importer, out List<string> disabledPlatforms);
|
||||||
|
|
||||||
Texture2D texture2D = AssetDatabase.LoadAssetAtPath<Texture2D>(texturePath);
|
Texture2D texture2D = AssetDatabase.LoadAssetAtPath<Texture2D>(texturePath);
|
||||||
if (texture2D) {
|
if (texture2D) {
|
||||||
Color[] maxTextureSizePixels = texture2D.GetPixels();
|
Color[] maxTextureSizePixels = texture2D.GetPixels();
|
||||||
@ -223,6 +226,10 @@ namespace Spine.Unity.Editor {
|
|||||||
EditorUtility.SetDirty(nonCompressedTexture);
|
EditorUtility.SetDirty(nonCompressedTexture);
|
||||||
AssetDatabase.SaveAssets();
|
AssetDatabase.SaveAssets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hasOverridesToEnable) {
|
||||||
|
TextureImporterUtils.EnableOverrides(importer, disabledPlatforms);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
placeholderTexture = AssetDatabase.LoadAssetAtPath<Texture>(texturePath);
|
placeholderTexture = AssetDatabase.LoadAssetAtPath<Texture>(texturePath);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,61 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using UnityEditor;
|
||||||
|
|
||||||
|
namespace Spine.Unity.Editor {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Utility class for working with TextureImporter.
|
||||||
|
/// </summary>
|
||||||
|
public static class TextureImporterUtils {
|
||||||
|
|
||||||
|
private static IEnumerable<string> GetAllPossiblePlatforms() {
|
||||||
|
BuildTarget[] buildTargets = (BuildTarget[])Enum.GetValues(typeof(BuildTarget));
|
||||||
|
var platformNames = buildTargets.Select(x => x.ToString()).ToList();
|
||||||
|
|
||||||
|
// Add additional platforms that are not part of BuildTarget enum.
|
||||||
|
platformNames.Add("Server");
|
||||||
|
|
||||||
|
return platformNames.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool TryDisableOverrides(TextureImporter importer, out List<string> disabledPlatforms) {
|
||||||
|
IEnumerable<string> platforms = GetAllPossiblePlatforms();
|
||||||
|
disabledPlatforms = new List<string>();
|
||||||
|
|
||||||
|
foreach (string platform in platforms) {
|
||||||
|
var platformSettings = importer.GetPlatformTextureSettings(platform);
|
||||||
|
|
||||||
|
if (!platformSettings.overridden) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
disabledPlatforms.Add(platform);
|
||||||
|
platformSettings.overridden = false;
|
||||||
|
importer.SetPlatformTextureSettings(platformSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (disabledPlatforms.Count <= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
importer.SaveAndReimport();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void EnableOverrides(TextureImporter importer, List<string> platformsToEnable) {
|
||||||
|
if (platformsToEnable.Count == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (string platform in platformsToEnable) {
|
||||||
|
var platformSettings = importer.GetPlatformTextureSettings(platform);
|
||||||
|
platformSettings.overridden = true;
|
||||||
|
importer.SetPlatformTextureSettings(platformSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
importer.SaveAndReimport();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d7e6bbfca422433c9e60e78930eae065
|
||||||
|
timeCreated: 1708382726
|
||||||
Loading…
x
Reference in New Issue
Block a user