[unity] Unity SpriteAtlas Support: Removed unnecessary material reference to generated editor atlas texture in pre-build step. See #1900.

This commit is contained in:
Harald Csaszar 2022-02-15 14:52:29 +01:00
parent ece6530b0c
commit dcb593489b

View File

@ -51,31 +51,73 @@ namespace Spine.Unity.Editor {
#if HAS_ON_POSTPROCESS_PREFAB #if HAS_ON_POSTPROCESS_PREFAB
static List<string> prefabsToRestore = new List<string>(); static List<string> prefabsToRestore = new List<string>();
#endif #endif
static Dictionary<string, Texture> spriteAtlasTexturesToRestore = new Dictionary<string, Texture>();
internal static void PreprocessBuild () { internal static void PreprocessBuild () {
isBuilding = true; isBuilding = true;
#if HAS_ON_POSTPROCESS_PREFAB #if HAS_ON_POSTPROCESS_PREFAB
var assets = AssetDatabase.FindAssets("t:Prefab"); PreprocessSpinePrefabMeshes();
foreach(var asset in assets) { #endif
PreprocessSpriteAtlases();
}
internal static void PostprocessBuild () {
isBuilding = false;
#if HAS_ON_POSTPROCESS_PREFAB
PostprocessSpinePrefabMeshes();
#endif
PostprocessSpriteAtlases();
}
#if HAS_ON_POSTPROCESS_PREFAB
internal static void PreprocessSpinePrefabMeshes () {
var prefabAssets = AssetDatabase.FindAssets("t:Prefab");
foreach (var asset in prefabAssets) {
string assetPath = AssetDatabase.GUIDToAssetPath(asset); string assetPath = AssetDatabase.GUIDToAssetPath(asset);
GameObject g = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath); GameObject g = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
if (SpineEditorUtilities.CleanupSpinePrefabMesh(g)) { if (SpineEditorUtilities.CleanupSpinePrefabMesh(g)) {
prefabsToRestore.Add(assetPath); prefabsToRestore.Add(assetPath);
} }
} }
AssetDatabase.SaveAssets(); if (prefabAssets.Length > 0)
#endif AssetDatabase.SaveAssets();
} }
internal static void PostprocessBuild () { internal static void PostprocessSpinePrefabMeshes () {
isBuilding = false;
#if HAS_ON_POSTPROCESS_PREFAB
foreach (string assetPath in prefabsToRestore) { foreach (string assetPath in prefabsToRestore) {
GameObject g = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath); GameObject g = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
SpineEditorUtilities.SetupSpinePrefabMesh(g, null); SpineEditorUtilities.SetupSpinePrefabMesh(g, null);
} }
AssetDatabase.SaveAssets(); if (prefabsToRestore.Count > 0)
AssetDatabase.SaveAssets();
prefabsToRestore.Clear();
}
#endif #endif
internal static void PreprocessSpriteAtlases () {
var spriteAtlasAssets = AssetDatabase.FindAssets("t:SpineSpriteAtlasAsset");
foreach (var asset in spriteAtlasAssets) {
string assetPath = AssetDatabase.GUIDToAssetPath(asset);
SpineSpriteAtlasAsset atlasAsset = AssetDatabase.LoadAssetAtPath<SpineSpriteAtlasAsset>(assetPath);
if (atlasAsset && atlasAsset.materials.Length > 0) {
spriteAtlasTexturesToRestore[assetPath] = atlasAsset.materials[0].mainTexture;
atlasAsset.materials[0].mainTexture = null;
}
}
if (spriteAtlasAssets.Length > 0)
AssetDatabase.SaveAssets();
}
internal static void PostprocessSpriteAtlases () {
foreach (var pair in spriteAtlasTexturesToRestore) {
string assetPath = pair.Key;
SpineSpriteAtlasAsset atlasAsset = AssetDatabase.LoadAssetAtPath<SpineSpriteAtlasAsset>(assetPath);
if (atlasAsset && atlasAsset.materials.Length > 0) {
atlasAsset.materials[0].mainTexture = pair.Value;
}
}
if (spriteAtlasTexturesToRestore.Count > 0)
AssetDatabase.SaveAssets();
spriteAtlasTexturesToRestore.Clear();
} }
} }
@ -90,8 +132,7 @@ namespace Spine.Unity.Editor {
get { return -2000; } get { return -2000; }
} }
#if HAS_BUILD_PROCESS_WITH_REPORT #if HAS_BUILD_PROCESS_WITH_REPORT
void IPreprocessBuildWithReport.OnPreprocessBuild(BuildReport report) void IPreprocessBuildWithReport.OnPreprocessBuild (BuildReport report) {
{
SpineBuildProcessor.PreprocessBuild(); SpineBuildProcessor.PreprocessBuild();
} }
#else #else
@ -114,8 +155,7 @@ namespace Spine.Unity.Editor {
#if HAS_BUILD_PROCESS_WITH_REPORT #if HAS_BUILD_PROCESS_WITH_REPORT
void IPostprocessBuildWithReport.OnPostprocessBuild(BuildReport report) void IPostprocessBuildWithReport.OnPostprocessBuild (BuildReport report) {
{
SpineBuildProcessor.PostprocessBuild(); SpineBuildProcessor.PostprocessBuild();
} }
#else #else