local this = class("previewHeroEntity", require(L_EcsConst.aliveType.preview))
local CapsuleCollider = CS.UnityEngine.CapsuleCollider

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

function this:getUnitId()
  local unitId = L_GameUtil.getUnitIdByRole(self.entityId, L_Const.roleType.hero)
  return unitId
end

function this:setAnimatorController(playableAnimator, animatorConfig)
  local isPlayer = self.entityId == L_GameUtil.getDefaultHeroId()
  if not isPlayer then
    local unitTpl = L_GameTpl:getUnitTpl()
    local unit = unitTpl:getTplById(self.unitId)
    playableAnimator.defaultAnimatorController = C_LuaUtility.LoadPlayableController(unitTpl:getAnimatorConfig(unit, animatorConfig ~= nil and animatorConfig or L_Const.avatarAnimatorConfigIndex.uiPreview)).config
  end
end

function this:setIk()
  local groundIk = L_CommonUtil.getModComponent(typeof(C_GrounderIK), self.gameObject)
  if groundIk then
    groundIk.enabled = false
    for i = 0, groundIk.legs.Length - 1 do
      groundIk.legs[i].enabled = false
    end
  end
end

function this:createCollider()
  this.super.createCollider(self)
  local formationTpl = L_GameTpl:getFormationTpl()
  local tpl = formationTpl:getTplById(self.unitId)
  local colliderCenter, colliderRadius, colliderHeight = formationTpl:getFormationCollider(tpl)
  local collider = self.gameObject:PickComponent(typeof(CapsuleCollider))
  collider.center = colliderCenter
  collider.radius = colliderRadius
  collider.height = colliderHeight
end

return this
