--- 场景中的表演物 ,纯表现的,不涉及任何逻辑 ---使用的代码不要用逻辑相关的接口 local Base = require("Battle/Logic/Level/LevelItemFactory/LevelItem") local LevelItem_SceneActor = class("LevelItem_SceneActor", Base) local string_isNilOrEmpty = string.isNilOrEmpty local tonumberV2 = FP.tonumberV2 local Const_VisualPriority = 10000 local Const_Layer = LuaConst.Layer.Soldier_Friend local ExpEntity = require "Battle/Expression/ExpEntity/ExpEntity" local SceneActorParent = nil function LevelItem_SceneActor:initialize(data) Base.initialize(self,data) self._renderEntity = nil -- 所出生的renderEntity self._modelData = DataSheetManager.MonsterModelData:GetDataByID(data.MonsterModelID) self.motionCount = #data.MotionInfos self.playTime = FP.newV1(0) self._showTime = data.IdleTime -- 默认先是idle self.curState = 0 -- 0 处于idle ,1 正在播放动作 self.isCameraLook = false -- 是否被相机强制观看 end function LevelItem_SceneActor:SetIsCameraLook(val) self.isCameraLook = val end function LevelItem_SceneActor:OnDestroy() Base.OnDestroy(self) if self._renderEntity then self._renderEntity:Dispose(false) if self.isCameraLook then ExpSystemManager.SetForceLookRenderEntity(nil) ExpSystemManager.SetCurEntity(LogicUpdateManager._curEntity.ExpEntity) end end self._renderEntity = nil-- 所有出生的entity end --region --***************生命周期***************-- function LevelItem_SceneActor:OnActive() if Base.OnActive(self) then self:CreateRenderEntity() return true end end function LevelItem_SceneActor:OnDeactive() if Base.OnDeactive(self) then if self._renderEntity then self._renderEntity:Dispose(false) if self.isCameraLook then ExpSystemManager.SetForceLookRenderEntity(nil) ExpSystemManager.SetCurEntity(LogicUpdateManager._curEntity.ExpEntity) end end self._renderEntity = nil-- 所有出生的entity return true end end -- 播放动画。 动画名字要求: GPU用clipName或者triggerStr都可以 ; 非GPU的需要用triggerStr function LevelItem_SceneActor:OnUpdate() if USE_LUA_STANDALONE then -- 校验程序不需要 return end if self.motionCount < 1 then return end self.playTime:Add(LuaConst.TimeSpan) if self.playTime >= self._showTime then local animStr = nil if self.curState == 0 then -- idle - 特殊动画 local randomIndex = math.random(1, self.motionCount) -- 因为是表现代码,不用逻辑随机是没问题的。 local motionInfo = self.ItemData.MotionInfos[randomIndex] animStr = motionInfo.MotionName self._showTime = motionInfo.Duration self.curState = 1 elseif self.curState == 1 then -- 特殊动画 -> idle animStr = self.ItemData.IdleName self._showTime = self.ItemData.IdleTime self.curState = 0 end local animIntKey= UTL.String.GetIdByString(animStr) self._renderEntity:PlayAnimation(animIntKey ,false,false, 0) self.playTime:Reset() end end --endregion 生命周期 --region --***************事件相关***************-- function LevelItem_SceneActor:DoAction(actionType, match, param1) Base.DoAction(self, actionType,param1) if actionType == LuaConst.LevelActionType.Npc_Active then self:OnActive() elseif actionType == LuaConst.LevelActionType.Delete then if self._renderEntity then self._renderEntity:Dispose(false) end end end --endregion 事件相关 --region --***************内部方法***************-- function LevelItem_SceneActor:CreateRenderEntity() if USE_LUA_STANDALONE then -- 校验程序不需要 return end local data = self.ItemData local modelData = self._modelData if SceneActorParent == nil then SceneActorParent = ExpLevelManager.SceneObjParent -- 623001 if SceneActorParent == nil then SceneActorParent = AuxUtil.GetEmptyObject(nil, "SceneActors").transform end end local cullingMode if GameAppInfo.IsVersionGreaterThan114000() then cullingMode = LuaConst.EntityCullingMode.NoCulling else cullingMode = false end local px, pz = tonumberV2(data.ItemPos) local dx, dz = tonumberV2(data.ItemDir) local renderEntity = ExpEntity.LoadRenderEntity(modelData, true, px, pz, dx, dz, not LevelManager.IsNoBattleLevel(), Const_Layer, -1, Const_VisualPriority, -1, false, cullingMode, SceneActorParent) self._renderEntity = renderEntity end --endregion 内部方法 return LevelItem_SceneActor