local this = class("cameraController_homeBuild", require("ui.manager.camera.controller.cameraController"))
local _homeCollectionWorldTpl = L_GameTpl:getHomeCollectionWorldTpl()
local _homeBuildingCollectionTpl = L_GameTpl:getHomeBuildingCollectionTpl()
local PATH_CAMERA = "Program/Camera/pre_collectionCamera.prefab"

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

function this:switchIn(preMode, params)
  local goVirCam = L_GameUtil.loadVirtualCamera(nil, PATH_CAMERA)
  self.virCamera = goVirCam:GetComponent(typeof(C_CinemachineVirtualCamera))
  self.cameraTactics = C_CameraManager.CreateCommonTactics(goVirCam, C_CinemachineBlendType.EaseInOut, true)
end

function this:switchOut(nextMode)
  C_CameraManager.SetBrainBlendStyle(L_Const.blendStyle.cut)
  self:onDestroy()
end

function this:setData(transform, dis)
  local cameraNode = transform
  self.virCamera.Follow = cameraNode
  self.virCamera.LookAt = cameraNode
  local body = self.virCamera:GetCinemachineComponent(0)
  local anim = self.virCamera:GetCinemachineComponent(1)
  local rot = L_Vector3.getRot(transform)
  local horizontal = anim.m_HorizontalAxis
  horizontal.Value = rot.y - 180
  anim.m_HorizontalAxis = horizontal
  local vertical = anim.m_VerticalAxis
  vertical.Value = rot.x
  anim.m_VerticalAxis = vertical
  body.m_CameraDistance = dis or 2
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
