--[[ Tips: 1. DataRelay.lua => add cache key 2. require("CommonUtils/Progressor/Progressor.lua").InitDataRelay(szKey) 3. require("CommonUtils/Progressor/Progressor.lua").SetCooldown(szKey, nPeriodTime) nPeriodTime => s 4. Update() => nFillAmount = require("CommonUtils/Progressor/Progressor.lua").FillProgressor(szKey, bFill, funCallback) ]] local DemoProgressor = {} local progressorA local progressorD local function ProgressorCallbackA() print("----> DemoProgressor.ProgressorCallbackA") end local function ProgressorCallbackD() print("----> DemoProgressor.ProgressorCallbackD") end local function CheckKeyA() local bFill = CS.UnityEngine.Input.GetKey(CS.UnityEngine.KeyCode.A) -- local nFillAmount = require("CommonUtils/Progressor/Progressor.lua").FillProgressor("PROGRESSOR_DEMO_A", bFill, ProgressorCallbackA) local imgCom = DemoProgressor.rootPanel.transform:Find("Img_A"):GetComponent("Image") imgCom.fillAmount = progressorA:FillProgressor(bFill, ProgressorCallbackA) end local function CheckKeyD() local bFill = CS.UnityEngine.Input.GetKey(CS.UnityEngine.KeyCode.D) -- local nFillAmount = require("CommonUtils/Progressor/Progressor.lua").FillProgressor("PROGRESSOR_DEMO_D", bFill, ProgressorCallbackD) local imgCom = DemoProgressor.rootPanel.transform:Find("Img_D"):GetComponent("Image") imgCom.fillAmount = progressorD:FillProgressor(bFill, ProgressorCallbackD) end local function RefreshUI() progressorA = require("CommonUtils/Progressor/Progressor.lua"):new() progressorA:SetCooldown(2) progressorD = require("CommonUtils/Progressor/Progressor.lua"):new() progressorD:SetCooldown(5) -- require("CommonUtils/Progressor/Progressor.lua").InitDataRelay("PROGRESSOR_DEMO_A") -- require("CommonUtils/Progressor/Progressor.lua").SetCooldown("PROGRESSOR_DEMO_A", 2) -- require("CommonUtils/Progressor/Progressor.lua").InitDataRelay("PROGRESSOR_DEMO_D") -- require("CommonUtils/Progressor/Progressor.lua").SetCooldown("PROGRESSOR_DEMO_D", 5) end local function OnClickBtnExit() require("Base/UIHelper.lua"):SwitchUI("CommonUtils/DemoLuaScripts/DemoAll.lua", "CommonUtils/DemoLuaScripts/DemoProgressor.lua") end local function RegisterTouchEvent() local uiHelper = require("Base/UIHelper.lua") local rootPanel = DemoProgressor.rootPanel uiHelper:AddClickEvent(rootPanel, "Btn_Exit", OnClickBtnExit) end function DemoProgressor.Awake(luaRoot) DemoProgressor.luaRoot = luaRoot local canvas = CS.UnityEngine.GameObject.Find('Canvas') DemoProgressor._rootCanvas = canvas local prefabTest = LoadResource('CommonUtils/Prefabs/Demo/ZDemoProgressorPanel.prefab') local rootPanel = CS.UnityEngine.GameObject.Instantiate(prefabTest, canvas.transform) DemoProgressor.rootPanel = rootPanel end function DemoProgressor.Start() RefreshUI() RegisterTouchEvent() end function DemoProgressor.Update() CheckKeyA() CheckKeyD() end function DemoProgressor.OnDestroy() CS.UnityEngine.GameObject.Destroy(DemoProgressor.rootPanel) end return DemoProgressor