local CameraManager = {}

local ADJUST_SCREEN_W = 720
local ADJUST_SCREEN_H = 1560

function CameraManager:init()
	self.mainCamera = CS.UnityEngine.Camera.main
	CS.UnityEngine.GameObject.DontDestroyOnLoad(self.mainCamera.gameObject)

	self.originPosition = self.mainCamera.transform.position
	self.originOrthographicSize = self.mainCamera.orthographicSize

	-- self.originFieldOfView = self.mainCamera.gameObject:GetComponent(GConst.TYPEOF_UNITY_CLASS.BF_CAMERA_HELPER).OriginFieldOfView
	-- self:adjustCameraForFight()
	-- 战斗相机参数调整
	self.mainCamera.transparencySortMode = CS.UnityEngine.TransparencySortMode.CustomAxis
	self.mainCamera.transparencySortAxis = BF.Vector3(0, 0, 1)
end

function CameraManager:getMainCamera()
	return self.mainCamera
end

function CameraManager:resetMainCamera()
	self.mainCamera.transform.position = self.originPosition
	self.mainCamera.orthographicSize = self.originOrthographicSize
end

function CameraManager:getMainCameraOriginPosition()
	return self.originPosition
end

function CameraManager:getOriginOrthographicSize()
	return self.originOrthographicSize
end

-- 适配战斗相机
function CameraManager:adjustCameraForFight()
	local manualHeight
	-- 然后得到当前屏幕的高宽比 和 你自定义需求的高宽比。通过判断他们的大小，来不同赋值
	if CS.UnityEngine.Screen.height / CS.UnityEngine.Screen.width ~= ADJUST_SCREEN_H / ADJUST_SCREEN_W then
		-- 如果屏幕的高宽比大于自定义的高宽比 。则通过公式  ADJUST_SCREEN_W * manualHeight = Screen.width * Screen.height；
		-- 来求得适应的manualHeight ，用它求出 实际高度与理想高度的比率 scale
		manualHeight = ADJUST_SCREEN_W / CS.UnityEngine.Screen.width * CS.UnityEngine.Screen.height
	else
		-- 否则 直接给manualHeight 自定义的 ADJUST_SCREEN_H 的值，那么相机的fieldOfView就会原封不动
		manualHeight = ADJUST_SCREEN_H
	end
	-- Camera.fieldOfView 视野:  这是垂直视野：水平FOV取决于视口的宽高比，当相机是正交时fieldofView被忽略
	-- 把实际高度与理想高度的比率scale乘加给Camera.fieldOfView。
	-- 这样就能达到自动调节分辨率的效果
	local scale = manualHeight / ADJUST_SCREEN_H
	if scale < 0.7 then
		scale = 0.7
	end
	self.mainCamera.fieldOfView = self.originFieldOfView*scale
end

return CameraManager