Make animation time of subspan relative.

This commit is contained in:
2023-03-09 10:07:24 +08:00
parent b89e1f983e
commit 26a8675922
2 changed files with 12 additions and 8 deletions

View File

@@ -9,7 +9,6 @@ namespace Cryville.Crtr.Components {
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);
Iteration = 1;
}
@@ -42,8 +41,6 @@ namespace Cryville.Crtr.Components {
public float Delay { get; private set; }
double _startTime;
float _rtime;
readonly PropSrc _rtimeSrc;
public override void Init() {
_skinContext = new SkinContext(transform);
@@ -52,7 +49,7 @@ namespace Cryville.Crtr.Components {
_startTime = time;
}
public override void Tick(SkinContainer c, double time) {
_rtime = (float)(time - _startTime - Delay) / Duration;
float _rtime = (float)(time - _startTime - Delay) / Duration;
if (_rtime < 0) _rtime = 0;
else if (_rtime > Iteration) {
if (Direction.HasFlag(AnimationDirection.alternate)) {
@@ -74,10 +71,7 @@ namespace Cryville.Crtr.Components {
}
}
if (Direction.HasFlag(AnimationDirection.reverse)) _rtime = 1 - _rtime;
_rtimeSrc.Invalidate();
ChartPlayer.etor.ContextSelfValue = _rtimeSrc;
if (_anim != null) c.MatchAnimation(_anim, _rtime, new RuntimeSkinContext(_skinContext));
ChartPlayer.etor.ContextSelfValue = null;
}
protected override void OnDestroy() { }
}

View File

@@ -32,6 +32,7 @@ namespace Cryville.Crtr {
_group = group;
_rootElement = rootElement;
for (int i = 0; i < _stacks.Length; i++) _stacks[i] = new DynamicStack();
_rtimeSrc = new PropSrc.Float(() => _rtime);
}
public void MatchStatic() {
var stack = _stacks[0];
@@ -140,13 +141,22 @@ namespace Cryville.Crtr {
}
if (rc.PropSrcs != null) ChartPlayer.etor.ContextCascadeDiscard();
}
float _rtime;
readonly PropSrc _rtimeSrc;
public void MatchAnimation(AnimationSpan span, float rtime, RuntimeSkinContext ctx) {
ChartPlayer.etor.ContextSelfValue = _rtimeSrc;
MatchAnimationInternal(span, rtime, ctx);
ChartPlayer.etor.ContextSelfValue = null;
}
void MatchAnimationInternal(AnimationSpan span, float rtime, RuntimeSkinContext ctx) {
_rtime = rtime;
_rtimeSrc.Invalidate();
foreach (var p in span.properties) {
p.Key.ExecuteDynamic(_group, ctx, p.Value, 0);
}
foreach (var s in span.spans) {
if (rtime < s.Key.Behind || rtime >= s.Key.Ahead) continue;
MatchAnimation(s.Value, rtime, ctx);
MatchAnimationInternal(s.Value, (rtime - s.Key.Behind) / (s.Key.Ahead - s.Key.Behind), ctx);
}
}
}