Преглед изворни кода

[unity] Add warnings for renamed atlas pages.

John пре 8 година
родитељ
комит
6b0f88cb7d
1 измењених фајлова са 14 додато и 3 уклоњено
  1. 14 3
      spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs

+ 14 - 3
spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs

@@ -1020,13 +1020,18 @@ namespace Spine.Unity.Editor {
 					pageFiles.Add(atlasLines[i + 1].Trim());
 			}
 
-			atlasAsset.materials = new Material[pageFiles.Count];
+			var populatingMaterials = new List<Material>(pageFiles.Count);//atlasAsset.materials = new Material[pageFiles.Count];
 
 			for (int i = 0; i < pageFiles.Count; i++) {
 				string texturePath = assetPath + "/" + pageFiles[i];
 				Texture2D texture = (Texture2D)AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D));
 
 				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));
+					continue;
+				}
+
 				#if UNITY_5_5_OR_NEWER
 				texImporter.textureCompression = TextureImporterCompression.Uncompressed;
 				texImporter.alphaSource = TextureImporterAlphaSource.FromInput;
@@ -1039,7 +1044,6 @@ namespace Spine.Unity.Editor {
 				texImporter.spriteImportMode = SpriteImportMode.None;
 				texImporter.maxTextureSize = 2048;
 
-
 				EditorUtility.SetDirty(texImporter);
 				AssetDatabase.ImportAsset(texturePath);
 				AssetDatabase.SaveAssets();
@@ -1064,9 +1068,11 @@ namespace Spine.Unity.Editor {
 				EditorUtility.SetDirty(mat);
 				AssetDatabase.SaveAssets();
 
-				atlasAsset.materials[i] = mat;
+				populatingMaterials.Add(mat); //atlasAsset.materials[i] = mat;
 			}
 
+			atlasAsset.materials = populatingMaterials.ToArray();
+
 			for (int i = 0; i < vestigialMaterials.Count; i++)
 				AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(vestigialMaterials[i]));
 
@@ -1078,6 +1084,11 @@ namespace Spine.Unity.Editor {
 			EditorUtility.SetDirty(atlasAsset);
 			AssetDatabase.SaveAssets();
 
+			if (pageFiles.Count != atlasAsset.materials.Length)
+				Debug.LogWarning(string.Format("{0} ::: Not all atlas pages were imported. If you rename your image files, please make sure you also edit the filenames specified in the atlas file.", atlasAsset.name));
+			else
+				Debug.Log(string.Format("{0} ::: Imported with {1} material", atlasAsset.name, atlasAsset.materials.Length));
+
 			// Iterate regions and bake marked.
 			Atlas atlas = atlasAsset.GetAtlas();
 			FieldInfo field = typeof(Atlas).GetField("regions", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.NonPublic);