local UIHeroLightEffectTool = {} local EFFECTPATH = ConstAssetPathConfig.PsGroupPath local private = { needLoopDataDic = {} } local effectLoopInterval = 1 --调用方法枚举,本质上是模型自带的方法 UIHeroLightEffectTool.PlayLightEffectFuncEnum = { UI3DModel = "PlayCharacterModelEffect", UI3DDriver = "PlayDriverModelEffect", PlayerModel = "PlayModelEffect", CountryOfficial = "CountryOfficialPlayModelEffect", LuaView = "AuxUtilPlayPsEffect", } local LvBuFaXingLightEffectId = 204001 --吕布法相光效id local LowPosLvBuFaXingLightEffectPath = ConstAssetPathConfig.LowPosLvBuFaXingLightEffectPath --低位置的吕布法相资源路径 --region -------------------------通用界面特效 ------------------- --播放光效的接口(1/3) View OnCreated时初始化特效数据 --isShowFootprint 是否显示脚部特效 function UIHeroLightEffectTool.CreateHeroLightEffectDatas(isShowFootprint) local datas = { isShowFootprint = isShowFootprint, } --下面的字段在运行时需要用到再创建 --datas.roleDic = nil --结构为 {roleKey:模型索引,{lightEffectID:特效ID,lightEffectRuntimeData:特效运行时数据}} return datas end --播放光效的接口(2/3) 开始播放 -- datas 整个view界面播放光效的运行时数据,view调用本方法前要先确保初始化了 -- objModel 模型 -- renderCameraId 渲染相机的机位,默认填0,意义是去RenderModelAsset.asset里获取一个相机位置的配置 -- funcEnum 使用哪个函数播放特效的枚举PlayLightEffectFuncEnum -- lightEffectID 光效的配置id -- param 支持自定义的参数,例如在CountryOfficialPlayModelEffect里传入了模型的位置 function UIHeroLightEffectTool.PlayHeroLightEffect(datas, objModel, renderCameraId, funcEnum, lightEffectID, param) --获取光效配置 local lightEffectData = DataSheetManager.LightEffect:GetDataByID(lightEffectID) --有配置则进入播放流程 if lightEffectData then --region 特殊处理区 if lightEffectData.Type == MDL.LightEffect.LightEffectType.Foot then --足底特效特殊处理,有些界面不显示就直接返回 if not datas.isShowFootprint then return end end if lightEffectData.PlayPsType == LuaConst.LightEffectType.IdleLoopShow and funcEnum == UIHeroLightEffectTool.PlayLightEffectFuncEnum.UI3DDriver then --骑马时不显示 特殊播放模式的光效 return end local realFuncEnum = funcEnum if lightEffectData.Type == MDL.LightEffect.LightEffectType.Foot then --特殊处理:足底特效需要修改播放方法 if funcEnum == UIHeroLightEffectTool.PlayLightEffectFuncEnum.UI3DDriver then realFuncEnum = UIHeroLightEffectTool.PlayLightEffectFuncEnum.UI3DModel end end local lightEffectIdKey = lightEffectID if (funcEnum == UIHeroLightEffectTool.PlayLightEffectFuncEnum.PlayerModel or funcEnum == UIHeroLightEffectTool.PlayLightEffectFuncEnum.UI3DDriver) and param then --特殊处理:支持一个模型上播放多个相同的光效 --会出现一个页面里显示两个武将骑马模型的情况,这里做一下Key上的区分 lightEffectIdKey = lightEffectID..param end --endregion 特殊处理区 --初始化模型-模型的所有光效的字典 if datas.roleDic == nil then datas.roleDic = {} end --初始化光效id-光效运行时数据的字典 if datas.roleDic[objModel] == nil then datas.roleDic[objModel] = {} end local effectDataDic = datas.roleDic[objModel] --去重 if effectDataDic[lightEffectIdKey] ~= nil then return end --获取特效文件路径 local lightEffectPath = private.GetLightEffectPath(lightEffectData, funcEnum, param) if CTL.HotFix.CanAssetLoad(lightEffectPath) == false then return end --初始化光效运行时数据 effectDataDic[lightEffectIdKey] = private.CreateEffectRuntimeData(realFuncEnum, renderCameraId, lightEffectPath, lightEffectData, param) local runtimeData = effectDataDic[lightEffectIdKey] --开始播放 runtimeData.psId = private.PlayEffect(objModel, runtimeData, datas) --有重复播放的特效,则开启轮询 if runtimeData.repeatDuration > 0 then private.AddToNeedLoopDataDic(datas) end end end --获取特效文件路径 --JWS2-44542需求 降低界面中吕布法相的位置,但因资源问题,无法直接修改位置大小,需加载低位置的法相资源 function private.GetLightEffectPath(lightEffectData, funcEnum, param) if lightEffectData.ID ~= LvBuFaXingLightEffectId then return string.format(EFFECTPATH, lightEffectData.EffectName) end --国家官员界面特殊需求,使用正常高位置的法相资源 if funcEnum == UIHeroLightEffectTool.PlayLightEffectFuncEnum.CountryOfficial and param and param.isUseHighEffect then return string.format(EFFECTPATH, lightEffectData.EffectName) end return LowPosLvBuFaXingLightEffectPath end --播放光效的统一接口(3/3) 停止播放 function UIHeroLightEffectTool.StopHeroLightEffect(datas) if datas.roleDic then for _, effectDataDic in pairs(datas.roleDic) do for _, effectRuntimeData in pairs(effectDataDic) do if effectRuntimeData and effectRuntimeData.psId > -1 then AuxUtil.StopPsEffect(effectRuntimeData.psId) end effectRuntimeData = nil end effectDataDic = nil end end datas.roleDic = nil if datas.curSoundId then CTL.Sound.StopById(datas.curSoundId) end private.needLoopDataDic[datas] = nil if private.repeatHandle ~= nil then TimerUtil.Remove(private.repeatHandle) private.repeatHandle = nil end end --创建光效运行时数据 function private.CreateEffectRuntimeData(funcEnum, renderCameraId, lightEffectPath, lightEffectData, param) local runtimeData = { funcEnum = funcEnum, renderCameraId = renderCameraId, lightEffectPath = lightEffectPath, soundName = lightEffectData.SoundName, param = param, repeatDuration = -1, remainTime = 0, } --初始化需要重复播放的光效 local repeatDuration = lightEffectData.RepeatPlay if repeatDuration > 0 then runtimeData.repeatDuration = repeatDuration runtimeData.remainTime = repeatDuration end return runtimeData end --需要反复播放的光效加入轮询table function private.AddToNeedLoopDataDic(datas) private.needLoopDataDic[datas] = 1 if private.repeatHandle == nil then private.repeatHandle = TimerUtil.Interval(private.PlayAlldDataLoopLightEffect, effectLoopInterval, 0) end end --工具内部轮询所有界面需要循环播放的光效 function private.PlayAlldDataLoopLightEffect() if next(private.needLoopDataDic) == nil then TimerUtil.Remove(private.repeatHandle) private.repeatHandle = nil return end for singleData,_ in pairs(private.needLoopDataDic) do private.PlaySingleDataLoopLightEffect(singleData) end end --单个界面的光效循环播放 function private.PlaySingleDataLoopLightEffect(datas) for objModel, effectDataDic in pairs(datas.roleDic) do for _, effectRuntimeData in pairs(effectDataDic) do if effectRuntimeData and effectRuntimeData.repeatDuration > 0 then local remainTime = effectRuntimeData.remainTime - effectLoopInterval effectRuntimeData.remainTime = remainTime if remainTime <= 0 then effectRuntimeData.remainTime = effectRuntimeData.repeatDuration AuxUtil.StopPsEffect(effectRuntimeData.psId) local lightEffectPsID = private.PlayEffect(objModel, effectRuntimeData, datas) effectRuntimeData.psId = lightEffectPsID end end end end end --光效单次播放 function private.PlayEffect(renderComp, effectRuntimeData, datas) local lightEffectPsID = -1 local func = effectRuntimeData.funcEnum if func == UIHeroLightEffectTool.PlayLightEffectFuncEnum.PlayerModel then lightEffectPsID = renderComp[func](renderComp, effectRuntimeData.renderCameraId, effectRuntimeData.lightEffectPath) elseif func == UIHeroLightEffectTool.PlayLightEffectFuncEnum.CountryOfficial then lightEffectPsID = renderComp[func](renderComp, effectRuntimeData.lightEffectPath, effectRuntimeData.param) else if effectRuntimeData.param then lightEffectPsID = renderComp[func](renderComp, effectRuntimeData.lightEffectPath, effectRuntimeData.param) else lightEffectPsID = renderComp[func](renderComp, effectRuntimeData.lightEffectPath) end end if not string.isNilOrEmpty(effectRuntimeData.soundName) then datas.curSoundId = CTL.Sound.PlayGameSound(effectRuntimeData.soundName) end return lightEffectPsID end -- todo暂时没用 UI3DModelComponent 脚本播放特效 function UIHeroLightEffectTool.PlayEffect_UI3D(effectSrt, lightEffectType) local parent = UnityEngine.GameObject.Find(ConstAssetPathConfig.Common2DScenePrefab) local parent1 = parent.transform:Find("HeroParent/EMPTY_GAME_OBJECT") if parent1 == nil then parent = parent.transform:Find("HeroParent/New Game Object") else parent = parent1 end parent = parent.transform:GetChild(0) if string.find(parent.name ,"Horse") and lightEffectType ~= LuaConst.LightEffectType.Footprint then parent = UTL.UIRender.FindInChildren(parent,"node_seat") parent = parent.transform:GetChild(0) end local effectID = AuxUtil.PlayPsEffect(effectSrt,parent.transform, 0) return effectID end -- todo暂时没用 UIRenderModel 脚本播放特效 function UIHeroLightEffectTool.PlayEffect_UIRender(effectStr, lightEffectType, parent) if parent == nil then parent = UnityEngine.GameObject.Find(ConstAssetPathConfig.Path3) end parent = parent.transform:Find("StageNode/ActorNode") parent = parent.transform:GetChild(0) if parent then local effectID = AuxUtil.PlayPsEffect(effectStr,parent.transform, 0) return effectID end return -1 end -- todo暂时没用 UIRenderModel 脚本播放特效 和 一些特殊的需要单独查询模型挂点的 function UIHeroLightEffectTool.PlayEffect_WithParent(effectStr, lightEffectType, parent) if parent == nil then logging.error(LTAG.ERROR,"[gws] : 注意 UIArray 播放光效 ,必须传入模型的父节点") return end parent = parent.transform:GetChild(0) if parent then local effectID = AuxUtil.PlayPsEffect(effectStr,parent.transform, 0) return effectID end return -1 end --endregion -------------------------通用界面特效 ------------------- return UIHeroLightEffectTool