유니티 - 전처리기 지시문을 사용하여 조건부 컴파일하기 (Scripting Define Symbols)
유니티 C#에서도 조건부 컴파일이 가능하다.
아래의 DefineTest.cs를 큐브에 추가한 후, 큐브를 클릭해보자.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DefineTest : MonoBehaviour
{
void OnMouseUp()
{
#if DEFINE_TEST
Debug.Log("OnMouseUp");
#endif
}
}
아마 아무 동작도 하지 않을 것이다.
DEFINE_TEST가 등록되지 않았기 때문에 전처리기가 해당 코드를 지울 것이다.
유니티에서도 사용자가 임의로 define 값을 정의할 수 있다.
[Edit] → [Project Settings...] → [Player] → Script Compilation에서
DEFINE_TEST를 등록한 후, Apply를 눌러 적용한다.
이제 큐브를 클릭하면 로그를 볼 수 있다.
DEFINE_TEST 가 등록되었기 때문에 #if DEFINE_TEST ~ #endif 코드가 처리된다.
Unity Plus:
Easy 2D, 3D, VR, & AR software for cross-platform development of games and mobile apps. - Unity Store
Have a 2D, 3D, VR, or AR project that needs cross-platform functionality? We can help. Take a look at the easy-to-use Unity Plus real-time dev platform!
store.unity.com
Unity Pro:
Unity Pro
The complete solutions for professionals to create and operate.
unity.com
Unity 프리미엄 학습:
Unity Learn
Advance your Unity skills with live sessions and over 750 hours of on-demand learning content designed for creators at every skill level.
unity.com