123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- using System;
- using System.IO;
- using System.Collections.Generic;
- using UnityEngine;
- using Spine;
- [ExecuteInEditMode]
- [AddComponentMenu("Spine/SkeletonAnimation")]
- public class SkeletonAnimation : SkeletonRenderer, ISkeletonAnimation
- {
- public float timeScale = 1;
- public bool loop;
- public Spine.AnimationState state;
- public event UpdateBonesDelegate UpdateLocal
- {
- add { _UpdateLocal += value; }
- remove { _UpdateLocal -= value; }
- }
- public event UpdateBonesDelegate UpdateWorld
- {
- add { _UpdateWorld += value; }
- remove { _UpdateWorld -= value; }
- }
- public event UpdateBonesDelegate UpdateComplete
- {
- add { _UpdateComplete += value; }
- remove { _UpdateComplete -= value; }
- }
- protected event UpdateBonesDelegate _UpdateLocal;
- protected event UpdateBonesDelegate _UpdateWorld;
- protected event UpdateBonesDelegate _UpdateComplete;
- [SerializeField]
- private String
- _animationName;
- public String AnimationName
- {
- get
- {
- TrackEntry entry = state.GetCurrent(0);
- return entry == null ? null : entry.Animation.Name;
- }
- set
- {
- if (_animationName == value)
- return;
- _animationName = value;
- if (value == null || value.Length == 0)
- state.ClearTrack(0);
- else
- state.SetAnimation(0, value, loop);
- }
- }
- public override void Reset()
- {
- base.Reset();
- if (!valid)
- return;
- state = new Spine.AnimationState(skeletonDataAsset.GetAnimationStateData());
- if (_animationName != null && _animationName.Length > 0)
- {
- state.SetAnimation(0, _animationName, loop);
- Update(0);
- }
- }
- public virtual void Update()
- {
- Update(Time.deltaTime);
- }
- public virtual void Update(float deltaTime)
- {
- if (!valid)
- return;
- deltaTime *= timeScale;
- skeleton.Update(deltaTime);
- state.Update(deltaTime);
- state.Apply(skeleton);
- if (_UpdateLocal != null)
- _UpdateLocal(this);
- skeleton.UpdateWorldTransform();
- if (_UpdateWorld != null)
- {
- _UpdateWorld(this);
- skeleton.UpdateWorldTransform();
- }
- if (_UpdateComplete != null)
- {
- _UpdateComplete(this);
- }
- }
- }
|