์คํ ์ (์ ๋๋ฉ์ด์ ์ด ๋ฆฌ์คํธ์ ๋ค์ด์์ง ์์)
์คํ ํ (์ ๋๋ฉ์ด์
์ด ๋ฆฌ์คํธ์ ๋ค์ด์์๊ณ , idel์ด ์ ๋๋ฉ์ด์
์ ๋ค์ด๊ฐ ์์)
๊ทผ๋ฐ ์ ์ ์ ๋๋ฉ์ด์ ์ด ์๋์ค์ธ ๋น ์ค๋ธ์ ํธ์๋ ์๋ฌด๊ฒ๋ ์๋ธ
๋น ์ค๋ธ์ ํธ์ ์ ๋๋ฉ์ด์ ๋ง๊ณ ๋ค๋ฅธ๊ฒ๋ ๋ฃ์ด์ผ ๋ณด์?ย
์๋ ์ด๋ฏธ์ง๊ฐ ๋๋ฌด ์์์ ์ฌ์์ค์ด์ฌ๋ ์๋ณด์ด๋๊ฑด๊ฐ?
using System.Collections;
using UnityEngine;
using System.Collections.Generic;
public class AnimationManager : MonoBehaviour
{
ย ย
ย ย public GameObject[] characterAnimationObjects;// ๊ฐ ์บ๋ฆญํฐ์ ์ ๋๋ฉ์ด์
์ ์คํํ ๋น ์ค๋ธ์ ํธ ๋ฐฐ์ด
ย ย private Dictionary<int, Coroutine> activeAnimations = new Dictionary<int, Coroutine>();
ย ย public void PlayCharacterAnimation(int characterIndex, int skillNumber)
ย ย {
ย ย ย ย if (!characterDataMap.ContainsKey(characterIndex)) return;
ย ย ย ย GameObject targetObject = characterAnimationObjects[characterIndex];
ย ย ย ย Animation anim = targetObject.GetComponent<Animation>();
ย ย ย ย string animationName = skillNumber switch
ย ย ย ย {
ย ย ย ย ย ย 1 => "Skill1",
ย ย ย ย ย ย 2 => "Skill2",
ย ย ย ย ย ย 3 => "Skill3",
ย ย ย ย ย ย _ => "Idle"
ย ย ย ย };
ย ย ย ย anim.Play(animationName);
ย ย ย ย
ย ย ย ย if (activeAnimations.ContainsKey(characterIndex))
ย ย ย ย {
ย ย ย ย ย ย StopCoroutine(activeAnimations[characterIndex]);
ย ย ย ย ย ย activeAnimations.Remove(characterIndex);
ย ย ย ย }
ย ย ย ย activeAnimations[characterIndex] = StartCoroutine(WaitForAnimationEnd(anim, characterIndex));
ย ย }
ย ย public float GetAnimationLength(int characterIndex)
ย ย {
ย ย ย ย if (characterIndex < 0 || characterIndex >= characterAnimationObjects.Length) return 0f;
ย ย ย ย Animation anim = characterAnimationObjects[characterIndex].GetComponent<Animation>();
ย ย ย ย if (anim != null && anim.clip != null)
ย ย ย ย {
ย ย ย ย ย ย return anim.clip.length;
ย ย ย ย }
ย ย ย ย return 0f;
ย ย }
ย ย private Dictionary<int, CharacterData> characterDataMap = new Dictionary<int, CharacterData>();
ย ย public void SetCharacterAnimations(int index, CharacterData characterData)
ย ย {
ย ย ย ย if (index < 0 || index >= characterAnimationObjects.Length) return;
ย ย ย ย
ย ย ย ย characterDataMap[index] = characterData;
ย ย ย ย GameObject targetObject = characterAnimationObjects[index];
ย ย ย ย Animation anim = targetObject.GetComponent<Animation>();
ย ย ย ย if (anim == null)
ย ย ย ย ย ย anim = targetObject.AddComponent<Animation>();
ย ย ย ย
ย ย ย ย anim.AddClip(characterData.idleAnimation, "Idle");
ย ย ย ย anim.AddClip(characterData.skill1Animation, "Skill1");
ย ย ย ย anim.AddClip(characterData.skill2Animation, "Skill2");
ย ย ย ย anim.AddClip(characterData.skill3Animation, "Skill3");
ย ย
ย ย ย ย anim.clip = characterData.idleAnimation;
ย ย ย ย anim.Play();
ย ย }
ย ย private IEnumerator WaitForAnimationEnd(Animation anim, int characterIndex)
ย ย {
ย ย ย ย yield return new WaitForSeconds(anim.clip.length);
ย ย ย ย PlayCharacterIdleAnimation(characterIndex);
ย ย }
ย ย public void PlayCharacterIdleAnimation(int characterIndex)
ย ย {
ย ย ย ย if (characterIndex < 0 || characterIndex >= characterAnimationObjects.Length) return;
ย ย ย ย GameObject targetObject = characterAnimationObjects[characterIndex];
ย ย ย ย Animation anim = targetObject.GetComponent<Animation>();
ย ย ย ย if (anim == null)
ย ย ย ย ย ย anim = targetObject.AddComponent<Animation>();
ย ย ย ย CharacterData characterData = BattleManager.Instance.GetCharacterData(characterIndex);
ย ย ย ย if (characterData != null && characterData.idleAnimation != null)
ย ย ย ย {
ย ย ย ย ย ย anim.clip = characterData.idleAnimation;
ย ย ย ย ย ย anim.Play();
ย ย ย ย }
ย ย }
}
์ผ๋จ ์ ๋๋ฉ์ด์
์ฌ์ ๋ด๋น ์คํฌ๋ฆฝํธ๋ ์ด๋ ๊ฒ์๊น
+์คํฌ ์ฌ์ฉํด๋ ์ ๋๋ฉ์ด์
์ํ๊ฐ ์ ๋ณํ๋๋ฐ ์ด๊ฒ๋ ์ด์ ๋ฅผ ๋ชจ๋ฅด๊ฒ ์
๋๊ธ 0