mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[unity] Fixed assigned custom atlas page material being deleted upon reimport. Closes #2793.
This commit is contained in:
parent
4eb2cc0869
commit
8a25057510
@ -658,7 +658,6 @@ namespace Spine.Unity.Editor {
|
|||||||
foreach (Material m in atlasAsset.materials)
|
foreach (Material m in atlasAsset.materials)
|
||||||
vestigialMaterials.Add(m);
|
vestigialMaterials.Add(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
protectFromStackGarbageCollection.Add(atlasAsset);
|
protectFromStackGarbageCollection.Add(atlasAsset);
|
||||||
atlasAsset.atlasFile = atlasText;
|
atlasAsset.atlasFile = atlasText;
|
||||||
|
|
||||||
@ -669,6 +668,7 @@ namespace Spine.Unity.Editor {
|
|||||||
foreach (AtlasPage page in atlas.Pages)
|
foreach (AtlasPage page in atlas.Pages)
|
||||||
pageFiles.Add(page.name);
|
pageFiles.Add(page.name);
|
||||||
}
|
}
|
||||||
|
bool atlasHasCustomMaterials = HasCustomMaterialsAssigned(vestigialMaterials, primaryName, pageFiles);
|
||||||
|
|
||||||
List<Material> populatingMaterials = new List<Material>(pageFiles.Count);
|
List<Material> populatingMaterials = new List<Material>(pageFiles.Count);
|
||||||
string materialDirectory = GetMaterialDirectory(assetPath, vestigialMaterials);
|
string materialDirectory = GetMaterialDirectory(assetPath, vestigialMaterials);
|
||||||
@ -685,12 +685,8 @@ namespace Spine.Unity.Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
string pageName = Path.GetFileNameWithoutExtension(pageFiles[i]);
|
string pageName = Path.GetFileNameWithoutExtension(pageFiles[i]);
|
||||||
|
string materialFileName = GetPageMaterialName(primaryName, pageName, pageFiles) + ".mat";
|
||||||
//because this looks silly
|
string materialPath = materialDirectory + "/" + materialFileName;
|
||||||
if (pageName == primaryName && pageFiles.Count == 1)
|
|
||||||
pageName = "Material";
|
|
||||||
|
|
||||||
string materialPath = materialDirectory + "/" + primaryName + "_" + pageName + ".mat";
|
|
||||||
Material material = (Material)AssetDatabase.LoadAssetAtPath(materialPath, typeof(Material));
|
Material material = (Material)AssetDatabase.LoadAssetAtPath(materialPath, typeof(Material));
|
||||||
if (material == null) {
|
if (material == null) {
|
||||||
Shader defaultShader = GetDefaultShader();
|
Shader defaultShader = GetDefaultShader();
|
||||||
@ -714,10 +710,11 @@ namespace Spine.Unity.Editor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!atlasHasCustomMaterials) {
|
||||||
atlasAsset.materials = populatingMaterials.ToArray();
|
atlasAsset.materials = populatingMaterials.ToArray();
|
||||||
|
|
||||||
for (int i = 0; i < vestigialMaterials.Count; i++)
|
for (int i = 0; i < vestigialMaterials.Count; i++)
|
||||||
AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(vestigialMaterials[i]));
|
AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(vestigialMaterials[i]));
|
||||||
|
}
|
||||||
|
|
||||||
if (AssetDatabase.GetAssetPath(atlasAsset) == "")
|
if (AssetDatabase.GetAssetPath(atlasAsset) == "")
|
||||||
AssetDatabase.CreateAsset(atlasAsset, atlasPath);
|
AssetDatabase.CreateAsset(atlasAsset, atlasPath);
|
||||||
@ -727,9 +724,14 @@ namespace Spine.Unity.Editor {
|
|||||||
EditorUtility.SetDirty(atlasAsset);
|
EditorUtility.SetDirty(atlasAsset);
|
||||||
AssetDatabase.SaveAssets();
|
AssetDatabase.SaveAssets();
|
||||||
|
|
||||||
if (pageFiles.Count != atlasAsset.materials.Length)
|
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);
|
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
|
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);
|
Debug.Log(string.Format("{0} :: Imported with {1} material", atlasAsset.name, atlasAsset.materials.Length), atlasAsset);
|
||||||
|
|
||||||
// Iterate regions and bake marked.
|
// Iterate regions and bake marked.
|
||||||
@ -766,6 +768,15 @@ namespace Spine.Unity.Editor {
|
|||||||
return loadedAtlas != null ? loadedAtlas : atlasAsset;
|
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 () {
|
public static Shader GetDefaultShader () {
|
||||||
Shader shader = Shader.Find(SpineEditorUtilities.Preferences.DefaultShader);
|
Shader shader = Shader.Find(SpineEditorUtilities.Preferences.DefaultShader);
|
||||||
if (shader == null) shader = Shader.Find("Spine/Skeleton");
|
if (shader == null) shader = Shader.Find("Spine/Skeleton");
|
||||||
@ -928,6 +939,13 @@ namespace Spine.Unity.Editor {
|
|||||||
return (AtlasAssetBase)AssetDatabase.LoadAssetAtPath(atlasPath, typeof(AtlasAssetBase));
|
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) {
|
static string GetMaterialDirectory (string assetPath, List<Material> previousMaterials) {
|
||||||
if (previousMaterials.Count > 0 && previousMaterials[0] != null) {
|
if (previousMaterials.Count > 0 && previousMaterials[0] != null) {
|
||||||
string materialPath = AssetDatabase.GetAssetPath(previousMaterials[0]);
|
string materialPath = AssetDatabase.GetAssetPath(previousMaterials[0]);
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"name": "com.esotericsoftware.spine.spine-unity",
|
"name": "com.esotericsoftware.spine.spine-unity",
|
||||||
"displayName": "spine-unity Runtime",
|
"displayName": "spine-unity Runtime",
|
||||||
"description": "This plugin provides the spine-unity runtime core.",
|
"description": "This plugin provides the spine-unity runtime core.",
|
||||||
"version": "4.2.99",
|
"version": "4.2.100",
|
||||||
"unity": "2018.3",
|
"unity": "2018.3",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Esoteric Software",
|
"name": "Esoteric Software",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user