方法一:使用宏命令
方法二:使用RuntimePlatform枚举去判断平台
方法三:使用Application中API
一,宏命令
#if UNITY_EDITOR
//编辑器
#elif UNITY_WINDOW
//电脑平台
#elif UNITY_ANDROID
//安卓平台
#elif UNITY_IOS
//苹果平台
#endif
二,使用Application中API
RuntimePlatform platform = Application.platform;
枚举值:
OSXEditor = 0,
//
// 摘要:
// In the player on macOS.
OSXPlayer = 1,
//
// 摘要:
// In the player on Windows.
WindowsPlayer = 2,
//
// 摘要:
// In the web player on macOS.
OSXWebPlayer = 3,
//
// 摘要:
// In the Dashboard widget on macOS.
OSXDashboardPlayer = 4,
//
// 摘要:
// In the web player on Windows.
WindowsWebPlayer = 5,
//
// 摘要:
// In the Unity editor on Windows.
WindowsEditor = 7,
//
// 摘要:
// In the player on the iPhone.
IPhonePlayer = 8,
PS3 = 9,
XBOX360 = 10,
//
// 摘要:
// In the player on Android devices.
Android = 11,
NaCl = 12,
//
// 摘要:
// In the player on Linux.
LinuxPlayer = 13,
FlashPlayer = 15,
//
// 摘要:
// In the Unity editor on Linux.
LinuxEditor = 16,
//
// 摘要:
// In the player on WebGL
WebGLPlayer = 17,
MetroPlayerX86 = 18,
//
// 摘要:
// In the player on Windows Store Apps when CPU architecture is X86.
WSAPlayerX86 = 18,
MetroPlayerX64 = 19,
//
// 摘要:
// In the player on Windows Store Apps when CPU architecture is X64.
WSAPlayerX64 = 19,
MetroPlayerARM = 20,
//
// 摘要:
// In the player on Windows Store Apps when CPU architecture is ARM.
WSAPlayerARM = 20,
WP8Player = 21,
BB10Player = 22,
BlackBerryPlayer = 22,
TizenPlayer = 23,
//
// 摘要:
// In the player on the PS Vita.
PSP2 = 24,
//
// 摘要:
// In the player on the Playstation 4.
PS4 = 25,
PSM = 26,
//
// 摘要:
// In the player on Xbox One.
XboxOne = 27,
SamsungTVPlayer = 28,
//
// 摘要:
// In the player on Wii U.
WiiU = 30,
//
// 摘要:
// In the player on the Apple's tvOS.
tvOS = 31,
//
// 摘要:
// In the player on Nintendo Switch.
Switch = 32
三,使用Application中API
bool platform= Application.isEditor;//是否是编辑器状态
platform = Application.isMobilePlatform;//是否是移动平台