mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[unity] Hopefully fixed some occurrances of a build crash when building many prefabs and textures. See #2047.
This commit is contained in:
parent
b23ff3b216
commit
ec53964603
@ -71,62 +71,83 @@ namespace Spine.Unity.Editor {
|
|||||||
|
|
||||||
#if HAS_ON_POSTPROCESS_PREFAB
|
#if HAS_ON_POSTPROCESS_PREFAB
|
||||||
internal static void PreprocessSpinePrefabMeshes () {
|
internal static void PreprocessSpinePrefabMeshes () {
|
||||||
AssetDatabase.StartAssetEditing();
|
BuildUtilities.IsInSkeletonAssetBuildPreProcessing = true;
|
||||||
prefabsToRestore.Clear();
|
try {
|
||||||
var prefabAssets = AssetDatabase.FindAssets("t:Prefab");
|
AssetDatabase.StartAssetEditing();
|
||||||
foreach (var asset in prefabAssets) {
|
prefabsToRestore.Clear();
|
||||||
string assetPath = AssetDatabase.GUIDToAssetPath(asset);
|
var prefabAssets = AssetDatabase.FindAssets("t:Prefab");
|
||||||
GameObject prefabGameObject = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
|
foreach (var asset in prefabAssets) {
|
||||||
if (SpineEditorUtilities.CleanupSpinePrefabMesh(prefabGameObject)) {
|
string assetPath = AssetDatabase.GUIDToAssetPath(asset);
|
||||||
prefabsToRestore.Add(assetPath);
|
GameObject prefabGameObject = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
|
||||||
|
if (SpineEditorUtilities.CleanupSpinePrefabMesh(prefabGameObject)) {
|
||||||
|
prefabsToRestore.Add(assetPath);
|
||||||
|
}
|
||||||
|
EditorUtility.UnloadUnusedAssetsImmediate();
|
||||||
}
|
}
|
||||||
EditorUtility.UnloadUnusedAssetsImmediate();
|
AssetDatabase.StopAssetEditing();
|
||||||
|
if (prefabAssets.Length > 0)
|
||||||
|
AssetDatabase.SaveAssets();
|
||||||
|
} finally {
|
||||||
|
BuildUtilities.IsInSkeletonAssetBuildPreProcessing = false;
|
||||||
}
|
}
|
||||||
AssetDatabase.StopAssetEditing();
|
|
||||||
if (prefabAssets.Length > 0)
|
|
||||||
AssetDatabase.SaveAssets();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void PostprocessSpinePrefabMeshes () {
|
internal static void PostprocessSpinePrefabMeshes () {
|
||||||
foreach (string assetPath in prefabsToRestore) {
|
BuildUtilities.IsInSkeletonAssetBuildPostProcessing = true;
|
||||||
GameObject g = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
|
try {
|
||||||
SpineEditorUtilities.SetupSpinePrefabMesh(g, null);
|
foreach (string assetPath in prefabsToRestore) {
|
||||||
|
GameObject g = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
|
||||||
|
SpineEditorUtilities.SetupSpinePrefabMesh(g, null);
|
||||||
|
}
|
||||||
|
if (prefabsToRestore.Count > 0)
|
||||||
|
AssetDatabase.SaveAssets();
|
||||||
|
prefabsToRestore.Clear();
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
BuildUtilities.IsInSkeletonAssetBuildPostProcessing = false;
|
||||||
}
|
}
|
||||||
if (prefabsToRestore.Count > 0)
|
|
||||||
AssetDatabase.SaveAssets();
|
|
||||||
prefabsToRestore.Clear();
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
internal static void PreprocessSpriteAtlases () {
|
internal static void PreprocessSpriteAtlases () {
|
||||||
AssetDatabase.StartAssetEditing();
|
BuildUtilities.IsInSpriteAtlasBuildPreProcessing = true;
|
||||||
spriteAtlasTexturesToRestore.Clear();
|
try {
|
||||||
var spriteAtlasAssets = AssetDatabase.FindAssets("t:SpineSpriteAtlasAsset");
|
AssetDatabase.StartAssetEditing();
|
||||||
foreach (var asset in spriteAtlasAssets) {
|
spriteAtlasTexturesToRestore.Clear();
|
||||||
string assetPath = AssetDatabase.GUIDToAssetPath(asset);
|
var spriteAtlasAssets = AssetDatabase.FindAssets("t:SpineSpriteAtlasAsset");
|
||||||
SpineSpriteAtlasAsset atlasAsset = AssetDatabase.LoadAssetAtPath<SpineSpriteAtlasAsset>(assetPath);
|
foreach (var asset in spriteAtlasAssets) {
|
||||||
if (atlasAsset && atlasAsset.materials.Length > 0) {
|
string assetPath = AssetDatabase.GUIDToAssetPath(asset);
|
||||||
spriteAtlasTexturesToRestore[assetPath] = AssetDatabase.GetAssetPath(atlasAsset.materials[0].mainTexture);
|
SpineSpriteAtlasAsset atlasAsset = AssetDatabase.LoadAssetAtPath<SpineSpriteAtlasAsset>(assetPath);
|
||||||
atlasAsset.materials[0].mainTexture = null;
|
if (atlasAsset && atlasAsset.materials.Length > 0) {
|
||||||
|
spriteAtlasTexturesToRestore[assetPath] = AssetDatabase.GetAssetPath(atlasAsset.materials[0].mainTexture);
|
||||||
|
atlasAsset.materials[0].mainTexture = null;
|
||||||
|
}
|
||||||
|
EditorUtility.UnloadUnusedAssetsImmediate();
|
||||||
}
|
}
|
||||||
EditorUtility.UnloadUnusedAssetsImmediate();
|
AssetDatabase.StopAssetEditing();
|
||||||
|
if (spriteAtlasAssets.Length > 0)
|
||||||
|
AssetDatabase.SaveAssets();
|
||||||
|
} finally {
|
||||||
|
BuildUtilities.IsInSpriteAtlasBuildPreProcessing = false;
|
||||||
}
|
}
|
||||||
AssetDatabase.StopAssetEditing();
|
|
||||||
if (spriteAtlasAssets.Length > 0)
|
|
||||||
AssetDatabase.SaveAssets();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void PostprocessSpriteAtlases () {
|
internal static void PostprocessSpriteAtlases () {
|
||||||
foreach (var pair in spriteAtlasTexturesToRestore) {
|
BuildUtilities.IsInSpriteAtlasBuildPostProcessing = true;
|
||||||
string assetPath = pair.Key;
|
try {
|
||||||
SpineSpriteAtlasAsset atlasAsset = AssetDatabase.LoadAssetAtPath<SpineSpriteAtlasAsset>(assetPath);
|
foreach (var pair in spriteAtlasTexturesToRestore) {
|
||||||
if (atlasAsset && atlasAsset.materials.Length > 0) {
|
string assetPath = pair.Key;
|
||||||
Texture atlasTexture = AssetDatabase.LoadAssetAtPath<Texture>(pair.Value);
|
SpineSpriteAtlasAsset atlasAsset = AssetDatabase.LoadAssetAtPath<SpineSpriteAtlasAsset>(assetPath);
|
||||||
atlasAsset.materials[0].mainTexture = atlasTexture;
|
if (atlasAsset && atlasAsset.materials.Length > 0) {
|
||||||
|
Texture atlasTexture = AssetDatabase.LoadAssetAtPath<Texture>(pair.Value);
|
||||||
|
atlasAsset.materials[0].mainTexture = atlasTexture;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (spriteAtlasTexturesToRestore.Count > 0)
|
||||||
|
AssetDatabase.SaveAssets();
|
||||||
|
spriteAtlasTexturesToRestore.Clear();
|
||||||
|
} finally {
|
||||||
|
BuildUtilities.IsInSpriteAtlasBuildPostProcessing = false;
|
||||||
}
|
}
|
||||||
if (spriteAtlasTexturesToRestore.Count > 0)
|
|
||||||
AssetDatabase.SaveAssets();
|
|
||||||
spriteAtlasTexturesToRestore.Clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -238,6 +238,11 @@ namespace Spine.Unity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Load (AtlasPage page, string path) {
|
public void Load (AtlasPage page, string path) {
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
if (BuildUtilities.IsInSkeletonAssetBuildPreProcessing ||
|
||||||
|
BuildUtilities.IsInSkeletonAssetBuildPostProcessing)
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
String name = Path.GetFileNameWithoutExtension(path);
|
String name = Path.GetFileNameWithoutExtension(path);
|
||||||
Material material = null;
|
Material material = null;
|
||||||
foreach (Material other in atlasAsset.materials) {
|
foreach (Material other in atlasAsset.materials) {
|
||||||
|
|||||||
@ -166,6 +166,10 @@ namespace Spine.Unity {
|
|||||||
public override void Initialize (bool overwrite, bool quiet = false) {
|
public override void Initialize (bool overwrite, bool quiet = false) {
|
||||||
if (valid && !overwrite)
|
if (valid && !overwrite)
|
||||||
return;
|
return;
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
if (BuildUtilities.IsInSkeletonAssetBuildPreProcessing)
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
base.Initialize(overwrite, quiet);
|
base.Initialize(overwrite, quiet);
|
||||||
|
|
||||||
if (!valid)
|
if (!valid)
|
||||||
|
|||||||
@ -102,7 +102,7 @@ namespace Spine.Unity {
|
|||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
protected override void OnValidate () {
|
protected override void OnValidate () {
|
||||||
// This handles Scene View preview.
|
// This handles Scene View preview.
|
||||||
base.OnValidate ();
|
base.OnValidate();
|
||||||
if (this.IsValid) {
|
if (this.IsValid) {
|
||||||
if (skeletonDataAsset == null) {
|
if (skeletonDataAsset == null) {
|
||||||
Clear();
|
Clear();
|
||||||
@ -360,8 +360,7 @@ namespace Spine.Unity {
|
|||||||
separatorSlots.Add(slot);
|
separatorSlots.Add(slot);
|
||||||
}
|
}
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
Debug.LogWarning(slotName + " is not a slot in " + skeletonDataAsset.skeletonJSON.name);
|
Debug.LogWarning(slotName + " is not a slot in " + skeletonDataAsset.skeletonJSON.name);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -521,7 +520,10 @@ namespace Spine.Unity {
|
|||||||
|
|
||||||
public void Initialize (bool overwrite) {
|
public void Initialize (bool overwrite) {
|
||||||
if (this.IsValid && !overwrite) return;
|
if (this.IsValid && !overwrite) return;
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
if (BuildUtilities.IsInSkeletonAssetBuildPreProcessing)
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
if (this.skeletonDataAsset == null) return;
|
if (this.skeletonDataAsset == null) return;
|
||||||
var skeletonData = this.skeletonDataAsset.GetSkeletonData(false);
|
var skeletonData = this.skeletonDataAsset.GetSkeletonData(false);
|
||||||
if (skeletonData == null) return;
|
if (skeletonData == null) return;
|
||||||
@ -839,7 +841,7 @@ namespace Spine.Unity {
|
|||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
if (Application.isEditor && !Application.isPlaying) {
|
if (Application.isEditor && !Application.isPlaying) {
|
||||||
for (int i = separatorParts.Count-1; i >= 0; --i) {
|
for (int i = separatorParts.Count - 1; i >= 0; --i) {
|
||||||
if (separatorParts[i] == null) {
|
if (separatorParts[i] == null) {
|
||||||
separatorParts.RemoveAt(i);
|
separatorParts.RemoveAt(i);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -72,7 +72,10 @@ namespace Spine.Unity {
|
|||||||
public override void Initialize (bool overwrite, bool quiet = false) {
|
public override void Initialize (bool overwrite, bool quiet = false) {
|
||||||
if (valid && !overwrite)
|
if (valid && !overwrite)
|
||||||
return;
|
return;
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
if (BuildUtilities.IsInSkeletonAssetBuildPreProcessing)
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
base.Initialize(overwrite, quiet);
|
base.Initialize(overwrite, quiet);
|
||||||
|
|
||||||
if (!valid)
|
if (!valid)
|
||||||
@ -104,8 +107,7 @@ namespace Spine.Unity {
|
|||||||
|
|
||||||
if (Application.isPlaying) {
|
if (Application.isPlaying) {
|
||||||
translator.Apply(skeleton);
|
translator.Apply(skeleton);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (translatorAnimator != null && translatorAnimator.isInitialized &&
|
if (translatorAnimator != null && translatorAnimator.isInitialized &&
|
||||||
translatorAnimator.isActiveAndEnabled && translatorAnimator.runtimeAnimatorController != null) {
|
translatorAnimator.isActiveAndEnabled && translatorAnimator.runtimeAnimatorController != null) {
|
||||||
// Note: Rebind is required to prevent warning "Animator is not playing an AnimatorController" with prefabs
|
// Note: Rebind is required to prevent warning "Animator is not playing an AnimatorController" with prefabs
|
||||||
@ -535,7 +537,7 @@ namespace Spine.Unity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
void GetLayerBlendModes() {
|
void GetLayerBlendModes () {
|
||||||
if (layerBlendModes.Length < animator.layerCount) {
|
if (layerBlendModes.Length < animator.layerCount) {
|
||||||
System.Array.Resize<MixBlend>(ref layerBlendModes, animator.layerCount);
|
System.Array.Resize<MixBlend>(ref layerBlendModes, animator.layerCount);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -367,7 +367,10 @@ namespace Spine.Unity {
|
|||||||
public virtual void Initialize (bool overwrite, bool quiet = false) {
|
public virtual void Initialize (bool overwrite, bool quiet = false) {
|
||||||
if (valid && !overwrite)
|
if (valid && !overwrite)
|
||||||
return;
|
return;
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
if (BuildUtilities.IsInSkeletonAssetBuildPreProcessing)
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
// Clear
|
// Clear
|
||||||
{
|
{
|
||||||
// Note: do not reset meshFilter.sharedMesh or meshRenderer.sharedMaterial to null,
|
// Note: do not reset meshFilter.sharedMesh or meshRenderer.sharedMaterial to null,
|
||||||
|
|||||||
@ -0,0 +1,42 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Spine Runtimes License Agreement
|
||||||
|
* Last updated January 1, 2020. Replaces all prior versions.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013-2022, Esoteric Software LLC
|
||||||
|
*
|
||||||
|
* Integration of the Spine Runtimes into software or otherwise creating
|
||||||
|
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||||
|
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||||
|
* http://esotericsoftware.com/spine-editor-license
|
||||||
|
*
|
||||||
|
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||||
|
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||||
|
* "Products"), provided that each user of the Products must obtain their own
|
||||||
|
* Spine Editor license and redistribution of the Products in any form must
|
||||||
|
* include this license and copyright notice.
|
||||||
|
*
|
||||||
|
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
|
||||||
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
|
||||||
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
|
||||||
|
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
|
||||||
|
namespace Spine.Unity {
|
||||||
|
|
||||||
|
public static class BuildUtilities {
|
||||||
|
public static bool IsInSkeletonAssetBuildPreProcessing = false;
|
||||||
|
public static bool IsInSkeletonAssetBuildPostProcessing = false;
|
||||||
|
public static bool IsInSpriteAtlasBuildPreProcessing = false;
|
||||||
|
public static bool IsInSpriteAtlasBuildPostProcessing = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a2f1169aaf0063f4da1c2b6033bbc13f
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Loading…
x
Reference in New Issue
Block a user