rj-action-library/Runtime/Animation/AnimationManager.cs

74 lines
1.8 KiB
C#
Raw Normal View History

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
{
public interface Animator
{
public void OnAnimatorStart();
public void OnAnimatorEnd();
public void OnAnimatorCancel();
}
/*
public void OnAnimatorStart(){}
public void OnAnimatorEnd(){}
public void OnAnimatorCancel(){}
*/
public class AnimationMember
{
string _name;
public string name => _name;
public AnimationMember( string name )
{
_name = name;
}
}
public class AnimationManager
{
static MultiMap<Node,string,Animator> _animating = new MultiMap<Node,string,Animator>();
public static AnimationMember position = new AnimationMember( "position" );
public static AnimationMember rotation = new AnimationMember( "rotation" );
public static AnimationMember scale = new AnimationMember( "scale" );
public static Animator GetAnimator( Node node, AnimationMember member )
{
return _animating[ node ][ member.name ];
}
public static bool IsAnimating( Animator animator, Node node, AnimationMember member )
{
return GetAnimator( node, member ) == animator;
}
public static void StartAnimation( Animator animator, Node node, AnimationMember member )
{
var activeAnimator = GetAnimator( node, member );
if ( activeAnimator != null )
{
activeAnimator.OnAnimatorCancel();
}
_animating.Set( node, member.name, animator );
}
public static void EndAnimation( Animator animator, Node node, AnimationMember member )
{
var activeAnimator = GetAnimator( node, member );
if ( activeAnimator != null )
{
activeAnimator.OnAnimatorCancel();
}
}
}
}