using UnityEngine; using System.Collections; public class Recompile : MonoBehaviour { private string platform = string.Empty; // Use this for initialization void Start() { DebugPlatformMesaage(); } void DebugPlatformMesaage() { #if UNITY_EDITOR platform = "hi,大家好,我是在unity编辑模式下"; #elif UNITY_XBOX360 platform="hi,大家好,我在XBOX360平台"; #elif UNITY_IPHONE platform="hi,大家好,我是IPHONE平台"; #elif UNITY_ANDROID platform="hi,大家好,我是ANDROID平台"; #elif UNITY_STANDALONE_OSX platform="hi,大家好,我是OSX平台"; #elif UNITY_STANDALONE_WIN platform="hi,大家好,我是Windows平台"; #endif Debug.Log("Current Platform:" + platform); } }
注意一点:如果你写一行代码,想让在Android平台下运行时,如果你如下面这种写法:
#if UNITY_ANDROID // 调用Android的方法 #endif
你会发现在unity运行的时候,会影响socket的访问。
实际应该这样写:
#if UNITY_ANDROID && !UNITY_EDITOR // 调用Android的方法 #endif
这样就不会出现问题了。