CapersProject/Assets/02.Scripts/Character/SpineController.cs
Nam Tae Gun 3b44d173ed #5 스파인 컨트롤러 추가
+ Tycoon, TycoonUi Action Map 추가
+ 기본적인 TycoonPlayer 연동
+ GameManager에서 CurrentCombatPlayer로직 변경

Closes #5
2024-06-06 20:07:07 +09:00

97 lines
2.8 KiB
C#

using System;
using Spine;
using Spine.Unity;
using UnityEngine;
using AnimationState = Spine.AnimationState;
namespace BlueWater.Players
{
public abstract class SpineController : MonoBehaviour
{
// Variables
#region Variables
// Components
protected SkeletonAnimation SkeletonAnimation;
protected AnimationState AnimationState;
#endregion
// Unity events
#region Unity events
private void OnDestroy()
{
if (AnimationState != null)
{
AnimationState.Start -= OnAnimationStart;
AnimationState.Complete -= OnAnimationComplete;
}
}
#endregion
// Initialize methods
#region Initialize methods
public virtual void InitializeComponents(SkeletonAnimation skeletonAnimation)
{
if (skeletonAnimation == null)
{
Debug.LogError("SkeletonAnimation component is null.");
return;
}
SkeletonAnimation = skeletonAnimation;
AnimationState = SkeletonAnimation.AnimationState;
if (AnimationState != null)
{
AnimationState.Complete += OnAnimationComplete;
}
else
{
Debug.LogError("AnimationState is not initialized.");
}
}
#endregion
// Methods
#region Methods
public void PlayAnimation(string animationName, bool isLoopActive, float speed = 1f)
{
if (SkeletonAnimation == null && AnimationState == null) return;
if (string.IsNullOrEmpty(animationName))
{
Debug.LogError($"{animationName}의 애니메이션은 존재하지 않습니다.");
return;
}
AnimationState.TimeScale = speed;
AnimationState.SetAnimation(0, animationName, isLoopActive);
}
public void SetSkin(string skinName)
{
if (SkeletonAnimation == null && AnimationState == null) return;
if (string.IsNullOrEmpty(skinName))
{
Debug.LogError($"{skinName}의 스킨 이름은 존재하지 않습니다.");
return;
}
SkeletonAnimation.Skeleton.SetSkin(skinName);
SkeletonAnimation.Skeleton.SetSlotsToSetupPose();
AnimationState.Apply(SkeletonAnimation.Skeleton);
}
protected abstract void OnAnimationStart(TrackEntry trackEntry);
protected abstract void OnAnimationComplete(TrackEntry trackEntry);
#endregion
}
}