local ConditionHandle = require('Battle/Logic/Level/LevelItemFunction/LevelConditionHandle') local LevelEventCondition = class("LevelEventCondition") --[[ 事件的条件管理类型 _eventBelong:所属的关卡事件 ]]-- function LevelEventCondition:initialize(condition, event) self.Data = condition self._eventBelong = event ConditionHandle.RegisterEvent(self) end -- 收到信号,修改标志位,并检测是否执行actions -- context 是个临时变量,不可直接存储 -- ... 为不定参 function LevelEventCondition:OnMessage(itemId, context, ...) if not self.Data then --由于EventSystem的UnregistCache机制,有可能出现Destroy后还能接收到Message的情况,所以添加判空 --logging.error(LTAG.ERROR, "注意:关卡条件丢失数据!") return end local conditionType = self.Data.Type local handleFunc = ConditionHandle[conditionType] if handleFunc and not handleFunc(self, ...) then return end if not self.Data.IsPulse then self.InReachState = true end self._eventBelong:OnConditionReach(self, context) end function LevelEventCondition:OnReset() ConditionHandle.ClearCondition(self) self.InReachState = nil end -- 销毁- 跟随事件一起销毁 function LevelEventCondition:OnDestroy() ConditionHandle.UnregisterEvent(self) self:OnReset() self._eventBelong = nil self.Data = nil end return LevelEventCondition