local Base = require("Battle/Logic/Level/LevelItemFactory/LevelItem") local LevelItem_WalkPath = class("LevelItem_WalkPath", Base) local VisualObject = require("Battle/Expression/VisualObject") function LevelItem_WalkPath:initialize(data) Base.initialize(self,data) end --region --***************生命周期***************-- function LevelItem_WalkPath:OnActive() if Base.OnActive(self) then if self.ItemData.SeeDefault then if self.ItemData.ObjectPath and self.ItemData.ObjectPath ~= "" then self:CreateWalkPathObject() end else if self.ItemData.WalkShows then self:CreateWalkPathObject() end end return true end end function LevelItem_WalkPath:OnDeactive() if Base.OnDeactive(self) then self:ClearWalkPathObject() return true end end --endregion 生命周期 --region --***************事件相关***************-- function LevelItem_WalkPath:DoAction(actionType, match, param1) if actionType == LuaConst.LevelActionType.WalkPath_Show then if param1 then self:OnActive() else self:OnDeactive() end end end --endregion 事件相关 --region --***************内部方法***************-- function LevelItem_WalkPath:ClearWalkPathObject() if self._walkObjectList then for i = #self._walkObjectList, 1, -1 do self._walkObjectList[i]:Dispose() self._walkObjectList[i] = nil end end self._walkObjectList = nil end function LevelItem_WalkPath:CreateWalkPathObject() self._walkObjectList = {} local data = self.ItemData local objPath -- 资源路径 local accumulateLength = 0 -- 总长度 local preTotalLength = 0 -- 两点间长度 local prefabInterval = 1 -- 资源间隔 local curPosY = 0 if data.ItemPosY then curPosY = data.ItemPosY -- 不吸附地面的高度 end if data.SeeDefault then objPath = data.ObjectPath prefabInterval = data.PrefabInterval else --LevelPlayerManager.MainEntityCampID --主视角safe local walkShowData = data.WalkShows[LevelPlayerManager.MainEntityCampID] if walkShowData then objPath = walkShowData.ObjectPath -- 资源路径 prefabInterval = walkShowData.PrefabInterval end end if objPath == nil or objPath == "" then return end local logicPos = FP.newV2(0,0) local logicDir = FP.newV2(0,0) local path = data.PathPoints -- 路点数组 for i = 1, #path - 1 do local current = path[i] local next = path[i+1] local length = FP.tonumberV1(FP.V2.Distance(next,current)) logicDir:Reset(next):Sub(current):Normalize() local totalLength = preTotalLength + length while accumulateLength < totalLength do logicPos:Reset(logicDir):Mul(accumulateLength - preTotalLength):Add(current) local point = VisualObject.CreateVisualObject(objPath,ExpLevelManager.SceneObjParent) local px, pz = FP.tonumberV2(logicPos) local cx, cz = FP.tonumberV2(current) local nx, nz = FP.tonumberV2(next) point:Invoke("SetPositionAndDirection",cx, cz, nx, nz,px, 0, pz) table.insert(self._walkObjectList, point) accumulateLength = accumulateLength + prefabInterval end preTotalLength = totalLength end end --endregion 内部方法 return LevelItem_WalkPath