89 lines
2.1 KiB
C#
89 lines
2.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Text.RegularExpressions;
|
|
using System.Text;
|
|
using Godot;
|
|
|
|
namespace Rokojori
|
|
{
|
|
[Tool]
|
|
[GlobalClass]
|
|
public partial class AnimateTransform:RJSequenceAction, Animator
|
|
{
|
|
|
|
[Export]
|
|
public TransformAnimations animations;
|
|
|
|
[Export]
|
|
public Node3D target;
|
|
|
|
List<Vector3> _frameValues;
|
|
List<Vector3> _randomizations;
|
|
|
|
public void OnAnimatorStart(){}
|
|
public void OnAnimatorEnd(){}
|
|
public void OnAnimatorCancel(){}
|
|
|
|
|
|
public override void _OnTrigger()
|
|
{
|
|
_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 );
|
|
|
|
var start = TimeLineManager.GetPosition( timeline );
|
|
var end = start + animations.GetMaxDuration( _randomizations );
|
|
|
|
var actionID = DispatchStart();
|
|
|
|
foreach ( var c in animations.curves )
|
|
{
|
|
AnimationManager.StartAnimation( c, target, c.animationMember );
|
|
}
|
|
|
|
TimeLineScheduler.ScheduleSpanIn( timeline, 0, duration,
|
|
( int id, int type )=>
|
|
{
|
|
var timeNow = TimeLineManager.GetPosition( timeline );
|
|
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 ++;
|
|
}
|
|
|
|
if ( type == TimeLineSpan.End )
|
|
{
|
|
foreach ( var c in animations.curves )
|
|
{
|
|
AnimationManager.EndAnimation( c, target, c.animationMember );
|
|
}
|
|
|
|
DispatchEnd( actionID );
|
|
}
|
|
}
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
} |