function CameraController:mouseCheck()
if Input.GetMouseButtonDown(0) then
self.startPos = Input.mousePosition
end
if Input.GetMouseButton(0) then
local _mousePos = Input.mousePosition
if _mousePos ~= self.startPos then
-- 方向
local _dir = (_mousePos - self.startPos).normalized
_dir.z = _dir.y * (1 + (80 + 90 + 30) / 360) -- 40 * 2 + 45 * 2 + 30(多重节点旋转角度)
_dir.y = 0
local _dis = Vector3.Distance(self:screenPos2World(_mousePos),self:screenPos2World(self.startPos))
local _oldPos = self.cameraTrans.localPosition
local _targetPos = _oldPos - _dir * _dis
self:adaptiveMapEdge(_targetPos)
self.startPos = Input.mousePosition
end
end
end
--转换成世界坐标
function CameraController:screenPos2World(worldPos)
return self.camera:ScreenToWorldPoint(worldPos)
end
--- 屏幕地图边缘判断
function CameraController:adaptiveMapEdge(pos)
self.cameraTrans.localPosition = pos
pos = self.cameraTrans.position
local _upMax = self.upMax.position.z
local _downMax = self.downMax.position.z
if pos.z >= _upMax then
pos.z = _upMax
end
if pos.z <= _downMax then
pos.z = _downMax
end
local _leftMax = self.leftMax.position.x
local _rightMax = self.rightMax.position.x
if pos.x < _leftMax then
pos.x = _leftMax
end
if pos.x > _rightMax then
pos.x = _rightMax
end
self.cameraTrans.position = pos
return pos
end