local this = class("entityManager", G_EventManagerBase)
this.event = {
  createEntity = "createEntity",
  destroyEntity = "destroyEntity",
  destroyAllEntity = "destroyAllEntity",
  createMount = "createMount",
  triggerStack = "triggerStack"
}
this.node = {
  photo = "[World-Photo]"
}
table.merge(this, require(L_R.world.coreMgr .. "entity.entityManager_res"))
table.merge(this, require(L_R.world.coreMgr .. "entity.entityManager_hero"))
table.merge(this, require(L_R.world.coreMgr .. "entity.entityManager_photo"))

function this:ctor()
  this.super.ctor(self)
  self.rootLock = {}
  self.root = {}
  for _, v in pairs(self.node) do
    self:getRoot(v, true)
  end
  self.deSpawnRoot = Unity.GameObject("[entitySpawn]").transform
  self.asyncSpawnPool = L_PoolManager:getAsyncSpawnPool(self.deSpawnRoot)
end

function this:getRoot(rootName, isCreate)
  if self.root[rootName] == nil and isCreate ~= false then
    local trans = C_GameObject(rootName).transform
    trans.transform.position = L_Vector3.getTemp()
    trans.transform:SetRelativeEulerAngles(L_Vector3.getTemp())
    self.root[rootName] = trans
  end
  return self.root[rootName]
end

function this:showOrHideRoot(type, isShow)
  AzurWorldInstance:SetNodeVisible(type, isShow, L_Const.worldNodeHideType.LuaUIControlHide)
end

function this:showOrHideAllRoot(isShow, key)
  key = key or L_Const.moduleControl.default
  if isShow then
    self.rootLock[key] = nil
  else
    self.rootLock[key] = isShow
  end
  isShow = next(self.rootLock) == nil
  for _, v in pairs(self.root) do
    v.gameObject:ActiveTrans(isShow)
  end
  AzurWorldInstance:SetAllNodeVisible(isShow)
  local playerEntity = L_PlayerManager:getMainControlEntity()
  if playerEntity then
    playerEntity:setFsmLeave(not isShow)
  end
end

function this:dispose()
end

function this:generatePreviewPet(petGuid, go, petData)
  local entity = require(L_EcsConst.aliveType.previewPet).new(L_EcsConst.aliveType.previewPet)
  entity:initPreview(petGuid, go, petData)
  return entity
end

return this
