mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Merge pull request #428 from Fenrisul/master
[Unity] Auto-import of .skel.bytes added.
This commit is contained in:
commit
e96c077ce8
@ -274,9 +274,13 @@ public class SpineEditorUtilities : AssetPostprocessor {
|
|||||||
imagePaths.Add(str);
|
imagePaths.Add(str);
|
||||||
break;
|
break;
|
||||||
case ".json":
|
case ".json":
|
||||||
TextAsset spineDataFile = (TextAsset)AssetDatabase.LoadAssetAtPath(str, typeof(TextAsset));
|
if (IsValidSpineData((TextAsset)AssetDatabase.LoadAssetAtPath(str, typeof(TextAsset))))
|
||||||
if (IsValidSpineData(spineDataFile)) {
|
|
||||||
skeletonPaths.Add(str);
|
skeletonPaths.Add(str);
|
||||||
|
break;
|
||||||
|
case ".bytes":
|
||||||
|
if (str.ToLower().EndsWith(".skel.bytes")) {
|
||||||
|
if (IsValidSpineData((TextAsset)AssetDatabase.LoadAssetAtPath(str, typeof(TextAsset))))
|
||||||
|
skeletonPaths.Add(str);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -426,7 +430,7 @@ public class SpineEditorUtilities : AssetPostprocessor {
|
|||||||
|
|
||||||
|
|
||||||
static bool CheckForValidAtlas (string atlasPath) {
|
static bool CheckForValidAtlas (string atlasPath) {
|
||||||
return false;
|
return false;
|
||||||
//////////////DEPRECATED - always check for new atlas data now
|
//////////////DEPRECATED - always check for new atlas data now
|
||||||
/*
|
/*
|
||||||
string dir = Path.GetDirectoryName(atlasPath);
|
string dir = Path.GetDirectoryName(atlasPath);
|
||||||
@ -565,13 +569,23 @@ public class SpineEditorUtilities : AssetPostprocessor {
|
|||||||
return (AtlasAsset)obj;
|
return (AtlasAsset)obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<string> GetRequiredAtlasRegions (string jsonPath) {
|
static void AddRequiredAtlasRegionsFromBinary (string skeletonDataPath, List<string> requiredPaths) {
|
||||||
|
SkeletonBinary binary = new SkeletonBinary(new AtlasRequirementLoader(requiredPaths));
|
||||||
|
TextAsset data = (TextAsset)AssetDatabase.LoadAssetAtPath(skeletonDataPath, typeof(TextAsset));
|
||||||
|
MemoryStream input = new MemoryStream(data.bytes);
|
||||||
|
binary.ReadSkeletonData(input);
|
||||||
|
binary = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<string> GetRequiredAtlasRegions (string skeletonDataPath) {
|
||||||
List<string> requiredPaths = new List<string>();
|
List<string> requiredPaths = new List<string>();
|
||||||
|
|
||||||
// FIXME - This doesn't work for a binary skeleton file!
|
if (skeletonDataPath.Contains(".skel")) {
|
||||||
if (jsonPath.Contains(".skel")) return requiredPaths;
|
AddRequiredAtlasRegionsFromBinary(skeletonDataPath, requiredPaths);
|
||||||
|
return requiredPaths;
|
||||||
|
}
|
||||||
|
|
||||||
TextAsset spineJson = (TextAsset)AssetDatabase.LoadAssetAtPath(jsonPath, typeof(TextAsset));
|
TextAsset spineJson = (TextAsset)AssetDatabase.LoadAssetAtPath(skeletonDataPath, typeof(TextAsset));
|
||||||
|
|
||||||
StringReader reader = new StringReader(spineJson.text);
|
StringReader reader = new StringReader(spineJson.text);
|
||||||
var root = Json.Deserialize(reader) as Dictionary<string, object>;
|
var root = Json.Deserialize(reader) as Dictionary<string, object>;
|
||||||
@ -585,7 +599,7 @@ public class SpineEditorUtilities : AssetPostprocessor {
|
|||||||
if ((string)data["type"] == "boundingbox") {
|
if ((string)data["type"] == "boundingbox") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (data.ContainsKey("path"))
|
if (data.ContainsKey("path"))
|
||||||
requiredPaths.Add((string)data["path"]);
|
requiredPaths.Add((string)data["path"]);
|
||||||
@ -809,7 +823,7 @@ public class SpineEditorUtilities : AssetPostprocessor {
|
|||||||
Object.DestroyImmediate(root);
|
Object.DestroyImmediate(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
mesh = (Mesh)AssetDatabase.LoadAssetAtPath(bakedPrefabPath, typeof(Mesh));
|
mesh = (Mesh)AssetDatabase.LoadAssetAtPath(bakedPrefabPath, typeof(Mesh));
|
||||||
|
|
||||||
Material mat = null;
|
Material mat = null;
|
||||||
mesh = atlasAsset.GenerateMesh(region.name, mesh, out mat);
|
mesh = atlasAsset.GenerateMesh(region.name, mesh, out mat);
|
||||||
@ -825,7 +839,7 @@ public class SpineEditorUtilities : AssetPostprocessor {
|
|||||||
AssetDatabase.SaveAssets();
|
AssetDatabase.SaveAssets();
|
||||||
AssetDatabase.Refresh();
|
AssetDatabase.Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
prefab.GetComponent<MeshRenderer>().sharedMaterial = mat;
|
prefab.GetComponent<MeshRenderer>().sharedMaterial = mat;
|
||||||
|
|
||||||
@ -1112,4 +1126,30 @@ public class SpineEditorUtilities : AssetPostprocessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class AtlasRequirementLoader : AttachmentLoader {
|
||||||
|
|
||||||
|
List<string> requirementList;
|
||||||
|
public AtlasRequirementLoader (List<string> requirementList) {
|
||||||
|
this.requirementList = requirementList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RegionAttachment NewRegionAttachment (Skin skin, string name, string path) {
|
||||||
|
requirementList.Add(path);
|
||||||
|
return new RegionAttachment(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MeshAttachment NewMeshAttachment (Skin skin, string name, string path) {
|
||||||
|
requirementList.Add(path);
|
||||||
|
return new MeshAttachment(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SkinnedMeshAttachment NewSkinnedMeshAttachment (Skin skin, string name, string path) {
|
||||||
|
requirementList.Add(path);
|
||||||
|
return new SkinnedMeshAttachment(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BoundingBoxAttachment NewBoundingBoxAttachment (Skin skin, string name) {
|
||||||
|
return new BoundingBoxAttachment(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -107,7 +107,7 @@ public class SkeletonDataAsset : ScriptableObject {
|
|||||||
skeletonDataScale = scale;
|
skeletonDataScale = scale;
|
||||||
#else
|
#else
|
||||||
if (spriteCollection != null) {
|
if (spriteCollection != null) {
|
||||||
attachmentLoader = new SpriteCollectionAttachmentLoader(spriteCollection)
|
attachmentLoader = new SpriteCollectionAttachmentLoader(spriteCollection);
|
||||||
skeletonDataScale = (1.0f / (spriteCollection.invOrthoSize * spriteCollection.halfTargetHeight) * scale) * 100f;
|
skeletonDataScale = (1.0f / (spriteCollection.invOrthoSize * spriteCollection.halfTargetHeight) * scale) * 100f;
|
||||||
} else {
|
} else {
|
||||||
if (atlasArr.Length == 0) {
|
if (atlasArr.Length == 0) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user