using Sirenix.OdinInspector; using Spine.Unity; using UnityEngine; using AnimationState = Spine.AnimationState; namespace BlueWater.Players { public class SpineController : MonoBehaviour { // Variables #region Variables // Components [SerializeField] private SkeletonAnimation _skeletonAnimation; private AnimationState _animationState; // Variables [SerializeField] private string _initialSkinName; #endregion // Unity events #region Unity events private void Awake() { InitializeComponents(); } #endregion // Initialize methods #region Initialize methods [Button("셋팅 초기화")] public virtual void InitializeComponents() { _skeletonAnimation = transform.GetComponentInChildren(); _animationState = _skeletonAnimation.AnimationState; SetSkin(_initialSkinName); } #endregion // Methods #region Methods public void PlayAnimation(string animationName, bool isLoopActive, float speed = 1f) { if (!_skeletonAnimation && _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); } #endregion } }