DOCUMENTATION / 03
Player APIPlayer API
Use a GameObject for each independently controlled player.用独立 GameObject 控制各个播放器。
Create a player创建播放器
Attach this example to a GameObject and assign a valid baked resource. The bake window can also create a bound player for you. SetAnimation uses a zero-based clip index and resets playback time to zero.把此示例挂到 GameObject,并绑定有效的烘焙资源;烘焙窗口也可直接创建已绑定的播放器。SetAnimation 使用从0开始的动画索引,并把播放时间归零。
using JoyLinkStudio.SpineGpuAnimation;
using UnityEngine;
public sealed class PlayBakedAnimation : MonoBehaviour
{
[SerializeField] private GpuAnimationResource bakedResource;
private void Start()
{
if (bakedResource == null) return;
var player = gameObject.AddComponent<GpuAnimationPlayer>();
player.Resource = bakedResource;
player.SetAnimation(0);
player.Speed = 0.8f;
player.Loop = true;
player.Seek(0.35f);
player.Paused = false;
}
}Playback controls播放控制
| API | Purpose用途 |
|---|---|
Resource | Assign a validated resource; resets clip and time.绑定通过验证的资源,重置动画与时间。 |
SetAnimation(index) | Select a clip; time resets to zero.选择动画,时间归零。 |
Seek(seconds) | Wrap in loop mode; clamp otherwise.循环时回绕,否则钳制到动画长度。 |
Speed | Independent finite speed; zero and negative values allowed.独立有限速度,可为0或负数。 |
Loop / Paused | Configure looping and pause/resume.设置循环和暂停/继续。 |
TimeSeconds / AnimationIndex | Read the current time and selected clip.读取当前时间和动画索引。 |
Automatic time and shared assets自动推进与共享资源
Enabled players advance time in Update. Disabling unregisters drawing and stops automatic Update. Assign the same baked resource to multiple players to share animation assets. Do not destroy the shared mesh/material/texture when removing a player. The core has no Spine API dependency.启用的播放器在 Update 推进时间;禁用后取消绘制注册,自动 Update 停止。多个播放器可引用同一烘焙资源以共享资源。删除播放器时不要销毁共享 mesh、material、texture;核心不依赖 Spine API。
Do not manually call Advance every frame while the enabled Player already updates, or time will advance twice. For explicitly controlled bulk updates, use Crowd with AutoAdvance disabled.启用的 Player 已自动更新,不要每帧再调用 Advance,否则会重复推进。需要显式控制批量更新时,可使用关闭 AutoAdvance 的 Crowd。