Add anim.iteration, anim.direction, and anim.delay properties.
This commit is contained in:
@@ -1,11 +1,16 @@
|
|||||||
using Cryville.Common;
|
using Cryville.Common;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Components {
|
namespace Cryville.Crtr.Components {
|
||||||
public class SkinAnimation : SkinComponent {
|
public class SkinAnimation : SkinComponent {
|
||||||
public SkinAnimation() {
|
public SkinAnimation() {
|
||||||
SubmitProperty("name", new PropOp.Identifier(v => Name = v));
|
SubmitProperty("name", new PropOp.Identifier(v => Name = v));
|
||||||
SubmitProperty("duration", new PropOp.Float(v => Duration = v));
|
SubmitProperty("duration", new PropOp.Float(v => Duration = v));
|
||||||
|
SubmitProperty("iteration", new PropOp.Float(v => Iteration = v));
|
||||||
|
SubmitProperty("direction", new PropOp.Enum<AnimationDirection>(v => Direction = v, v => (AnimationDirection)v));
|
||||||
|
SubmitProperty("delay", new PropOp.Float(v => Delay = v));
|
||||||
_rtimeSrc = new PropSrc.Float(() => _rtime);
|
_rtimeSrc = new PropSrc.Float(() => _rtime);
|
||||||
|
Iteration = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkinContext _skinContext;
|
SkinContext _skinContext;
|
||||||
@@ -32,6 +37,9 @@ namespace Cryville.Crtr.Components {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public float Duration { get; private set; }
|
public float Duration { get; private set; }
|
||||||
|
public float Iteration { get; private set; }
|
||||||
|
public AnimationDirection Direction { get; private set; }
|
||||||
|
public float Delay { get; private set; }
|
||||||
|
|
||||||
double _startTime;
|
double _startTime;
|
||||||
float _rtime;
|
float _rtime;
|
||||||
@@ -44,7 +52,28 @@ namespace Cryville.Crtr.Components {
|
|||||||
_startTime = time;
|
_startTime = time;
|
||||||
}
|
}
|
||||||
public override void Tick(SkinContainer c, double time) {
|
public override void Tick(SkinContainer c, double time) {
|
||||||
_rtime = (float)(time - _startTime) / Duration;
|
_rtime = (float)(time - _startTime - Delay) / Duration;
|
||||||
|
if (_rtime < 0) _rtime = 0;
|
||||||
|
else if (_rtime > Iteration) {
|
||||||
|
if (Direction.HasFlag(AnimationDirection.alternate)) {
|
||||||
|
_rtime = Iteration % 2;
|
||||||
|
if (_rtime > 1) _rtime = 2 - _rtime;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_rtime = Iteration % 1;
|
||||||
|
if (_rtime == 0) _rtime = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (Direction.HasFlag(AnimationDirection.alternate)) {
|
||||||
|
_rtime %= 2;
|
||||||
|
if (_rtime > 1) _rtime = 2 - _rtime;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_rtime %= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Direction.HasFlag(AnimationDirection.reverse)) _rtime = 1 - _rtime;
|
||||||
_rtimeSrc.Invalidate();
|
_rtimeSrc.Invalidate();
|
||||||
ChartPlayer.etor.ContextSelfValue = _rtimeSrc;
|
ChartPlayer.etor.ContextSelfValue = _rtimeSrc;
|
||||||
if (_anim != null) c.MatchAnimation(_anim, _rtime, new RuntimeSkinContext(_skinContext));
|
if (_anim != null) c.MatchAnimation(_anim, _rtime, new RuntimeSkinContext(_skinContext));
|
||||||
@@ -52,4 +81,10 @@ namespace Cryville.Crtr.Components {
|
|||||||
}
|
}
|
||||||
protected override void OnDestroy() { }
|
protected override void OnDestroy() { }
|
||||||
}
|
}
|
||||||
|
[Flags]
|
||||||
|
public enum AnimationDirection {
|
||||||
|
normal = 0,
|
||||||
|
reverse = 1,
|
||||||
|
alternate = 2,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user