2025-01-03 12:09:23 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using System.Text;
|
|
|
|
using Godot;
|
|
|
|
|
|
|
|
namespace Rokojori
|
|
|
|
{
|
|
|
|
[Tool]
|
|
|
|
[GlobalClass]
|
2025-01-08 18:46:17 +00:00
|
|
|
public partial class AnimateTransform:SequenceAction, Animator
|
2025-01-03 12:09:23 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
public TransformAnimations animations;
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
public Node3D target;
|
|
|
|
|
|
|
|
List<Vector3> _frameValues;
|
|
|
|
List<Vector3> _randomizations;
|
|
|
|
|
|
|
|
public void OnAnimatorStart(){}
|
|
|
|
public void OnAnimatorEnd(){}
|
|
|
|
public void OnAnimatorCancel(){}
|
|
|
|
|
|
|
|
|
2025-01-08 18:46:17 +00:00
|
|
|
protected override void _OnTrigger()
|
2025-01-03 12:09:23 +00:00
|
|
|
{
|
|
|
|
_frameValues = new List<Vector3>();
|
|
|
|
_randomizations = new List<Vector3>();
|
|
|
|
|
|
|
|
foreach ( var curve in animations.curves )
|
|
|
|
{
|
|
|
|
_frameValues.Add( TransformTargets.Get( target, curve.transformTarget ) );
|
|
|
|
_randomizations.Add( curve.Randomize() );
|
|
|
|
}
|
|
|
|
|
|
|
|
var timeline = animations.timeline;
|
|
|
|
var duration = animations.GetMaxDuration( _randomizations );
|
|
|
|
|
2025-01-19 20:35:51 +00:00
|
|
|
var start = timeline.position;
|
2025-01-03 12:09:23 +00:00
|
|
|
var end = start + animations.GetMaxDuration( _randomizations );
|
|
|
|
|
2025-01-21 20:58:56 +00:00
|
|
|
var sequenceID = DispatchStart();
|
2025-01-03 12:09:23 +00:00
|
|
|
|
|
|
|
foreach ( var c in animations.curves )
|
|
|
|
{
|
|
|
|
AnimationManager.StartAnimation( c, target, c.animationMember );
|
|
|
|
}
|
|
|
|
|
2025-01-19 20:35:51 +00:00
|
|
|
TimeLineManager.ScheduleSpanIn( timeline, 0, duration,
|
|
|
|
( span, type )=>
|
2025-01-03 12:09:23 +00:00
|
|
|
{
|
2025-01-19 20:35:51 +00:00
|
|
|
var timeNow = timeline.position;
|
2025-01-03 12:09:23 +00:00
|
|
|
var elapsed = timeNow - start;
|
|
|
|
|
|
|
|
var index = 0;
|
|
|
|
|
|
|
|
foreach ( var c in animations.curves )
|
|
|
|
{
|
|
|
|
if ( AnimationManager.IsAnimating( c, target, c.animationMember ) )
|
|
|
|
{
|
|
|
|
c.Apply( elapsed, target, _randomizations[ index ], _frameValues[ index ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
index ++;
|
|
|
|
}
|
|
|
|
|
2025-01-08 18:46:17 +00:00
|
|
|
if ( type == TimeLineSpanUpdateType.End )
|
2025-01-03 12:09:23 +00:00
|
|
|
{
|
|
|
|
foreach ( var c in animations.curves )
|
|
|
|
{
|
|
|
|
AnimationManager.EndAnimation( c, target, c.animationMember );
|
|
|
|
}
|
|
|
|
|
2025-01-21 20:58:56 +00:00
|
|
|
DispatchEnd( sequenceID );
|
2025-01-03 12:09:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|