https://docs.unity3d.com/kr/530/Manual/PlatformDependentCompilation.html
유니티 - 매뉴얼: 플랫폼 의존 컴파일
자동 메모리 관리를 이해하기 플랫폼 의존 컴파일 Unity는 “플랫폼 의존 컴파일”이라는 기능이 있습니다. 여기에는 몇 가지 전 처리기 지시문이 포함되어, 스크립트를 ’파티션화’하여 코드
docs.unity3d.com
https://docs.microsoft.com/ko-kr/dotnet/csharp/language-reference/preprocessor-directives
C# 전처리기 지시문
조건부 컴파일, 경고, null 허용 분석 등을 제어하는 다양한 C# 전처리기 지시문을 알아봅니다.
docs.microsoft.com
C# 전처리기 + 플랫폼 매크로를 이용하여 플랫폼을 대응
Ex)
#if UNITY_EDITOR
//에디터에서 해야 할 작업
#endif
#if UNITY_ANDROID
//안드로이드에서 해야 할 작업
#endif
또는
https://docs.unity3d.com/kr/530/ScriptReference/Application-platform.html
Unity - 스크립팅 API: Application.platform
Success! Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. 닫기
docs.unity3d.com
if (Application.platform == RuntimePlatform.Android /* 코드가 실행될 플랫폼 */)
{
}
위처럼 대응
주의할 점
- 전처리기를 사용할 경우 Unity의 Build Setting이 만약 Android로 돼있을 경우엔 유니티의 에디터 상에서도
#if UNITY_ANDROID
//안드로이드에서 해야 할 작업
#endif
위 코드가 먹힌다는 부분
'Unity > Tips' 카테고리의 다른 글
기존 프로젝트 URP, HDRP로 전환 시 Material 일일이 바꾸지 말자 (0) | 2021.07.06 |
---|---|
Unity Visual Studio에서 이상한 오류?! (0) | 2021.06.27 |
Shader HLSL -> Shader Graph화 할때 유용한 사이트 (0) | 2021.06.03 |
Unity manifest 위치, 수정, 권한 요청 (4) | 2021.06.01 |
유니티 씬뷰 확대 축소_Unity SceneView Zoom in, out (0) | 2021.04.23 |