Yes, you can play Spine animations in Unity using the downloaded JSON, PNG, and atlas files without importing them as SkeletonData
assets. You can achieve this by loading the files at runtime and creating the necessary Spine objects programmatically.
Here is a general approach to do this:
Download the files: Ensure your JSON, PNG, and atlas files are downloaded and accessible in your Unity project.
Load the files at runtime: Use Unity's file I/O operations to read the JSON, PNG, and atlas files.
Create Spine objects: Use the Spine runtime API to create the necessary objects from the loaded files.
Here is a simplified example of how you might do this:
using Spine;
using Spine.Unity;
using System.IO;
using UnityEngine;
public class SpineLoader : MonoBehaviour
{
public string jsonPath;
public string atlasPath;
public string pngPath;
private SkeletonAnimation skeletonAnimation;
void Start()
{
// Load the JSON, atlas, and PNG files
string json = File.ReadAllText(jsonPath);
TextAsset atlasText = new TextAsset(File.ReadAllText(atlasPath));
Texture2D texture = LoadTexture(pngPath);
// Create the Atlas
Atlas atlas = new Atlas(new StringReader(atlasText.text), "", new MaterialsTextureLoader(texture));
// Create the SkeletonData
SkeletonJson skeletonJson = new SkeletonJson(atlas);
SkeletonData skeletonData = skeletonJson.ReadSkeletonData(new StringReader(json));
// Create the SkeletonAnimation
skeletonAnimation = SkeletonAnimation.NewSkeletonAnimationGameObject(skeletonData);
skeletonAnimation.Initialize(true);
}
private Texture2D LoadTexture(string path)
{
byte[] fileData = File.ReadAllBytes(path);
Texture2D texture = new Texture2D(2, 2);
texture.LoadImage(fileData);
return texture;
}
}
In this example:
jsonPath
, atlasPath
, and pngPath
are the paths to your downloaded files.
LoadTexture
is a helper function to load the PNG file into a Texture2D
.
- The
SkeletonAnimation
object is created and initialized with the loaded data.
This approach allows you to dynamically load and play Spine animations in Unity without pre-importing them as SkeletonData
assets.
For more detailed information, you can refer to the Spine Runtimes documentation.