根据浮生梦老师前端课程内容,可以通过以下方式判断客户端类型:
```lua
-- 获取设备信息来判断客户端类型
local deviceInfo = SL:GetMetaValue("DEVICE_UNIQUE_ID")
local isPC = false
-- 方法1:通过设备ID判断(PC端有特定格式的设备ID)
if deviceInfo and string.find(deviceInfo, "PC") then
isPC = true
SL:print("当前是PC端")
else
SL:print("当前是手机端")
end
-- 方法2:通过SDK登录状态辅助判断
local isSDKLogin = SL:GetMetaValue("IS_SDK_LOGIN")
if isSDKLogin and isSDKLogin == "true" then
SL:print("SDK登录,通常是手机端")
end
-- 方法3:通过996盒子登录状态判断
local isBoxLogin = SL:GetMetaValue("BOX996_LOGIN")
if isBoxLogin and isBoxLogin == "true" then
SL:print("996盒子登录")
end
-- 方法4:通过云真机状态判断
local isCloudDevice = SL:GetMetaValue("CLOUD996_DEVICE")
if isCloudDevice and isCloudDevice == "true" then
SL:print("996云真机")
end
```
主要判断逻辑:
1. PC端通常有包含"PC"字样的设备ID
2. 手机端通常通过SDK登录
3. 还可以结合其他设备信息进行综合判断
建议在实际使用中结合多种判断方式,以提高准确性。