private static void OnSpritePrefabPostprocess( ) { EditorApplication.delayCall -= OnSpritePrefabPostprocess; try { Uni2DAssetPostprocessor.LockTo(false); foreach (string rGameObjectPrefabGUID in ms_oGameObjectGUIDsToPostProcess) { GameObject rGameObjectPrefab = Uni2DEditorUtils.GetAssetFromUnityGUID <GameObject>(rGameObjectPrefabGUID); if (rGameObjectPrefab != null) { //Debug.Log ( "Post processing game object prefab " + rGameObjectPrefabGUID ); Uni2DEditorSpriteBuilderUtils.OnPrefabPostProcess(rGameObjectPrefab); rGameObjectPrefab = null; EditorUtility.UnloadUnusedAssets( ); } } } finally { ms_oGameObjectGUIDsToPostProcess.Clear( ); Uni2DAssetPostprocessor.Unlock( ); Uni2DAssetPostprocessor.Enabled = true; } }
public static void ForceImportAssetIfLocked(string a_rAssetPath, ImportAssetOptions a_eImportOptions) { bool bWasLocked = ms_bLocked; bool bPreviousValue = ms_bEnabled; if (bWasLocked) { Uni2DAssetPostprocessor.Unlock( ); } Uni2DAssetPostprocessor.Enabled = true; { AssetDatabase.ImportAsset(a_rAssetPath, a_eImportOptions); } if (bWasLocked) { Uni2DAssetPostprocessor.LockTo(bPreviousValue); } else { Uni2DAssetPostprocessor.Enabled = bPreviousValue; } }
private static void UpdateUni2DAssets( ) { EditorApplication.delayCall -= UpdateUni2DAssets; Uni2DEditorAssetTable rAssetTable = Uni2DEditorAssetTable.Instance; try { Uni2DAssetPostprocessor.LockTo(false); // Update animation clips first, because they can change the atlases foreach (string rAnimationClipGUID in ms_oAnimationClipGUIDsToUpdate) { Uni2DAnimationClip rAnimationClip = Uni2DEditorUtils.GetAssetFromUnityGUID <Uni2DAnimationClip>(rAnimationClipGUID); if (rAnimationClip != null) { //Debug.Log ( "Updating clip " + rAnimationClipGUID ); rAnimationClip.OnTexturesChange(ms_oImportedTextureGUIDs); rAnimationClip = null; EditorUtility.UnloadUnusedAssets( ); } else { // Clean asset table foreach (string rTextureGUID in ms_oImportedTextureGUIDs) { rAssetTable.RemoveClipUsingTexture(rAnimationClipGUID, rTextureGUID); } } } foreach (string rAtlasGUID in ms_oAtlasGUIDsToUpdate) { Uni2DTextureAtlas rAtlas = Uni2DEditorUtils.GetAssetFromUnityGUID <Uni2DTextureAtlas>(rAtlasGUID); if (rAtlas != null) { //Debug.Log( "Updating atlas " + rAtlasGUID ); rAtlas.OnTextureChange( ); rAtlas = null; EditorUtility.UnloadUnusedAssets( ); } else { // Clean foreach (string rTextureGUID in ms_oImportedTextureGUIDs) { rAssetTable.RemoveAtlasUsingTexture(rAtlasGUID, rTextureGUID); } } } foreach (string rSpritePrefabGUID in ms_oSpritePrefabGUIDsToUpdate) { GameObject rSpritePrefab = Uni2DEditorUtils.GetAssetFromUnityGUID <GameObject>(rSpritePrefabGUID); if (rSpritePrefab != null) { //Debug.Log( "Updating sprite prefab " + rSpritePrefabGUID ); foreach (Uni2DSprite rSpritePrefabComponent in rSpritePrefab.GetComponentsInChildren <Uni2DSprite>(true)) { Uni2DEditorSpriteSettings rSpriteSettings = rSpritePrefabComponent.SpriteSettings; string rSpriteTextureGUID = rSpriteSettings.textureContainer.GUID; string rSpriteAtlasGUID = rSpriteSettings.atlas != null?Uni2DEditorUtils.GetUnityAssetGUID(rSpriteSettings.atlas) : null; if (ms_oImportedTextureGUIDs.Contains(rSpriteTextureGUID) || (!string.IsNullOrEmpty(rSpriteAtlasGUID) && ms_oAtlasGUIDsToUpdate.Contains(rSpriteAtlasGUID))) { rSpritePrefabComponent.Regenerate(true); } EditorUtility.UnloadUnusedAssets( ); } rSpritePrefab = null; EditorUtility.UnloadUnusedAssets( ); } else { // Clean foreach (string rTextureGUID in ms_oImportedTextureGUIDs) { rAssetTable.RemoveSpritePrefabUsingTexture(rSpritePrefabGUID, rTextureGUID); } foreach (string rAtlasGUID in ms_oAtlasGUIDsToUpdate) { rAssetTable.RemoveSpritePrefabUsingAtlas(rSpritePrefabGUID, rAtlasGUID); } } } } finally { ms_oImportedTextureGUIDs.Clear( ); ms_oAtlasGUIDsToUpdate.Clear( ); ms_oAnimationClipGUIDsToUpdate.Clear( ); ms_oSpritePrefabGUIDsToUpdate.Clear( ); rAssetTable.Save( ); Uni2DAssetPostprocessor.Unlock( ); Uni2DAssetPostprocessor.Enabled = true; } }