1. 오늘 학습 키워드
버그 및 누락 수정
2. 오늘 학습 한 내용을 나만의 언어로 정리하기
로딩 애니메이션 코드를 추가로 제작하고
#region을 통해, 코드를 기능에 맞게 나눠주었다.
대충 이런 코드인데, 주석으로 설명을 다 달아두었으니,, 스킵하겠다.
#region ------------------- 애니메이션 -------------------
private IEnumerator ChangeAnimationLoop() // 시간에 따라서 랜덤으로 애니메이션 변경
{
while (true)
{
SetRandomAnimatorController();
yield return new WaitForSeconds(animationChangeInterval);
}
}
private async Task LoadAnimations() // 애니메이터 컨트롤러 로드
{
try
{
Debug.Log($"시작: 애니메이터 컨트롤러 로드 - 레이블: {loadingAnimatorLabel}");
animatorLoadHandle = Addressables.LoadAssetsAsync<RuntimeAnimatorController>(loadingAnimatorLabel, null);
await animatorLoadHandle.Task;
if (animatorLoadHandle.Status == AsyncOperationStatus.Succeeded)
{
loadedAnimators = new List<RuntimeAnimatorController>(animatorLoadHandle.Result);
Debug.Log($"성공: {loadedAnimators.Count}개의 애니메이터 컨트롤러 로드됨");
if (loadedAnimators.Count > 0 && imageAnimator != null)
{
Debug.Log("애니메이터 초기 설정 시작");
SetRandomAnimatorController();
}
else
{
Debug.LogError($"오류: loadedAnimators 수: {loadedAnimators.Count}, imageAnimator null?: {imageAnimator == null}");
}
}
else
{
Debug.LogError($"실패: 애니메이터 컨트롤러 로드 실패 - 상태: {animatorLoadHandle.Status}");
}
}
catch (Exception e)
{
Debug.LogError($"오류 발생: 애니메이터 컨트롤러 로드 중 예외 발생 - {e.Message}\n{e.StackTrace}");
}
}
private void SetRandomAnimatorController()
{
if (loadedAnimators == null || loadedAnimators.Count == 0 || imageAnimator == null)
{
Debug.LogError($"애니메이션 설정 실패: loadedAnimators null?: {loadedAnimators == null}, count: {loadedAnimators?.Count}, imageAnimator null?: {imageAnimator == null}");
return;
}
try
{
int randomIndex = Random.Range(0, loadedAnimators.Count);
RuntimeAnimatorController selectedController = loadedAnimators[randomIndex];
string controllerName = selectedController.name;
Debug.Log($"애니메이터 컨트롤러 설정: {controllerName}");
// 컨트롤러별 상태 정보 가져오기
var (maxStates, stateNames) = controllerStates.TryGetValue(controllerName, out var states)
? states
: (3, new[] { "Idle", "Attack_1", "Death" });
// 랜덤 상태 선택
int randomState = Random.Range(0, maxStates);
string stateName = randomState < stateNames.Length ? stateNames[randomState] : "Idle";
// 상태 설정 및 컨트롤러 적용
imageAnimator.SetInteger("isActive", randomState);
imageAnimator.runtimeAnimatorController = selectedController;
imageAnimator.Play(stateName, 0, 0f);
if (loadingImage != null)
{
loadingImage.SetNativeSize();
loadingImage.transform.localScale = defaultScale;
Debug.Log("이미지 크기 조정 완료");
}
foreach (var param in imageAnimator.parameters)
{
Debug.Log($"사용 가능한 파라미터: {param.name} (타입: {param.type})");
}
Debug.Log($"애니메이션 상태 설정: 컨트롤러 = {controllerName}, isActive = {randomState}, 상태 이름 = {stateName}");
}
catch (Exception e)
{
Debug.LogError($"애니메이터 설정 중 오류 발생: {e.Message}\n{e.StackTrace}");
}
}
#endregion
3. 학습하며 겪었던 문제점 & 에러
애니메이션이 계속 idle 상태가 나와서, 이거 수정했다.
4. 내일 학습 할 것은 무엇인지
커서 매니저를 일단 제작을 해두었고, 클릭 이벤트를 커서 매니저를 통해 전역으로 관리 해줄 예정이다
'TIL' 카테고리의 다른 글
25.05.07 TIL (0) | 2025.05.07 |
---|---|
25.05.01 TIL (0) | 2025.05.01 |
25.04.29 TIL (0) | 2025.04.29 |
25.04.28 TIL (0) | 2025.04.28 |
25.04.25 TIL (0) | 2025.04.25 |