cocos creator获取当前平台信息,2.4版本使用cc.sys.dump()可以打印所有平台信息:
cc.sys.dump();
打印结果:
isMobile : false
language : zh
browserType : chrome
browserVersion : 92.0.4515.159
capabilities : {"canvas":true,"opengl":true,"webp":true,"imageBitmap":true,"mouse":true,"keyboard":true,"accelerometer":true}
os : Windows
osVersion :
platform : 101
Using WEBGL renderer.
参考:cocos论坛问答
对应“platform”参数的代码:101代表是什么,翻查资料:
let platformArr = {
"WIN32": 0,
"LINUX": 1,
"MACOS": 2,
"android": 3,
"IPHONE": 4,
"IPAD": 5,
"BLACKBERRY": 6,
"NACL": 7,
"EMSCRIPTEN": 8,
"TIZEN": 9,
"WINRT": 10,
"WP8": 11,
"MOBILE_BROWSER": 100,
"DESKTOP_BROWSER": 101,
"EDITOR_PAGE": 102,
"EDITOR_CORE": 103,
"WECHAT_GAME": 104,
"QQ_PLAY": 105,
"FB_PLAYABLE_ADS": 106,
"BAIDU_GAME": 107,
"VIVO_GAME": 108,
"OPPO_GAME": 109,
"HUAWEI_GAME": 110,
"XIAOMI_GAME": 111,
"WECHAT_OPEN_DATA": 114,
}
以及3.x也可以用的接口:
console.log("clic>>>>>>>>>>>>>>>>>>>>>", sys.os, sys.dump())
//安卓
if (sys.os == sys.OS.ANDROID) {
}
//ios
else if (sys.os == sys.OS.IOS) {
}