local WorldAlCenterSelectEffectManager = BaseClass("WorldAlCenterSelectEffectManager", Singleton)
local ResourceManager = CS.GameEntry.Resource
local ColorSelf = Color.New(0, 1, 0, 1)
local ColorOther = Color.New(1, 0, 0, 1)
local __init = function(self)
  self.rangeObjMat = nil
  self:AddListener()
end
local __delete = function(self)
  self:RemoveListener()
  self:RemoveEffect()
end
local AddListener = function(self)
  EventManager:GetInstance():AddListener(EventId.PveLevelEnter, self.RemoveAllTips)
  EventManager:GetInstance():AddListener(EventId.OnEnterWorld, self.OnEnterWorld)
  EventManager:GetInstance():AddListener(EventId.OnEnterCity, self.OnEnterCity)
end
local RemoveListener = function(self)
  EventManager:GetInstance():RemoveListener(EventId.PveLevelEnter, self.RemoveAllTips)
  EventManager:GetInstance():RemoveListener(EventId.OnEnterWorld, self.OnEnterWorld)
  EventManager:GetInstance():RemoveListener(EventId.OnEnterCity, self.OnEnterCity)
end
local RemoveAllTips = function(data)
  WorldAlCenterSelectEffectManager:GetInstance():RemoveEffect()
end
local OnEnterWorld = function(data)
end
local OnEnterCity = function(data)
  WorldAlCenterSelectEffectManager:GetInstance():RemoveEffect()
end
local ShowPos = function(self, pointId, state, serverId)
  if self.effectInstance ~= nil then
    if self.effectInstance.gameObject ~= nil then
      self.effectInstance.gameObject:SetActive(true)
      local posV3 = SceneUtils.TileIndexToWorld(pointId, ForceChangeScene.World, serverId)
      self.effectInstance.gameObject.transform.position = posV3
      if self.rangeObjMat ~= nil then
        if state == BuildPutState.Ok then
          self.rangeObjMat.color = ColorSelf
        else
          self.rangeObjMat.color = ColorOther
        end
      end
    end
  else
    local request = ResourceManager:InstantiateAsync("Assets/Main/Prefabs/Building/AllianceSelectRange.prefab")
    self.effectInstance = request
    local pointIndex = pointId
    local theServerId = serverId
    request:completed("+", function()
      if request.isError then
        self.effectInstance = nil
        return
      end
      request.gameObject:SetActive(true)
      request.gameObject.transform:SetParent(CS.SceneManager.World.DynamicObjNode)
      request.gameObject.transform:Set_localScale(ResetScale.x, ResetScale.y, ResetScale.z)
      local posV3 = SceneUtils.TileIndexToWorld(pointIndex, ForceChangeScene.World, theServerId)
      request.gameObject.transform.position = posV3
      local range = request.gameObject.transform:Find("range"):GetComponent(typeof(CS.UnityEngine.Renderer))
      if range ~= nil then
        self.rangeObjMat = range.material
      end
      if state == BuildPutState.Ok then
        self.rangeObjMat.color = ColorSelf
      else
        self.rangeObjMat.color = ColorOther
      end
    end)
  end
end
local HidePos = function(self)
  self:RemoveEffect()
end
local RemoveEffect = function(self)
  if self.effectInstance ~= nil then
    self.effectInstance:Destroy()
    self.effectInstance = nil
  end
end
WorldAlCenterSelectEffectManager.OnEnterWorld = OnEnterWorld
WorldAlCenterSelectEffectManager.OnEnterCity = OnEnterCity
WorldAlCenterSelectEffectManager.__init = __init
WorldAlCenterSelectEffectManager.__delete = __delete
WorldAlCenterSelectEffectManager.AddListener = AddListener
WorldAlCenterSelectEffectManager.RemoveListener = RemoveListener
WorldAlCenterSelectEffectManager.RemoveEffect = RemoveEffect
WorldAlCenterSelectEffectManager.ShowPos = ShowPos
WorldAlCenterSelectEffectManager.HidePos = HidePos
WorldAlCenterSelectEffectManager.RemoveAllTips = RemoveAllTips
return WorldAlCenterSelectEffectManager
