mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-02 05:39:07 +08:00
[Unity] Various importer fixes and improvements
This commit is contained in:
parent
dd248169ec
commit
55896be38f
@ -269,15 +269,23 @@ public class SpineEditorUtilities : AssetPostprocessor {
|
|||||||
|
|
||||||
sharedAtlas = data.atlasAsset;
|
sharedAtlas = data.atlasAsset;
|
||||||
|
|
||||||
SkeletonAnimation anim = SpawnAnimatedSkeleton(data);
|
|
||||||
string dir = Path.GetDirectoryName(Path.GetDirectoryName(AssetDatabase.GetAssetPath(data)));
|
string dir = Path.GetDirectoryName(Path.GetDirectoryName(AssetDatabase.GetAssetPath(data)));
|
||||||
string prefabPath = Path.Combine(dir, data.skeletonJSON.name + ".prefab").Replace("\\", "/");
|
string prefabPath = Path.Combine(dir, data.skeletonJSON.name + ".prefab").Replace("\\", "/");
|
||||||
PrefabUtility.CreatePrefab(prefabPath, anim.gameObject, ReplacePrefabOptions.ReplaceNameBased);
|
|
||||||
|
|
||||||
if(EditorApplication.isPlaying)
|
if(File.Exists(prefabPath) == false){
|
||||||
GameObject.Destroy(anim.gameObject);
|
SkeletonAnimation anim = SpawnAnimatedSkeleton(data);
|
||||||
else
|
PrefabUtility.CreatePrefab(prefabPath, anim.gameObject, ReplacePrefabOptions.ReplaceNameBased);
|
||||||
GameObject.DestroyImmediate(anim.gameObject);
|
if(EditorApplication.isPlaying)
|
||||||
|
GameObject.Destroy(anim.gameObject);
|
||||||
|
else
|
||||||
|
GameObject.DestroyImmediate(anim.gameObject);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -338,7 +346,6 @@ public class SpineEditorUtilities : AssetPostprocessor {
|
|||||||
path = path.Replace("\\", "/");
|
path = path.Replace("\\", "/");
|
||||||
path = path.Replace(Application.dataPath.Replace("\\", "/"), "Assets");
|
path = path.Replace(Application.dataPath.Replace("\\", "/"), "Assets");
|
||||||
atlasText = (TextAsset)AssetDatabase.LoadAssetAtPath(path, typeof(TextAsset));
|
atlasText = (TextAsset)AssetDatabase.LoadAssetAtPath(path, typeof(TextAsset));
|
||||||
// Debug.Log("Atlas Path: " + path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,10 +370,12 @@ public class SpineEditorUtilities : AssetPostprocessor {
|
|||||||
|
|
||||||
string atlasPath = assetPath + "/" + primaryName + "_Atlas.asset";
|
string atlasPath = assetPath + "/" + primaryName + "_Atlas.asset";
|
||||||
|
|
||||||
if(File.Exists(atlasPath))
|
AtlasAsset atlasAsset = (AtlasAsset)AssetDatabase.LoadAssetAtPath(atlasPath, typeof(AtlasAsset));
|
||||||
return (AtlasAsset)AssetDatabase.LoadAssetAtPath(atlasPath, typeof(AtlasAsset));
|
|
||||||
|
|
||||||
|
if(atlasAsset == null)
|
||||||
|
atlasAsset = AtlasAsset.CreateInstance<AtlasAsset>();
|
||||||
|
|
||||||
AtlasAsset atlasAsset = AtlasAsset.CreateInstance<AtlasAsset>();
|
|
||||||
atlasAsset.atlasFile = atlasText;
|
atlasAsset.atlasFile = atlasText;
|
||||||
|
|
||||||
//strip CR
|
//strip CR
|
||||||
@ -402,18 +411,26 @@ public class SpineEditorUtilities : AssetPostprocessor {
|
|||||||
pageName = "Material";
|
pageName = "Material";
|
||||||
|
|
||||||
string materialPath = assetPath + "/" + primaryName + "_" + pageName + ".mat";
|
string materialPath = assetPath + "/" + primaryName + "_" + pageName + ".mat";
|
||||||
|
Material mat = (Material)AssetDatabase.LoadAssetAtPath(materialPath, typeof(Material));
|
||||||
Material mat = new Material(Shader.Find(defaultShader));
|
|
||||||
|
if(mat == null){
|
||||||
|
mat = new Material(Shader.Find(defaultShader));
|
||||||
|
AssetDatabase.CreateAsset(mat, materialPath);
|
||||||
|
}
|
||||||
|
|
||||||
mat.mainTexture = texture;
|
mat.mainTexture = texture;
|
||||||
|
EditorUtility.SetDirty(mat);
|
||||||
AssetDatabase.CreateAsset(mat, materialPath);
|
|
||||||
AssetDatabase.SaveAssets();
|
AssetDatabase.SaveAssets();
|
||||||
|
|
||||||
atlasAsset.materials[i] = mat;
|
atlasAsset.materials[i] = mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
AssetDatabase.CreateAsset(atlasAsset, atlasPath);
|
if(AssetDatabase.GetAssetPath( atlasAsset ) == "")
|
||||||
|
AssetDatabase.CreateAsset(atlasAsset, atlasPath);
|
||||||
|
else
|
||||||
|
atlasAsset.Reset();
|
||||||
|
|
||||||
AssetDatabase.SaveAssets();
|
AssetDatabase.SaveAssets();
|
||||||
|
|
||||||
return (AtlasAsset)AssetDatabase.LoadAssetAtPath(atlasPath, typeof(AtlasAsset));
|
return (AtlasAsset)AssetDatabase.LoadAssetAtPath(atlasPath, typeof(AtlasAsset));
|
||||||
@ -442,6 +459,10 @@ public class SpineEditorUtilities : AssetPostprocessor {
|
|||||||
AssetDatabase.CreateAsset(skelDataAsset, filePath);
|
AssetDatabase.CreateAsset(skelDataAsset, filePath);
|
||||||
AssetDatabase.SaveAssets();
|
AssetDatabase.SaveAssets();
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
skelDataAsset.Reset();
|
||||||
|
skelDataAsset.GetSkeletonData(true);
|
||||||
|
}
|
||||||
|
|
||||||
return skelDataAsset;
|
return skelDataAsset;
|
||||||
}
|
}
|
||||||
@ -484,7 +505,7 @@ public class SpineEditorUtilities : AssetPostprocessor {
|
|||||||
return SpawnAnimatedSkeleton(skeletonDataAsset, skeletonDataAsset.GetSkeletonData(true).FindSkin(skinName));
|
return SpawnAnimatedSkeleton(skeletonDataAsset, skeletonDataAsset.GetSkeletonData(true).FindSkin(skinName));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SkeletonAnimation SpawnAnimatedSkeleton(SkeletonDataAsset skeletonDataAsset, Skin skin = null){
|
public static SkeletonAnimation SpawnAnimatedSkeleton(SkeletonDataAsset skeletonDataAsset, Skin skin = null){
|
||||||
|
|
||||||
GameObject go = new GameObject(skeletonDataAsset.name.Replace("_SkeletonData", ""), typeof(MeshFilter), typeof(MeshRenderer), typeof(SkeletonAnimation));
|
GameObject go = new GameObject(skeletonDataAsset.name.Replace("_SkeletonData", ""), typeof(MeshFilter), typeof(MeshRenderer), typeof(SkeletonAnimation));
|
||||||
SkeletonAnimation anim = go.GetComponent<SkeletonAnimation>();
|
SkeletonAnimation anim = go.GetComponent<SkeletonAnimation>();
|
||||||
@ -501,11 +522,19 @@ public class SpineEditorUtilities : AssetPostprocessor {
|
|||||||
|
|
||||||
anim.calculateNormals = requiresNormals;
|
anim.calculateNormals = requiresNormals;
|
||||||
|
|
||||||
|
SkeletonData data = skeletonDataAsset.GetSkeletonData(true);
|
||||||
|
|
||||||
|
if(data == null){
|
||||||
|
string reloadAtlasPath = AssetDatabase.GetAssetPath( skeletonDataAsset.atlasAsset );
|
||||||
|
skeletonDataAsset.atlasAsset = (AtlasAsset)AssetDatabase.LoadAssetAtPath( reloadAtlasPath, typeof(AtlasAsset));
|
||||||
|
data = skeletonDataAsset.GetSkeletonData(true);
|
||||||
|
}
|
||||||
|
|
||||||
if(skin == null)
|
if(skin == null)
|
||||||
skin = skeletonDataAsset.GetSkeletonData(true).DefaultSkin;
|
skin = data.DefaultSkin;
|
||||||
|
|
||||||
if(skin == null)
|
if(skin == null)
|
||||||
skin = skeletonDataAsset.GetSkeletonData(true).Skins[0];
|
skin = data.Skins[0];
|
||||||
|
|
||||||
anim.Reset();
|
anim.Reset();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user