local Base = require("Battle/Logic/Level/LevelItemFactory/LevelItem") local VisualObject = require("Battle/Expression/VisualObject") local LevelItem_Obstruct = class("LevelItem_Obstruct", Base) local PATH_EFFECT = ConstAssetPathConfig.PATH_EFFECT1 local SHOW_LENGTH = 2 local EFFECT_COLLIDER_HEIGHT = 4 function LevelItem_Obstruct:initialize(data) Base.initialize(self,data) LuaShoveManager.SetObstructData(data.LevelItemID, data.ItemPos, data.ItemDir, data.Length, data.Width) self._objectList = {} end --region --***************生命周期***************-- function LevelItem_Obstruct:OnActive() if Base.OnActive(self) then LuaShoveManager.OpenObstruct(self.LevelItemID) local itemData = self.ItemData local effectStay = itemData.EffectStay if not string.isNilOrEmpty(itemData.Effect) then local path = string.format(PATH_EFFECT,itemData.Effect) local center_px, center_pz = FP.tonumberV2(itemData.ItemPos) local dx, dz = FP.tonumberV2(itemData.ItemDir) local count = math.ceil(itemData.ShowLength/ SHOW_LENGTH) local right_dx = dz local right_dz = -dx local offset = count / 2 - 0.5 local start_px = center_px - right_dx * offset * SHOW_LENGTH local start_pz = center_pz - right_dz * offset * SHOW_LENGTH local effectZ = FP.tonumberV1(itemData.Width)/2 for i = 0, count-1 do local px = start_px + right_dx * i * SHOW_LENGTH local pz = start_pz + right_dz * i * SHOW_LENGTH local obstructObj if effectStay then obstructObj = VisualObject.CreateVisualObject(path, ExpLevelManager.SceneObjParent) obstructObj:SetPositionAndDirection(dx, dz,px, 0, pz + effectZ, -0.5) else obstructObj = VisualObject.CreateObstructEffectTrigger(ExpLevelManager.SceneObjParent, path, SHOW_LENGTH, EFFECT_COLLIDER_HEIGHT, itemData.ShowWidth) obstructObj:SetPositionAndDirection(dx, dz,px, 0, pz) obstructObj:Invoke('SetChildLocalPosition', 0, -0.5, effectZ) end table.insert(self._objectList, obstructObj) end end return true end end function LevelItem_Obstruct:OnDeactive() if Base.OnDeactive(self) then LuaShoveManager.CloseObstruct(self.LevelItemID) for i = #self._objectList,1,-1 do self._objectList[i]:Dispose() self._objectList[i] = nil end return true end end --endregion 生命周期 --region --***************事件相关***************-- function LevelItem_Obstruct:DoAction(actionType, match) Base.DoAction(self, actionType) if actionType == LuaConst.LevelActionType.Obstruct_Active then self:OnActive() elseif actionType == LuaConst.LevelActionType.Obstruct_Deactive then self:OnDeactive() end end --endregion 事件相关 return LevelItem_Obstruct