|
@@ -658,7 +658,6 @@ namespace Spine.Unity.Editor {
|
|
|
foreach (Material m in atlasAsset.materials)
|
|
|
vestigialMaterials.Add(m);
|
|
|
}
|
|
|
-
|
|
|
protectFromStackGarbageCollection.Add(atlasAsset);
|
|
|
atlasAsset.atlasFile = atlasText;
|
|
|
|
|
@@ -669,6 +668,7 @@ namespace Spine.Unity.Editor {
|
|
|
foreach (AtlasPage page in atlas.Pages)
|
|
|
pageFiles.Add(page.name);
|
|
|
}
|
|
|
+ bool atlasHasCustomMaterials = HasCustomMaterialsAssigned(vestigialMaterials, primaryName, pageFiles);
|
|
|
|
|
|
List<Material> populatingMaterials = new List<Material>(pageFiles.Count);
|
|
|
string materialDirectory = GetMaterialDirectory(assetPath, vestigialMaterials);
|
|
@@ -685,12 +685,8 @@ namespace Spine.Unity.Editor {
|
|
|
}
|
|
|
|
|
|
string pageName = Path.GetFileNameWithoutExtension(pageFiles[i]);
|
|
|
-
|
|
|
- //because this looks silly
|
|
|
- if (pageName == primaryName && pageFiles.Count == 1)
|
|
|
- pageName = "Material";
|
|
|
-
|
|
|
- string materialPath = materialDirectory + "/" + primaryName + "_" + pageName + ".mat";
|
|
|
+ string materialFileName = GetPageMaterialName(primaryName, pageName, pageFiles) + ".mat";
|
|
|
+ string materialPath = materialDirectory + "/" + materialFileName;
|
|
|
Material material = (Material)AssetDatabase.LoadAssetAtPath(materialPath, typeof(Material));
|
|
|
if (material == null) {
|
|
|
Shader defaultShader = GetDefaultShader();
|
|
@@ -714,10 +710,11 @@ namespace Spine.Unity.Editor {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- atlasAsset.materials = populatingMaterials.ToArray();
|
|
|
-
|
|
|
- for (int i = 0; i < vestigialMaterials.Count; i++)
|
|
|
- AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(vestigialMaterials[i]));
|
|
|
+ if (!atlasHasCustomMaterials) {
|
|
|
+ atlasAsset.materials = populatingMaterials.ToArray();
|
|
|
+ for (int i = 0; i < vestigialMaterials.Count; i++)
|
|
|
+ AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(vestigialMaterials[i]));
|
|
|
+ }
|
|
|
|
|
|
if (AssetDatabase.GetAssetPath(atlasAsset) == "")
|
|
|
AssetDatabase.CreateAsset(atlasAsset, atlasPath);
|
|
@@ -727,9 +724,14 @@ 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), atlasAsset);
|
|
|
- else
|
|
|
+ if (pageFiles.Count != atlasAsset.materials.Length) {
|
|
|
+ if (atlasHasCustomMaterials)
|
|
|
+ Debug.LogWarning(string.Format("{0} :: Found custom materials at atlas asset, but atlas page count " +
|
|
|
+ "changed. Please update the Materials list accordingly.", atlasAsset.name), atlasAsset);
|
|
|
+ else
|
|
|
+ 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), atlasAsset);
|
|
|
+ } else
|
|
|
Debug.Log(string.Format("{0} :: Imported with {1} material", atlasAsset.name, atlasAsset.materials.Length), atlasAsset);
|
|
|
|
|
|
// Iterate regions and bake marked.
|
|
@@ -766,6 +768,15 @@ namespace Spine.Unity.Editor {
|
|
|
return loadedAtlas != null ? loadedAtlas : atlasAsset;
|
|
|
}
|
|
|
|
|
|
+ static bool HasCustomMaterialsAssigned (List<Material> vestigialMaterials, string primaryName, List<string> pageFiles) {
|
|
|
+ if (pageFiles.Count == 0 || vestigialMaterials.Count == 0)
|
|
|
+ return false;
|
|
|
+
|
|
|
+ string firstPageName = Path.GetFileNameWithoutExtension(pageFiles[0]);
|
|
|
+ string defaultMaterialName = GetPageMaterialName(primaryName, firstPageName, pageFiles);
|
|
|
+ return vestigialMaterials[0].name != defaultMaterialName;
|
|
|
+ }
|
|
|
+
|
|
|
public static Shader GetDefaultShader () {
|
|
|
Shader shader = Shader.Find(SpineEditorUtilities.Preferences.DefaultShader);
|
|
|
if (shader == null) shader = Shader.Find("Spine/Skeleton");
|
|
@@ -928,6 +939,13 @@ namespace Spine.Unity.Editor {
|
|
|
return (AtlasAssetBase)AssetDatabase.LoadAssetAtPath(atlasPath, typeof(AtlasAssetBase));
|
|
|
}
|
|
|
|
|
|
+ static string GetPageMaterialName (string primaryName, string pageName, List<string> pageFiles) {
|
|
|
+ // use skeleton_Material.mat instead of skeleton_skeleton.mat if we have just a single atlas page
|
|
|
+ if (pageName == primaryName && pageFiles.Count == 1)
|
|
|
+ pageName = "Material";
|
|
|
+ return primaryName + "_" + pageName;
|
|
|
+ }
|
|
|
+
|
|
|
static string GetMaterialDirectory (string assetPath, List<Material> previousMaterials) {
|
|
|
if (previousMaterials.Count > 0 && previousMaterials[0] != null) {
|
|
|
string materialPath = AssetDatabase.GetAssetPath(previousMaterials[0]);
|