local this = {}
local m_touchEffect = "UI/UIEffect/TouchEffect/pre_touchEffect.prefab"

function this:initTouch()
  self.touchQueue = L_Struct.getQueue()
  self.onClickEvent = L_CommonUtil.handle(self.onSceenTouch_click, self)
  self.pool:preload(m_touchEffect, 1)
  C_ScreenTouch.On_Touch("+", self.onClickEvent)
  C_ScreenTouch.OnUI_Touch("+", self.onClickEvent)
end

function this:onSceenTouch_click(gesture)
  if L_DeviceTpl:getIsPc() and not L_CameraManager:getShowCursor() then
    return
  end
  local length = self.touchQueue:getLength()
  local effect
  if 5 <= length then
    effect = self.touchQueue:deQueue()
  else
    effect = self.pool:spawn(m_touchEffect)
    effect = effect:GetComponent(typeof(C_RectTransform))
    effect:Reset(self.touchRoot, true)
  end
  effect.gameObject:ActiveTrans(false)
  effect.gameObject:ActiveTrans(true)
  self.touchQueue:enQueue(effect)
  local touchPos = L_Vector3.screenToLocalInRectangle(self.touchRoot, gesture.position)
  L_Vector3.setAnchored(effect, touchPos)
end

function this:disposeTouch()
  if self.onClickEvent then
    C_ScreenTouch.On_Touch("-", self.onClickEvent)
    C_ScreenTouch.OnUI_Touch("-", self.onClickEvent)
    self.onClickEvent = nil
  end
end

return this
