Unity 커스텀 프로파일러 사용 가이드
이 문서에서는 Unity에서 커스텀 프로파일러 카운터를 생성하고 사용하는 방법에 대해 설명합니다. 이 가이드는 Unity의 프로파일링에 대한 기본 개념과 함께 사용자 정의 지표를 추가하는 구체적인 예제를 포함합니다.
프로파일러 개요
Unity의 프로파일러는 애플리케이션의 성능을 분석하고 시스템 지표를 시각화하는 도구입니다. 프로파일러를 활용하여 게임의 성능 문제를 조기에 파악하고 해결할 수 있습니다.
커스텀 프로파일러 카운터 생성
커스텀 프로파일러 카운터를 생성하려면 다음 단계를 따릅니다:
- 새로운 카운터 생성
- 카운터를 프로파일러 카테고리에 할당
- 카운터 값 업데이트
카운터 정의
새로운 카운터를 정의할 때는 카운터의 타입, 이름, 단위를 지정해야 합니다. 아래는 Tank Trail Particles
라는 이름의 카운터를 생성하는 예시입니다.
public static class GameStats
{
public static readonly ProfilerCategory TanksCategory = ProfilerCategory.Scripts;
public const string TankTrailParticleCountName = "Tank Trail Particles";
public static readonly ProfilerCounterValue<int> TankTrailParticleCount =
new ProfilerCounterValue<int>(TanksCategory, TankTrailParticleCountName, ProfilerMarkerDataUnit.Count,
||
||
}
FlushOnEndOfFrame
: 프레임 종료 시 카운터 값을 초기화합니다.ResetToZeroOnFlush
: 카운터 값을 프로파일러 데이터 스트림에 보냅니다.
프로파일러 카테고리 사용
Unity에서는 카운터를 카운터 프로파일 작업 유형에 따라 카테고리로 그룹화합니다. 사용 가능한 프로파일러 카테고리는 ProfilerCategory
를 참조하십시오. 카운터 정의 시 카테고리를 반드시 지정해야 합니다.
using Unity.Profiling;
using Unity.Profiling.Editor;
[System.Serializable]
[ProfilerModuleMetadata("Tank Effects")]
public class TankEffectsProfilerModule : ProfilerModule
{
static readonly ProfilerCounterDescriptor[] k_Counters = new ProfilerCounterDescriptor[]
{
new ProfilerCounterDescriptor(GameStatistics.TankTrailParticleCountName, GameStatistics.TanksCategory),
// 다른 카운터 추가 가능
};
static readonly string[] k_AutoEnabledCategoryNames = new string[]
{
ProfilerCategory.Scripts.Name,
ProfilerCategory.Memory.Name
};
public TankEffectsProfilerModule() : base(k_Counters, autoEnabledCategoryNames: k_AutoEnabledCategoryNames) { }
}
카운터 값 업데이트
카운터 값을 업데이트하기 위해 MonoBehaviour 스크립트를 생성합니다. 아래 스크립트는 매 프레임 마다 TankTrailParticleCount
카운터를 업데이트 합니다.
using UnityEngine;
class TankMovement : MonoBehaviour
{
public ParticleSystem m_TrailParticleSystem;
void Update()
{
GameStats.TankTrailParticleCount.Value += m_TrailParticleSystem.particleCount;
}
}
릴리스 빌드에서 프로파일러 카운터 사용
릴리스 플레이어에서 프로파일러 창은 사용할 수 없지만, 카운터 값을 사용자 인터페이스 요소로 표시할 수 있습니다. 이를 통해 릴리스된 애플리케이션의 성능 지표를 관찰할 수 있습니다.
결론
이 문서에서 제공된 정보를 바탕으로 Unity에서 커스텀 프로파일러 카운터를 생성하고 활용하는 방법을 이해하셨기를 바랍니다. 성능 최적화와 문제 해결을 위해 프로파일러 기능을 적극적으로 활용해보세요!