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
|
|
|
|
{
|
2025-01-08 18:46:17 +00:00
|
|
|
public static readonly AnimationMember Position = new AnimationMember( "position" );
|
|
|
|
public static readonly AnimationMember Rotation = new AnimationMember( "rotation" );
|
|
|
|
public static readonly AnimationMember Scale = new AnimationMember( "scale" );
|
|
|
|
|
|
|
|
public static readonly AnimationMember[] Transform = new AnimationMember[]
|
|
|
|
{
|
|
|
|
AnimationMember.Position, AnimationMember.Rotation, AnimationMember.Scale
|
|
|
|
};
|
|
|
|
|
2025-01-03 12:09:23 +00:00
|
|
|
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>();
|
|
|
|
|
2025-01-08 18:46:17 +00:00
|
|
|
|
2025-01-03 12:09:23 +00:00
|
|
|
|
|
|
|
public static Animator GetAnimator( Node node, AnimationMember member )
|
|
|
|
{
|
2025-01-08 18:46:17 +00:00
|
|
|
return _animating.Get( node, member.name );
|
2025-01-03 12:09:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static bool IsAnimating( Animator animator, Node node, AnimationMember member )
|
|
|
|
{
|
|
|
|
return GetAnimator( node, member ) == animator;
|
2025-01-08 18:46:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static bool IsAnimating( Animator animator, Node node, params AnimationMember[] members )
|
|
|
|
{
|
|
|
|
for ( int i = 0; i < members.Length; i++ )
|
|
|
|
{
|
|
|
|
if ( ! IsAnimating( animator, node, members[ i ] ) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return members.Length > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool IsAnimating( Animator animator, Node[] nodes, params AnimationMember[] members )
|
|
|
|
{
|
|
|
|
for ( int i = 0; i < nodes.Length; i++ )
|
|
|
|
{
|
|
|
|
if ( ! IsAnimating( animator, nodes[ i ], members ) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nodes.Length > 0;
|
2025-01-03 12:09:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2025-01-08 18:46:17 +00:00
|
|
|
public static void StartAnimation( Animator animator, Node node, params AnimationMember[] members )
|
|
|
|
{
|
|
|
|
for ( int i = 0; i < members.Length; i++ )
|
|
|
|
{
|
|
|
|
StartAnimation( animator, node, members[ i ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void StartAnimation( Animator animator, Node[] nodes, params AnimationMember[] members )
|
|
|
|
{
|
|
|
|
for ( int i = 0; i < nodes.Length; i++ )
|
|
|
|
{
|
|
|
|
StartAnimation( animator, nodes[ i ], members );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-03 12:09:23 +00:00
|
|
|
public static void EndAnimation( Animator animator, Node node, AnimationMember member )
|
|
|
|
{
|
|
|
|
var activeAnimator = GetAnimator( node, member );
|
|
|
|
|
|
|
|
if ( activeAnimator != null )
|
|
|
|
{
|
|
|
|
activeAnimator.OnAnimatorCancel();
|
|
|
|
}
|
|
|
|
}
|
2025-01-08 18:46:17 +00:00
|
|
|
|
|
|
|
public static void EndAnimation( Animator animator, Node node, params AnimationMember[] members )
|
|
|
|
{
|
|
|
|
for ( int i = 0; i < members.Length; i++ )
|
|
|
|
{
|
|
|
|
EndAnimation( animator, node, members[ i ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void EndAnimation( Animator animator, Node[] nodes, params AnimationMember[] members )
|
|
|
|
{
|
|
|
|
for ( int i = 0; i < nodes.Length; i++ )
|
|
|
|
{
|
|
|
|
EndAnimation( animator, nodes[ i ], members );
|
|
|
|
}
|
|
|
|
}
|
2025-01-03 12:09:23 +00:00
|
|
|
}
|
|
|
|
}
|