Implement animation.
This commit is contained in:
@@ -1,5 +1,48 @@
|
||||
namespace Cryville.Crtr.Components {
|
||||
using Cryville.Common;
|
||||
|
||||
namespace Cryville.Crtr.Components {
|
||||
public class SkinAnimation : SkinComponent {
|
||||
public SkinAnimation() {
|
||||
SubmitProperty("name", new PropOp.Identifier(v => Name = v));
|
||||
SubmitProperty("duration", new PropOp.Float(v => Duration = v));
|
||||
_rtimeSrc = new PropSrc.Float(() => _rtime);
|
||||
}
|
||||
|
||||
SkinContext _skinContext;
|
||||
|
||||
AnimationSpan _anim;
|
||||
public int Name {
|
||||
set {
|
||||
if (value == 0) return;
|
||||
var id = new Identifier(value);
|
||||
AnimationSpan anim;
|
||||
if (!ChartPlayer.pskin.animations.TryGetValue(id, out anim)) {
|
||||
Logger.Log("main", 4, "Skin", "Animation {0} not found", id.Name);
|
||||
_anim = null;
|
||||
return;
|
||||
}
|
||||
_anim = anim;
|
||||
}
|
||||
}
|
||||
public float Duration { get; private set; }
|
||||
|
||||
double _startTime;
|
||||
float _rtime;
|
||||
readonly PropSrc _rtimeSrc;
|
||||
|
||||
public override void Init() {
|
||||
_skinContext = new SkinContext(transform);
|
||||
}
|
||||
public override void Rewind(double time) {
|
||||
_startTime = time;
|
||||
}
|
||||
public override void Tick(SkinContainer c, double time) {
|
||||
_rtime = (float)(time - _startTime) / Duration;
|
||||
_rtimeSrc.Invalidate();
|
||||
ChartPlayer.etor.ContextSelfValue = _rtimeSrc;
|
||||
if (_anim != null) c.MatchAnimation(_anim, _rtime, new RuntimeSkinContext(_skinContext));
|
||||
ChartPlayer.etor.ContextSelfValue = null;
|
||||
}
|
||||
protected override void OnDestroy() { }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user