| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- local Progressor = require("CommonUtils/Object/Object.lua"):new()
- Progressor.nFillTime = 0
- Progressor.nCooldownTime = 0
- Progressor.bFilled = false
- Progressor.nCanFillTime = os.time()
- local FULL_FILL_TIME = 1.5
- function Progressor:FillProgressor(bFill, funCallback)
- local nTimeNow = os.time()
- if nTimeNow < self.nCanFillTime then
- return 0
- end
- if self.bFilled then
- return 1
- end
- if bFill then
- local eventManager = require('Base/ZEventDispatchCenter.lua')
- eventManager:DispatchEvent(eventManager.EventType.COMMON_SET_GESTUREINPUT)
- self.nFillTime = self.nFillTime + CS.UnityEngine.Time.deltaTime
- local nFillAmount = self.nFillTime / FULL_FILL_TIME
- if nFillAmount >= 1 then
- nFillAmount = 1
- self.bFilled = true
- funCallback()
- end
- return nFillAmount
- end
- self.nFillTime = self.nFillTime - CS.UnityEngine.Time.deltaTime
- local nFillAmount = self.nFillTime / FULL_FILL_TIME
- if nFillAmount <= 0 then
- self.nFillTime = 0
- nFillAmount = 0
- end
- return nFillAmount
- end
- function Progressor:FillProgressorRepeat(bFill, funCallback)
- local nTimeNow = os.time()
- if nTimeNow < self.nCanFillTime then
- return 0
- end
- if bFill then
- local eventManager = require('Base/ZEventDispatchCenter.lua')
- eventManager:DispatchEvent(eventManager.EventType.COMMON_SET_GESTUREINPUT)
- self.nFillTime = self.nFillTime + CS.UnityEngine.Time.deltaTime
- local nFillAmount = self.nFillTime / FULL_FILL_TIME
- if nFillAmount >= 1 then
- nFillAmount = 1
- self.nFillTime = 0
- funCallback()
- end
- return nFillAmount
- end
- self.nFillTime = self.nFillTime - CS.UnityEngine.Time.deltaTime
- local nFillAmount = self.nFillTime / FULL_FILL_TIME
- if nFillAmount <= 0 then
- self.nFillTime = 0
- nFillAmount = 0
- end
- return nFillAmount
- end
- function Progressor:SetCooldown(nPeriodTime)
- if not nPeriodTime then nPeriodTime = 1 end
- self.nFillTime = 0
- self.bFilled = false
- self.nCanFillTime = os.time() + nPeriodTime
- end
- -- function Progressor.FillProgressor(szDataRelayKey, bFill, funCallback)
- -- local tProgessor = GetCache(szDataRelayKey)
- -- local nTimeNow = os.time()
- -- if nTimeNow < tProgessor.nCanFillTime then
- -- return 0
- -- end
- -- if tProgessor.bFilled then
- -- return 1
- -- end
- -- if bFill then
- -- local eventManager = require('Base/ZEventDispatchCenter.lua')
- -- eventManager:DispatchEvent(eventManager.EventType.COMMON_SET_GESTUREINPUT)
- -- tProgessor.nFillTime = tProgessor.nFillTime + CS.UnityEngine.Time.deltaTime
- -- local nFillAmount = tProgessor.nFillTime / FULL_FILL_TIME
- -- if nFillAmount >= 1 then
- -- funCallback()
- -- nFillAmount = 1
- -- tProgessor.bFilled = true
- -- end
- -- SetCache(szDataRelayKey, tProgessor)
- -- return nFillAmount
- -- end
- -- tProgessor.nFillTime = tProgessor.nFillTime - CS.UnityEngine.Time.deltaTime
- -- local nFillAmount = tProgessor.nFillTime / FULL_FILL_TIME
- -- if nFillAmount <= 0 then
- -- tProgessor.nFillTime = 0
- -- nFillAmount = 0
- -- end
- -- SetCache(szDataRelayKey, tProgessor)
- -- return nFillAmount
- -- end
- -- function Progressor.SetCooldown(szDataRelayKey, nPeriodTime)
- -- if not nPeriodTime then nPeriodTime = 1 end
- -- local tProgessor = GetCache(szDataRelayKey)
- -- tProgessor.nCanFillTime = os.time() + nPeriodTime
- -- SetCache(szDataRelayKey, tProgessor)
- -- end
- -- function Progressor.InitDataRelay(szDataRelayKey)
- -- local tProgressorData = {
- -- ["nFillTime"] = 0,
- -- ["nCooldownTime"] = 0,
- -- ["bFilled"] = false,
- -- ["nCanFillTime"] = os.time(),
- -- }
- -- SetCache(szDataRelayKey, tProgressorData)
- -- end
- return Progressor
|