diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Asset Types/SkeletonDataAssetInspector.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Asset Types/SkeletonDataAssetInspector.cs index 21aaace86..a74b2b359 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Asset Types/SkeletonDataAssetInspector.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Asset Types/SkeletonDataAssetInspector.cs @@ -659,7 +659,7 @@ namespace Spine.Unity.Editor { } void DoReimport () { - AssetUtility.ImportSpineContent(new [] { AssetDatabase.GetAssetPath(skeletonJSON.objectReferenceValue) }, true); + AssetUtility.ImportSpineContent(new [] { AssetDatabase.GetAssetPath(skeletonJSON.objectReferenceValue) }, null, true); preview.Clear(); InitializeEditor(); EditorUtility.SetDirty(targetSkeletonDataAsset); diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs index 1dab19b49..939a93ed2 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs @@ -65,7 +65,7 @@ namespace Spine.Unity.Editor { public static readonly List protectFromStackGarbageCollection = new List(); public static HashSet assetsImportedInWrongState = new HashSet(); - public static void HandleOnPostprocessAllAssets (string[] imported) { + public static void HandleOnPostprocessAllAssets (string[] imported, List texturesWithoutMetaFile) { // In case user used "Assets -> Reimport All", during the import process, // asset database is not initialized until some point. During that period, // all attempts to load any assets using API (i.e. AssetDatabase.LoadAssetAtPath) @@ -87,7 +87,7 @@ namespace Spine.Unity.Editor { if (AssetDatabaseAvailabilityDetector.IsAssetDatabaseAvailable()) { string[] combinedAssets = AssetUtility.assetsImportedInWrongState.ToArray(); AssetUtility.assetsImportedInWrongState.Clear(); - AssetUtility.ImportSpineContent(combinedAssets); + AssetUtility.ImportSpineContent(combinedAssets, texturesWithoutMetaFile); } } @@ -243,7 +243,9 @@ namespace Spine.Unity.Editor { } #endregion - public static void ImportSpineContent (string[] imported, bool reimport = false) { + public static void ImportSpineContent (string[] imported, List texturesWithoutMetaFile, + bool reimport = false) { + var atlasPaths = new List(); var imagePaths = new List(); var skeletonPaths = new List(); @@ -285,7 +287,7 @@ namespace Spine.Unity.Editor { if (ap.StartsWith("Packages")) continue; TextAsset atlasText = AssetDatabase.LoadAssetAtPath(ap); - AtlasAssetBase atlas = IngestSpineAtlas(atlasText); + AtlasAssetBase atlas = IngestSpineAtlas(atlasText, texturesWithoutMetaFile); atlases.Add(atlas); } @@ -428,7 +430,7 @@ namespace Spine.Unity.Editor { return arr; } - static AtlasAssetBase IngestSpineAtlas (TextAsset atlasText) { + static AtlasAssetBase IngestSpineAtlas (TextAsset atlasText, List texturesWithoutMetaFile) { if (atlasText == null) { Debug.LogWarning("Atlas source cannot be null!"); return null; @@ -469,8 +471,9 @@ namespace Spine.Unity.Editor { for (int i = 0; i < pageFiles.Count; i++) { string texturePath = assetPath + "/" + pageFiles[i]; Texture2D texture = (Texture2D)AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D)); - if (SpineEditorUtilities.Preferences.setTextureImporterSettings) { - SetDefaultTextureSettingsIfNew(texturePath, atlasAsset); + bool textureIsUninitialized = texturesWithoutMetaFile != null && texturesWithoutMetaFile.Contains(texturePath); + if (SpineEditorUtilities.Preferences.setTextureImporterSettings && textureIsUninitialized) { + SetDefaultTextureSettings(texturePath, atlasAsset); } string pageName = Path.GetFileNameWithoutExtension(pageFiles[i]); @@ -546,27 +549,13 @@ namespace Spine.Unity.Editor { return (AtlasAssetBase)AssetDatabase.LoadAssetAtPath(atlasPath, typeof(AtlasAssetBase)); } - static bool SetDefaultTextureSettingsIfNew (string texturePath, SpineAtlasAsset atlasAsset) { + static bool SetDefaultTextureSettings (string texturePath, SpineAtlasAsset atlasAsset) { TextureImporter texImporter = (TextureImporter)TextureImporter.GetAtPath(texturePath); if (texImporter == null) { Debug.LogWarning(string.Format("{0}: Texture asset \"{1}\" not found. Skipping. Please check your atlas file for renamed files.", atlasAsset.name, texturePath)); return false; } - #if UNITY_2018_1_OR_NEWER - bool customTextureSettingsExist = !texImporter.importSettingsMissing; - #else - // unfortunately, importSettingsMissing is not available in Unity 2017, - // so we check if any settings deviate from Unity's default texture settings. - bool customTextureSettingsExist = texImporter.mipmapEnabled != true || - texImporter.maxTextureSize != 2048 || - texImporter.alphaIsTransparency != true || - texImporter.wrapMode != TextureWrapMode.Repeat || - texImporter.filterMode != FilterMode.Bilinear; - #endif - if (customTextureSettingsExist) - return false; - texImporter.textureCompression = TextureImporterCompression.Uncompressed; texImporter.alphaSource = TextureImporterAlphaSource.FromInput; texImporter.mipmapEnabled = false; diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineEditorUtilities.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineEditorUtilities.cs index 3e89893cf..5f7cac9e4 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineEditorUtilities.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineEditorUtilities.cs @@ -65,13 +65,27 @@ namespace Spine.Unity.Editor { public static string editorPath = ""; public static string editorGUIPath = ""; public static bool initialized; + private static List texturesWithoutMetaFile = new List(); - // Auto-import entry point + // Auto-import entry point for textures + void OnPreprocessTexture () { + #if UNITY_2018_1_OR_NEWER + bool customTextureSettingsExist = !assetImporter.importSettingsMissing; + #else + bool customTextureSettingsExist = System.IO.File.Exists(assetImporter.assetPath + ".meta"); + #endif + if (!customTextureSettingsExist) { + texturesWithoutMetaFile.Add(assetImporter.assetPath); + } + } + + // Auto-import post process entry point for all assets static void OnPostprocessAllAssets (string[] imported, string[] deleted, string[] moved, string[] movedFromAssetPaths) { if (imported.Length == 0) return; - AssetUtility.HandleOnPostprocessAllAssets(imported); + AssetUtility.HandleOnPostprocessAllAssets(imported, texturesWithoutMetaFile); + texturesWithoutMetaFile.Clear(); } #region Initialization