a15714ab041eb360be3335625683746f01534528d6a5eb89d53760f19c11cd6e823597eccb177737258491114d

์‹คํ–‰ ์ „ (์• ๋‹ˆ๋ฉ”์ด์…˜์ด ๋ฆฌ์ŠคํŠธ์— ๋“ค์–ด์žˆ์ง€ ์•Š์Œ)

a15714ab041eb360be3335625683746f01534528d6a5eb89d53763f89911cd6e0a3070d277c8bbef45e80d826d

์‹คํ–‰ ํ›„ (์• ๋‹ˆ๋ฉ”์ด์…˜์ด ๋ฆฌ์ŠคํŠธ์— ๋“ค์–ด์™€์žˆ๊ณ , idel์ด ์• ๋‹ˆ๋ฉ”์ด์…˜์— ๋“ค์–ด๊ฐ€ ์žˆ์Œ)


24b0d121e09c28a8699fe8b115ef046c60f12d4e

๊ทผ๋ฐ ์ •์ž‘ ์• ๋‹ˆ๋ฉ”์ด์…˜์ด ์ž‘๋™์ค‘์ธ ๋นˆ ์˜ค๋ธŒ์ ํŠธ์—๋Š” ์•„๋ฌด๊ฒƒ๋„ ์•ˆ๋œธ

๋นˆ ์˜ค๋ธŒ์ ํŠธ์— ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋ง๊ณ  ๋‹ค๋ฅธ๊ฒƒ๋„ ๋„ฃ์–ด์•ผ ๋ณด์ž„?ย 

์•„๋‹˜ ์ด๋ฏธ์ง€๊ฐ€ ๋„ˆ๋ฌด ์ž‘์•„์„œ ์žฌ์ƒ์ค‘์ด์—ฌ๋„ ์•ˆ๋ณด์ด๋Š”๊ฑด๊ฐ€?


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();
ย  ย  ย  ย  }
ย  ย  }
}

์ผ๋‹จ ์• ๋‹ˆ๋ฉ”์ด์…˜ ์žฌ์ƒ ๋‹ด๋‹น ์Šคํฌ๋ฆฝํŠธ๋Š” ์ด๋ ‡๊ฒŒ์ƒ๊น€

+์Šคํ‚ฌ ์‚ฌ์šฉํ•ด๋„ ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ƒํƒœ๊ฐ€ ์•ˆ ๋ณ€ํ•˜๋Š”๋ฐ ์ด๊ฒƒ๋„ ์ด์œ ๋ฅผ ๋ชจ๋ฅด๊ฒ ์Œ