[unity] Fixed Materials in separate directory being deleted upon reimport. Closes #2560.

This commit is contained in:
Harald Csaszar 2024-06-25 19:09:59 +02:00
parent 24070b4768
commit 6df18e22d3
2 changed files with 12 additions and 4 deletions

View File

@ -642,6 +642,7 @@ namespace Spine.Unity.Editor {
}
List<Material> populatingMaterials = new List<Material>(pageFiles.Count);
string materialDirectory = GetMaterialDirectory(assetPath, vestigialMaterials);
for (int i = 0; i < pageFiles.Count; i++) {
string texturePath = assetPath + "/" + pageFiles[i];
@ -660,9 +661,8 @@ namespace Spine.Unity.Editor {
if (pageName == primaryName && pageFiles.Count == 1)
pageName = "Material";
string materialPath = assetPath + "/" + primaryName + "_" + pageName + ".mat";
string materialPath = materialDirectory + "/" + primaryName + "_" + pageName + ".mat";
Material material = (Material)AssetDatabase.LoadAssetAtPath(materialPath, typeof(Material));
if (material == null) {
Shader defaultShader = GetDefaultShader();
material = defaultShader != null ? new Material(defaultShader) : null;
@ -836,7 +836,6 @@ namespace Spine.Unity.Editor {
string primaryName = spriteAtlas.name;
string assetPath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(spriteAtlas)).Replace('\\', '/');
string atlasPath = assetPath + "/" + primaryName + SpriteAtlasSuffix + ".asset";
SpineSpriteAtlasAsset atlasAsset = AssetDatabase.LoadAssetAtPath<SpineSpriteAtlasAsset>(atlasPath);
@ -900,6 +899,15 @@ namespace Spine.Unity.Editor {
return (AtlasAssetBase)AssetDatabase.LoadAssetAtPath(atlasPath, typeof(AtlasAssetBase));
}
static string GetMaterialDirectory (string assetPath, List<Material> previousMaterials) {
if (previousMaterials.Count > 0 && previousMaterials[0] != null) {
string materialPath = AssetDatabase.GetAssetPath(previousMaterials[0]);
string materialDirectory = Path.GetDirectoryName(materialPath).Replace('\\', '/');
return materialDirectory;
}
return assetPath;
}
static bool SetDefaultTextureSettings (string texturePath, SpineAtlasAsset atlasAsset) {
TextureImporter texImporter = (TextureImporter)TextureImporter.GetAtPath(texturePath);
if (texImporter == null) {

View File

@ -2,7 +2,7 @@
"name": "com.esotericsoftware.spine.spine-unity",
"displayName": "spine-unity Runtime",
"description": "This plugin provides the spine-unity runtime core.",
"version": "4.2.73",
"version": "4.2.74",
"unity": "2018.3",
"author": {
"name": "Esoteric Software",