local WorldCanBuildEffectManager = BaseClass("WorldCanBuildEffectManager", Singleton)
local ResourceManager = CS.GameEntry.Resource
local WorldCanBuildEffect = require("Scene.WorldCanBuildEffect.WorldCanBuildEffect")
local __init = function(self)
  self.allEffect = nil
  self.OnCreateEffect = nil
  self:AddListener()
end
local AddListener = function(self)
  EventManager:GetInstance():AddListener(EventId.ShowCanBuildEffect, self.ShowEffectSignal)
  EventManager:GetInstance():AddListener(EventId.HideCanBuildEffect, self.HideEffectSignal)
end
local RemoveListener = function(self)
  EventManager:GetInstance():RemoveListener(EventId.ShowCanBuildEffect, self.ShowEffectSignal)
  EventManager:GetInstance():RemoveListener(EventId.HideCanBuildEffect, self.HideEffectSignal)
end
local ShowEffectSignal = function(data)
  WorldCanBuildEffectManager:GetInstance():ShowEffect()
end
local HideEffectSignal = function(data)
  WorldCanBuildEffectManager:GetInstance():RemoveEffect()
end
local __delete = function(self)
  self:RemoveListener()
  if self.allEffect ~= nil then
    local request = self.allEffect.request
    self.allEffect.script:OnDestroy()
    request:Destroy()
  end
  self.allEffect = nil
end
local ShowEffect = function(self)
  if self.allEffect == nil and self.OnCreateEffect == nil then
    local request = ResourceManager:InstantiateAsync(UIAssets.WorldCanBuildEffect)
    local par = {}
    par.request = request
    self.OnCreateEffect = request
    request:completed("+", function()
      self.OnCreateEffect = nil
      if request.isError then
        return
      end
      request.gameObject:SetActive(true)
      request.gameObject.transform:Set_localScale(ResetScale.x, ResetScale.y, ResetScale.z)
      local effect = WorldCanBuildEffect.New()
      effect:OnCreate(request)
      effect:ReInit()
      par.script = effect
      self.allEffect = par
    end)
  elseif self.allEffect ~= nil then
    self.allEffect.script:ReInit()
  end
end
local RemoveEffect = function(self)
  if self.allEffect ~= nil then
    local request = self.allEffect.request
    self.allEffect.script:OnDestroy()
    request:Destroy()
  end
  self.allEffect = nil
end
WorldCanBuildEffectManager.__init = __init
WorldCanBuildEffectManager.__delete = __delete
WorldCanBuildEffectManager.ShowEffectSignal = ShowEffectSignal
WorldCanBuildEffectManager.HideEffectSignal = HideEffectSignal
WorldCanBuildEffectManager.RemoveEffect = RemoveEffect
WorldCanBuildEffectManager.AddListener = AddListener
WorldCanBuildEffectManager.RemoveListener = RemoveListener
WorldCanBuildEffectManager.ShowEffect = ShowEffect
return WorldCanBuildEffectManager
