Biên dịch có điều kiện (Conditional compilation)
· about 1 min readConditional compilation
[ExecuteInEditMode]
public class PlatformDetector : MonoBehaviour
{
#if UNITY_EDITOR
void Start()
{
Debug.Log("Đang chạy trong editor");
}
#endif
#if UNITY_ANDROID
void Update()
{
Debug.Log("Đang chạy trên Android");
}
#endif
}
using UnityEngine;
using System.Collections;
public class PlatformDefines : MonoBehaviour {
void Start () {
#if UNITY_EDITOR
Debug.Log("Unity Editor");
#endif
#if UNITY_IOS
Debug.Log("iOS");
#endif
#if UNITY_STANDALONE_OSX
Debug.Log("Standalone OSX");
#endif
#if UNITY_STANDALONE_WIN
Debug.Log("Standalone Windows");
#endif
}
}
Xem thêm: Conditional compilation
