UI坐标、屏幕坐标与世界坐标
UI坐标、屏幕坐标与世界坐标
- 解答:
UI坐标
UI坐标为界面编辑中的坐标,会受设备屏幕比例的影响,不受设备屏幕大小的影响。通过锚点与UI坐标可以调节控件在不同比列屏幕中的适配。
屏幕坐标
屏幕坐标为设备屏幕的坐标,会受设备屏幕大小的影响。
世界坐标
世界坐标为场景中的坐标,是常说的元件位置中的位置坐标,格式通常为Engine.Vector(X,Y,Z)。
使用例子:
点击屏幕射线检测点击到的场景元件。
GameClient.lua
--当玩家点击屏幕System:RegisterEvent( Events.ON_TOUCH_SCREEN_PRESSED, function (x, y) -- x,y = 屏幕坐标 local startPos1 = MiscService:ScreenToWorld(x, y, 0) --将屏幕坐标转换为世界坐标 local endPos1 = MiscService:ScreenToWorld(x, y, 3000) local id, hitInfo = PlayInteractive:GetHitResultWithRaycast(PlayInteractive.HIT_TYPE.Element, startPos1, endPos1, false, 0)--射线检测
--射线检测是否检测到结果 if not hitInfo.hitPos then UI:ShowMessageTip("没检测到物体") else -- 是否在触发盒内 local bInTriggerBox = TriggerBox:IsPositionInTriggerBox(endPos, 492) if bInTriggerBox then UI:ShowMessageTip("坐标在触发盒内") else UI:ShowMessageTip("坐标不在触发盒内") end end end)