+ AiMovement 클래스 재생성 및 초기화 방식 변경 + AnimationController 클래스 초기화 방식 변경 + MapManager, MapController 로직 수정 + BaseBoss 프리팹 수정 + SandMole 보스에 맞게 맵 추가 + 임시 SandMole, GhostBarrel 이미지 추가 + 기존 GroundGreen, GroundRed 스프라이트 정사각형으로 변경, 수정에 따라 BaseMapController Ground, Wall 수정 + 코뿔소 맵 투명화 Props 추가 Closes #12
122 lines
3.2 KiB
C#
122 lines
3.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
namespace BlueWater
|
|
{
|
|
public class AnimationController : MonoBehaviour
|
|
{
|
|
// Variables
|
|
#region Variables
|
|
|
|
// Components
|
|
private Animator _animator;
|
|
|
|
#endregion
|
|
|
|
// Unity events
|
|
#region Unity events
|
|
|
|
private void Awake()
|
|
{
|
|
InitializeComponents();
|
|
}
|
|
|
|
#endregion
|
|
|
|
// Initialize methods
|
|
#region Initialize Methdos
|
|
|
|
public void InitializeComponents()
|
|
{
|
|
_animator = GetComponentInChildren<Animator>();
|
|
}
|
|
|
|
#endregion
|
|
|
|
// Methods
|
|
#region Methods
|
|
|
|
public void SetAnimationParameter(string parameter, bool value)
|
|
{
|
|
if (!_animator) return;
|
|
|
|
_animator.SetBool(parameter, value);
|
|
}
|
|
|
|
public void SetAnimationParameter(string parameter, int value)
|
|
{
|
|
if (!_animator) return;
|
|
|
|
_animator.SetInteger(parameter, value);
|
|
}
|
|
|
|
public void SetAnimationParameter(string parameter, float value)
|
|
{
|
|
if (!_animator) return;
|
|
|
|
_animator.SetFloat(parameter, value);
|
|
}
|
|
|
|
public void SetAnimationTrigger(string parameter)
|
|
{
|
|
if (!_animator) return;
|
|
|
|
_animator.SetTrigger(parameter);
|
|
}
|
|
|
|
public bool IsComparingCurrentAnimation(string animationName, int animatorLayer = 0)
|
|
{
|
|
if (!_animator) return false;
|
|
|
|
return _animator.GetCurrentAnimatorStateInfo(animatorLayer).IsName(animationName);
|
|
}
|
|
|
|
public IEnumerator WaitForAnimationToRun(string animationName, Action<bool> onSuccess, float timeout = 2f)
|
|
{
|
|
var elapsedTime = 0f;
|
|
while (!IsComparingCurrentAnimation(animationName))
|
|
{
|
|
elapsedTime += Time.deltaTime;
|
|
yield return null;
|
|
if (elapsedTime <= timeout) continue;
|
|
|
|
Debug.Log("Timeout waiting for animation state: " + animationName);
|
|
onSuccess?.Invoke(false);
|
|
}
|
|
|
|
onSuccess?.Invoke(true);
|
|
}
|
|
|
|
public void SetCurrentAnimationSpeed(float targetDuration, int animatorLayer = 0)
|
|
{
|
|
if (!_animator) return;
|
|
|
|
var animationLength = _animator.GetCurrentAnimatorStateInfo(animatorLayer).length;
|
|
_animator.speed = animationLength / targetDuration;
|
|
}
|
|
|
|
public float GetCurrentAnimationNormalizedTime(int animatorLayer = 0)
|
|
{
|
|
if (!_animator) return 0f;
|
|
|
|
return _animator.GetCurrentAnimatorStateInfo(animatorLayer).normalizedTime;
|
|
}
|
|
|
|
public float GetCurrentAnimationLength(int animatorLayer = 0)
|
|
{
|
|
if (!_animator) return 0f;
|
|
|
|
return _animator.GetCurrentAnimatorStateInfo(animatorLayer).length;
|
|
}
|
|
|
|
public void ResetAnimationSpeed()
|
|
{
|
|
if (!_animator) return;
|
|
|
|
_animator.speed = 1f;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |