Yes, it is possible to import Spine JSON files and create the data at runtime in Unity. You can use the SkeletonDataAsset.CreateRuntimeInstance
and SpineAtlasAsset.CreateRuntimeInstance
methods to create a SkeletonDataAsset
and SpineAtlasAsset
at runtime from your JSON and atlas files. This process allows you to instantiate SkeletonAnimation
GameObjects from these assets. Here's a simplified example based on the provided contexts:
// Assuming atlasTxt is your loaded atlas text, textures are your loaded Texture2D array,
// materialPropertySource is a Material to copy properties from, and skeletonJson is your loaded JSON text.
SpineAtlasAsset runtimeAtlasAsset = SpineAtlasAsset.CreateRuntimeInstance(atlasTxt, textures, materialPropertySource, true);
SkeletonDataAsset runtimeSkeletonDataAsset = SkeletonDataAsset.CreateRuntimeInstance(skeletonJson, runtimeAtlasAsset, true);
// Now you can create a SkeletonAnimation GameObject using the runtimeSkeletonDataAsset
SkeletonAnimation instance = SkeletonAnimation.NewSkeletonAnimationGameObject(runtimeSkeletonDataAsset);
This approach is useful for loading Spine assets dynamically, such as from a "Mods" folder, as you described. Make sure the assets (JSON, atlas, and textures) are accessible at runtime and properly loaded into Unity before attempting to create the runtime instances.