local this = L_BevTree:registClass("guide.checkAnyInputs", L_BevTree.action)

function this:param()
  self.isOnlyTouch = 0
  self.detectKeycode = ""
end

function this:parse()
  self.isOnlyTouch = self:getParam("isOnlyTouch", true)
  self.detectKeycode = self:getParam("detectKeycode")
end

function this:onEnter()
  local keyCode = L_GameTpl:getKeyCodeTpl().data
  self.keys = {}
  for k, v in ipairs(keyCode) do
    table.insert(self.keys, v.keyCode)
  end
  self.result = L_BevTree.taskResult.Running
end

function this:execute()
  if self.result == L_BevTree.taskResult.Running then
    local keys = self.keys
    if not string.isEmpty(self.detectKeycode) then
      keys = string.split(self.detectKeycode, "|")
    end
    if Unity.Input.anyKeyDown and self.isOnlyTouch == 0 and not Unity.Input.GetKeyDown(Unity.KeyCode.LeftAlt) and not Unity.Input.GetKeyDown(Unity.KeyCode.RightAlt) then
      for k, v in ipairs(keys) do
        local key = Unity.KeyCode[v]
        if key ~= nil and Unity.Input.GetKeyDown(key) then
          self.result = L_BevTree.taskResult.Success
        end
      end
    end
    if string.isEmpty(self.detectKeycode) then
      if self.isOnlyTouch == 0 and (Unity.Input.GetAxis("Horizontal") ~= 0 or Unity.Input.GetAxis("Vertical") ~= 0) then
        self.result = L_BevTree.taskResult.Success
      end
      if Unity.Input.GetMouseButton(0) or Unity.Input.GetMouseButton(1) or Unity.Input.GetMouseButton(2) then
        self.result = L_BevTree.taskResult.Success
      end
      if 0 < Unity.Input.touchCount then
        self.result = L_BevTree.taskResult.Success
      end
    end
  end
  return self.result
end

function this:onFinish()
end

return this
