菱形格子的点击判断
一段菱形格子的点击判断
local function GetGird(screenPosition) -- 2D相机算法 -- local v = Camera.main:ScreenToWorldPoint(screenPosition) -- 3D相机 local ray = Camera.main:ScreenPointToRay(screenPosition) local hitBool, hit = XluaOverrideMethod.Raycast(ray) local v = hit.point -- //推导过程 -- //float x = (v.x / MapInfo.girdW + v.y / MapInfo.girdG) * 0.5f; -- //float y = (v.x / MapInfo.girdW - v.y / MapInfo.girdG) * 0.5f; -- //float x1 = (x +0.5f).ToInt(); -- //float y1 = (y +0.5f).ToInt(); local x = math.floor((v.x * static_config.girdWMul + v.y * static_config.girdGMul) * 0.5 + 0.5) local y = math.floor((v.x * static_config.girdWMul - v.y * static_config.girdGMul) * 0.5 + 0.5) -- print(x.."x1") -- y = math.max( y,0 ) -- print(y.."y") x = math.max( x,0 ) y = math.max( y,0 ) -- //Debug.Log(string.Format("{0},{1}", v.x, v.y)); -- //Debug.LogError(string.Format("{0},{1}", x, y)); return x * static_config.MapSize + y,x,y -- //Debug.LogError(string.Format("{0},{1}", x1, y1)); end
girdW是格子宽
girdG是格子高
girdWMul 是格子宽的乘法转换
浙公网安备 33010602011771号