1. 오늘 학습 키워드
애니메이션
2. 오늘 학습 한 내용을 나만의 언어로 정리하기
로딩 애니메이션 제작을 마무리 했다.
코드를 통해서 내가 미리 작업한 크기 위치 스케일 값을 struct를 사용해서 제작했고,
그 값을 이 메서드를 통해 컨트롤러 이름과 매핑을 해뒀다.
private void ApplyImageStyle(string controllerName)
{
if (loadingImage == null) return;
// 기본 설정 적용
loadingImage.SetNativeSize();
// 기본 스케일 설정
Vector3 defaultScaleValue = defaultScale * 2.0f;
// RectTransform인 경우 미리 정의된 속성 적용
if (loadingImage.transform is RectTransform rectTransform)
{
// 애니메이터 이름에 따라 적절한 이미지 속성 키를 결정
string propertyKey = controllerName;
// 매핑 딕셔너리에서 이미지 속성 키 찾기
if (animatorToImagePropertyMapping.TryGetValue(controllerName, out var mappedKey))
{
propertyKey = mappedKey;
}
// 이미지 속성 적용
ApplyImageProperties(propertyKey, rectTransform);
}
else
{
// RectTransform이 아닌 경우에는 기본 스케일 적용
loadingImage.transform.localScale = defaultScaleValue;
}
}
그리고 컨트롤러를 받아오고, 그 값에서 랜덤으로 isActive을 주어서 랜덤 애니메이션 컨트롤러와 랜덤 애니메이션 클립이 실행 되도록 했다.
private void ApplyRandomAnimationState(RuntimeAnimatorController controller, int stateCount, string[] stateNames)
{
// 애니메이터 컨트롤러 설정
imageAnimator.runtimeAnimatorController = controller;
// 컨트롤러가 설정되었는지 확인
if (imageAnimator.runtimeAnimatorController == null)
{
return;
}
// 랜덤 상태 인덱스 선택 - Idle(0)을 피하기 위해 1부터 시작
int randomState = 0;
if (stateCount > 1)
{
randomState = Random.Range(1, stateCount);
}
// 상태 이름 가져오기
string stateName = randomState < stateNames.Length ? stateNames[randomState] : "Idle";
// 애니메이터 파라미터 설정 시도
try {
imageAnimator.SetInteger("isActive", randomState);
} catch (Exception e) {
Debug.LogError($"파라미터 설정 중 오류: {e.Message}");
}
// 직접 해당 상태로 전환 시도
try {
// Play 메서드 사용
imageAnimator.Play(stateName, 0, 0f);
} catch (Exception e) {
Debug.LogError($"Play 메서드 호출 중 오류: {e.Message}");
// 대체 방법 시도
try {
// CrossFade 메서드 시도
imageAnimator.CrossFade(stateName, 0.1f, 0);
} catch (Exception ex) {
Debug.LogError($"CrossFade 메서드 호출 중 오류: {ex.Message}");
}
}
// 애니메이터 업데이트 강제 실행
imageAnimator.Update(0f);
}
3. 학습하며 겪었던 문제점 & 에러
작업한게 깃에서 합치다가 충돌나서 다 삭제되어서 작업을 새로했다.
4. 내일 학습 할 것은 무엇인지
빌드 이후 큼직한 오류를 수정해야한다.