Biên dịch có điều kiện (Conditional compilation)

Dong Ho · about 1 min read

Conditional 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

Outline

history cached

play_arrow arrow_right_alt

update skip_next

create close

settings arrow_downward

×

Memo

...
×

Under Maintenance