local this = class("cameraController_fishing", require("ui.manager.camera.controller.cameraController"))
local PATH_CAMERA = "Program/Camera/pre_fishingCamera.prefab"

function this:ctor(mode)
  this.super.ctor(self, mode)
end

function this:switchIn(preMode, params)
  self:initVirCamera()
  self.cameraTactics:SetEnabled(true)
end

function this:switchOut(nextMode)
  self:onDestroy()
end

function this:bindEntity(entity)
  self.cameraTactics.cineMachineCamera.Follow = entity:getTransform()
  self.cameraTactics.cineMachineCamera.LookAt = entity:getTransform()
  self.entity = entity
end

function this:setCameraByPoint(fishPointId)
  local fishPondTpl = L_GameTpl:getFishPondTpl()
  local tpl = fishPondTpl:getTplById(fishPointId)
  local dis = fishPondTpl:getCameraDistance(tpl)
  local angleVer = fishPondTpl:getCameraAngleVer(tpl)
  local angleHor = fishPondTpl:getCameraAngleHor(tpl)
  local playerRot = L_Vector3.getLocalRot(self.entity:getGameObject().transform)
  local body = self.virCamera:GetCinemachineComponent(0)
  local anim = self.virCamera:GetCinemachineComponent(1)
  local horizontal = anim.m_HorizontalAxis
  horizontal.Value = playerRot.y - 180 + angleHor
  anim.m_HorizontalAxis = horizontal
  local vertical = anim.m_VerticalAxis
  vertical.Value = angleVer
  anim.m_VerticalAxis = vertical
  body.m_CameraDistance = dis
end

function this:initVirCamera()
  local goVirCam = L_GameUtil.loadVirtualCamera(nil, PATH_CAMERA)
  self.virCamera = goVirCam:GetComponent(typeof(C_CinemachineVirtualCamera))
  self.cameraTactics = C_CameraManager.CreateCommonTactics(goVirCam, C_CinemachineBlendType.Cut, false)
end

function this:onDestroy()
  if L_CommonUtil.isValid(self.virCamera) then
    C_GameObject.Destroy(self.virCamera.gameObject)
  end
  self.virCamera = nil
  C_CameraManager.RemoveTactics(self.cameraTactics)
  self.entity = nil
end

return this
