local UIRender_Utility = {} local private = {} local EventSystem = require('Event/EventSystem') local RendererLayerCfg = require('Utility/RendererLayerCfg') local UIRender_ModelComponentHelper = require('Utility/UIRender_ModelComponentHelper') local JSON = require("cjson") local LuaFuncEntry = require("Main/LuaFuncEntry") local ScaleType = { Normal = 1, --正常 Team = 2, -- 组队 SoloFight = 3, -- 演武 CommandTheWorldHonor = 4, --号令天下荣誉榜展示 } local WeaponHaloBallPos = { {{0,1}}, {{0,1},{0,-1}}, {{0,1},{-0.866,-0.5},{0.866,-0.5}}, {{0,1},{0,-1},{1,0},{-1,0}}, } UIRender_Utility.CameraParentPosAndRot = { Default = {Pos={0, 0, 4.3}, Rot = {0, 180, 0}}, --默认,调整后要恢复默认值 RankUI = {Pos={0, 0.62, 4.45}, Rot = {7.5, 180, 0}}, --排行榜界面 } UIRender_Utility.BlackPlanePosAndRot = { Default = {Pos={0, 0, -3.8}, Rot = {0, 180, 0}}, --默认,调整后要恢复默认值 RankUI = {Pos={0, 0, -3}, Rot = {15, 180, 0}}, --排行榜界面 } local PsGroupPath = "Assets/PsEffect/Projects/%s.prefab"; local PsGroupPath = ConstAssetPathConfig.PsGroupPath; local SHOW_HERO_ID = 4 --高模默认武将 local NORMAL_HERO_ID = 4 --战斗模默认武将 local v3_zero = Vector3.New(0, 0, 0) local EFFECTPATH = ConstAssetPathConfig.PsGroupPath local RT_SCENE_PATH = ConstAssetPathConfig.Path3 local Common2DScenePrefab = ConstAssetPathConfig.Common2DScenePrefab local Common2DSceneTexture = ConstAssetPathConfig.Path40 local DEFAULT_ANIMATOR_CONTROLLER_PATH = ConstAssetPathConfig.DEFAULT_ANIMATOR_CONTROLLER_PATH local DEFAULT_ANIMATION_CLIP_NAME = "Hero_CaoCao_NPC_Plot_no" local DEAFULT_IDLE_ANIMATION_CLIP_NAME = "Hero_CaoCao_idle_loop" local WEAPON_HALO_PATH = ConstAssetPathConfig.WEAPON_HALO_PATH --铸魂天命光轮 local WEAPON_HALO_WHEEL_PATH = ConstAssetPathConfig.WEAPON_HALO_WHEEL_PATH --光轮的主轮盘 local NilTable = {} local DefaultBgImageWidth = 2340 local DefaultBgImageHeight = 1080 --正常适配尺寸 local textureWidth = nil local textureHeight = nil --保持宽度的适配尺寸,用于在平板设备要求图片以宽度为准进行适配 local keepWidthTextureWidth = nil local keepWidthTextureHeight = nil ---初始化需要设定图片的尺寸 这个尺寸应该就是固定的 也不会再变 function private.InitTextureSize() local screenWidth, screenHeight = UIUtils.UIRoot:GetSizeDelta() --下面的算法就是基于固定尺寸2340/1080的比例 去适配 if UIUtils.GetScreenResolutionRatio() >= LuaConst.ScreenResolutionRatio.Ratio1920_1080 then --当宽度比2340 还大时设为screenWidth 图片尺寸为screenWidth 等比拉伸 textureWidth, textureHeight = private.GetTextureSize(screenWidth) keepWidthTextureWidth, keepWidthTextureHeight = textureWidth, textureHeight else --当宽高比必16/9小时 图片高度预设为canvas screenHeight 宽度等比拉伸 textureWidth = DefaultBgImageWidth * screenHeight / DefaultBgImageHeight textureHeight = screenHeight keepWidthTextureWidth, keepWidthTextureHeight = private.GetTextureSize(screenWidth) end end function private.GetTextureSize(screenWidth) if screenWidth > DefaultBgImageWidth then return screenWidth, DefaultBgImageHeight * screenWidth / DefaultBgImageWidth else return DefaultBgImageWidth, DefaultBgImageHeight end end function UIRender_Utility.AdaptiveImageSizeFit(rawImage, notKeepWidthAdapt) if notKeepWidthAdapt then rawImage.transform:SetSizeDelta(textureWidth, textureHeight) else rawImage.transform:SetSizeDelta(keepWidthTextureWidth, keepWidthTextureHeight) end end function UIRender_Utility.AdaptivePadStretch(rectTransform) if UIUtils.GetScreenResolutionRatio() < LuaConst.ScreenResolutionRatio.Ratio1920_1080 then local x, y = rectTransform:GetSizeDelta() rectTransform:SetSizeDelta(x, DefaultBgImageHeight - textureHeight) end end function UIRender_Utility.OnStartup() private.SetupEntryFunc(true) private.InitTextureSize() RendererLayerCfg.InitCfg() --注册事件 在某些机子InitTextureSize时 UIUtils.GetScreenResolutionRatio()方法还没有初始化完成 导致适配错误 --预期不应该出现该现象,因为LuaMainFile是在初始化协程之后才执行的 EventSystem.Regist(EventID.Refresh_RenderTextureSize, private.InitTextureSize) end function private.SetupEntryFunc(isRegist) LuaFuncEntry.SetupMainEntryFunc(isRegist, LuaFuncEntry.FuncType.OnModelComponentLayerActiveType, private.OnModelComponentLayerActiveType) end function UIRender_Utility.OnShutdown() private.SetupEntryFunc(false) end -- 计算插值 function UIRender_Utility.GetLerpValue(startValue, endValue, ratio) if ratio <= 0 then return startValue elseif ratio >= 1 then return endValue else return (endValue - startValue) * ratio + startValue end end --加载武将先过一遍该方法,如果该资源未下载,返回刘备 --isShow 是否高模 function UIRender_Utility.PreprocessHeroData(heroId, isShow, heroAppearanceID) if CTL.HotFix.CanHeroLoad(heroId, isShow, heroAppearanceID) then return heroId, heroAppearanceID end if CTL.HotFix.CanHeroLoad(heroId, isShow) then return heroId, 0 end if isShow then return SHOW_HERO_ID, 0 else return NORMAL_HERO_ID, 0 end end function UIRender_Utility.GetModelPath(heroId, isShow, heroAppearanceID) local modelId if heroAppearanceID and heroAppearanceID > 0 then local appearanceData = DataSheetManager.HeroAppearance:GetDataByID(heroAppearanceID) modelId = isShow and appearanceData.PreviewModel or appearanceData.BattleModel else if isShow then local heroData = DataSheetManager.HeroNum:GetDataByID(heroId) modelId = heroData.PreviewModel else local heroData = DataSheetManager.HeroData:GetDataByID(heroId) modelId = heroData.ModelID end end return DataSheetManager.MonsterModelData:GetDataByID(modelId).Path end function UIRender_Utility.LoadSelectHero(heroId, isShowAppearance) local heroWearAppearanceID if isShowAppearance then heroWearAppearanceID = MDL.HeroSelect.GetAppearanceIDByHeroID(heroId) end heroId, heroWearAppearanceID = UIRender_Utility.PreprocessHeroData(heroId, true, heroWearAppearanceID) if heroWearAppearanceID and heroWearAppearanceID > 0 then return DataSheetManager.HeroAppearance:GetDataByID(heroWearAppearanceID).PreviewTimeline else return DataSheetManager.HeroNum:GetDataByID(heroId).PreviewTimeline end end -- 累冲界面rawTexture使用, paramId为相机ID, 不带皮肤 function UIRender_Utility.LoadWeaponWihoutAppearance(weaponId, paramId) --普通神兵id与武将id一致,因此可以直接调用武将的保护 weaponId = UIRender_Utility.PreprocessHeroData(weaponId, true) local data = DataSheetManager.MagicWeaponData:GetDataByMagicWeaponID(weaponId) local weaponModelData = DataSheetManager.MagicWeaponModel:GetDataByID(data.PreviewModel) local weaponData = {} for i, v in ipairs(weaponModelData.ModelPart_Table) do local tmp = { weaponPath = v.Prefeb, effectPath = v.MagicWeaponInitialShowEffect[data.EffectLevel], idleState = v.MagicWeaponAction } table.insert(weaponData, tmp) end return weaponModelData.ModelNode, weaponData, paramId, weaponModelData.ModelLight end -- 累冲界面rawTexture使用, paramId为相机ID, 有皮肤 function UIRender_Utility.LoadShowWeaponDataWithAppearance(weaponApperanceID, paramId) --目前武器时装没有跟武将本身有配置来映射,直接判断资源是否下完 local hasAllDownload = true local data = DataSheetManager.MagicWeaponStar:GetDataByMagicWeaponID_Star(weaponApperanceID, 15) local weaponModelData = DataSheetManager.MagicWeaponModel:GetDataByID(data.PreviewModel) local weaponData = {} for i, v in ipairs(weaponModelData.ModelPart_Table) do if CTL.HotFix.CanAssetLoad(v.Prefeb) == false then hasAllDownload = false break end local tmp = { weaponPath = v.Prefeb, effectPath = v.MagicWeaponInitialShowEffect[data.EffectLevel], idleState = v.MagicWeaponAction } table.insert(weaponData, tmp) end if hasAllDownload then return weaponModelData.ModelNode, weaponData, paramId, weaponModelData.ModelLight else return UIRender_Utility.LoadWeaponWihoutAppearance(SHOW_HERO_ID, paramId) end end --region *********************************** 根据服务器数据准备模型数据 ************************************************** function UIRender_Utility.LoadShowOtherHeroBattleModel(headInfo) local heroId = headInfo.HeroID local heroShowId, modelPath, modelScale, heroEffectPath, lightPath, animCtrlPath = UIRender_Utility.GetBattleHeroData(heroId, ScaleType.Normal, nil, 0, headInfo.HeroAppearanceID) heroId = heroShowId if heroId ~= headInfo.HeroID then headInfo.WeaponAppearanceID = heroId end local equipTable = UIRender_Utility.GetBattleWeaponEffect(heroId, headInfo.HeroBreakNums, headInfo.IsActiveMagicWeapon, headInfo.WeaponAppearanceID) return modelPath, equipTable, modelScale, lightPath, heroEffectPath, heroId end function UIRender_Utility.LoadShowOtherHeroShowModel(headInfo) local heroId = headInfo.HeroID local heroShowId, modelPath, modelScale, heroEffectPath, lightPath, animCtrlPath = UIRender_Utility.GetShowHeroData(heroId, 0, headInfo.HeroAppearanceID) heroId = heroShowId local equipTable = UIRender_Utility.GetPreViewWeaponEffect(heroId, headInfo.HeroBreakNums, headInfo.IsActiveMagicWeapon, headInfo.WeaponAppearanceID) return modelPath, equipTable, modelScale, lightPath, heroEffectPath end function UIRender_Utility.LoadRankListOtherHorseHero(headInfo) local heroId = headInfo.HeroID local showHeroId, modelPath, modelScale, heroEffectPath, lightPath, animCtrlPath = UIRender_Utility.GetBattleHeroData(heroId, ScaleType.Normal, nil, 0, headInfo.HeroAppearanceID) heroId = showHeroId local equipTable = UIRender_Utility.GetTownWeaponEffect(heroId, headInfo.MagicWeaponBreak, headInfo.IsActiveMagicWeapon, headInfo.WeaponAppearanceID) return modelPath, equipTable, modelScale, animCtrlPath, heroEffectPath end --endregion *********************************** 根据服务器数据准备模型数据 ************************************************** --region *********************************** 根据自身数据准备模型数据 ************************************************** -- 使用范围:【阵容】、【主城形象设置】、【武将养成】、【累充奖励】、【公平竞技:(1v1阵容选择界面)、(boss战阵容选择界面)、(3v3主界面限免模型、 阵容选择界面)】 ---@param showAppearance 是否要展示时装模型 function UIRender_Utility.LoadShowHero(heroId, hideWeapon, heroInfo, isShowAppearance) local heroInfo = heroInfo or MDL.HeroSelect.GetHeroInfo(heroId) local heroStarLevel = heroInfo and heroInfo.starLevel or 0 local heroWearAppearanceID if isShowAppearance then heroWearAppearanceID = heroInfo and heroInfo.curAppearanceId or nil end heroId, heroWearAppearanceID = UIRender_Utility.PreprocessHeroData(heroId, isShowAppearance, heroWearAppearanceID) local heroLightEffects = MDL.LightEffect.GetHeroWearLightEffectIDList(heroId) or NilTable local heroShowId, modelPath, modelScale, heroEffectPath, lightPath, animCtrlPath = UIRender_Utility.GetShowHeroData(heroId, heroStarLevel, heroWearAppearanceID) if heroShowId ~= heroId then heroId = heroShowId heroInfo = MDL.HeroSelect.GetHeroInfo(heroId) end if heroInfo and heroInfo.isMagicWeaponActive and not hideWeapon then local weaponAppearance = isShowAppearance and heroInfo.curWeaponAppearanceId or heroId local equipTable = UIRender_Utility.GetPreViewWeaponEffect(heroId, heroInfo.magicWeaponLevel, heroInfo.isMagicWeaponActive , weaponAppearance) return modelPath, equipTable, modelScale, lightPath, heroEffectPath, heroLightEffects else local weaponData = DataSheetManager.MagicWeaponData:GetDataByMagicWeaponID(heroId) local weaponModelData = DataSheetManager.MagicWeaponModel:GetDataByID(weaponData.PreviewModel) local equipTable = {} for i, v in ipairs(weaponModelData.ModelPart_Table) do local data = {} data.Prefeb = v.Prefeb data.EquipSlotStr = v.ModelSlotStr table.insert(equipTable, data) end return modelPath, equipTable, modelScale, lightPath, heroEffectPath, heroLightEffects end end function UIRender_Utility.CanLoadHorse(horseConfig) local horseModelData = DataSheetManager.HorseModelData:GetDataByHorseModelID(horseConfig.HorseModelID) local modelPath if CTL.WarHorse.IsUsingLowModel() or CTL.HeroDetail.GetSceneLowEffectSetting() then --低特效设备统一用低模 modelPath = horseModelData.HorseModel else --高特效设备配置了高模就用高模 modelPath = string.isNilOrEmpty(horseModelData.HorseModelHigh) and horseModelData.HorseModel or horseModelData.HorseModelHigh end return CTL.HotFix.CanAssetLoad(modelPath) end -- 获取坐骑或坐骑皮肤模型高低模 特效和模型 ---@param horseConfig table :HorseData、HorseAppearance表 function UIRender_Utility.GetHorseModelPathAndEffect(horseConfig) local horseModelData = DataSheetManager.HorseModelData:GetDataByHorseModelID(horseConfig.HorseModelID) local modelPath if CTL.WarHorse.IsUsingLowModel() or CTL.HeroDetail.GetSceneLowEffectSetting() then --低特效设备统一用低模 modelPath = horseModelData.HorseModel else --高特效设备配置了高模就用高模 modelPath = string.isNilOrEmpty(horseModelData.HorseModelHigh) and horseModelData.HorseModel or horseModelData.HorseModelHigh end if not CTL.HotFix.CanAssetLoad(modelPath) then --没下载完 显示河曲 local horseCfg = CTL.WarHorse.GetCurRealHorseDataByHorseID(1) local horseModelData = DataSheetManager.HorseModelData:GetDataByHorseModelID(horseCfg.HorseModelID) modelPath = horseModelData.HorseModel end -- 坐骑特效高低模 local showEffect = string.isNilOrEmpty(horseModelData.HorseShowEffectHigh) and horseModelData.HorseShowEffect or horseModelData.HorseShowEffectHigh local isStandOn = horseModelData.IsStandOnHorse return modelPath, showEffect, isStandOn end -- 获取坐骑是否要站立,且返回动画 function UIRender_Utility.GetOnHorseAnim(horseConfig) local horseModelData = DataSheetManager.HorseModelData:GetDataByHorseModelID(horseConfig.HorseModelID) local isStandOn = horseModelData.IsStandOnHorse local anim = LuaConst.Animation_horseIdle if isStandOn then anim = LuaConst.Animation_idle_loop end return isStandOn, anim end -- UI3DModelComponent.cs 组件使用 ---@param horseConfig table :HorseData、HorseAppearance表 ---@param rotation float : 不同界面下的旋转角度[option] ---@param scale float : 不同界面下的模型大小缩放[option] function UIRender_Utility.LoadShowHorse3DComponent(horseConfig, rotation, scaleVal) local modelPath, horseShowEffect, isStandOn = UIRender_Utility.GetHorseModelPathAndEffect(horseConfig) local modelRot = rotation and rotation or horseConfig.SettingModelRot local scale = scaleVal and scaleVal or horseConfig.SettingModelScale return modelPath, horseConfig.HorsePreviewModelLight, scale, modelRot, horseConfig.ModelIdleAnim, horseShowEffect end -- UIRenderModel.cs 组件使用 ---@param horseConfig table :HorseData、HorseAppearance表 ---@param caneraRenderID number :[option] function UIRender_Utility.LoadShowHorseRawTextureRender(horseConfig, cameraRenderID, rotation) local modelPath, horseShowEffect, isStandOn = UIRender_Utility.GetHorseModelPathAndEffect(horseConfig) local crID = cameraRenderID and cameraRenderID or horseConfig.CameraRenderId local modelRot = rotation and rotation or horseConfig.SettingModelRot return modelPath, crID, horseConfig.HorsePreviewModelLight, modelRot, horseConfig.ModelIdleAnim, horseShowEffect end function UIRender_Utility.LoadHorseHero(heroId, isShowAppearance, heroAppearanceIDByServer) local heroInfo = MDL.HeroSelect.GetHeroInfo(heroId) local heroWearAppearanceID = isShowAppearance and MDL.HeroSelect.GetAppearanceIDByHeroID(heroId) or nil if isShowAppearance and heroAppearanceIDByServer then heroWearAppearanceID = heroAppearanceIDByServer --如果是服务器传过来的数据不为空,使用服务器的时装 end local showHeroId, modelPath, modelScale, heroEffectPath, lightPath, animCtrlPath = UIRender_Utility.GetBattleHeroData(heroId, ScaleType.Normal, nil, heroInfo and heroInfo.starLevel or 0, heroWearAppearanceID) if heroId ~= showHeroId then heroId = showHeroId heroInfo = MDL.HeroSelect.GetHeroInfo(heroId) end local heroLightEffects = MDL.LightEffect.GetHeroWearLightEffectIDList(heroId) or NilTable if heroInfo and heroInfo.isMagicWeaponActive then local equipTable = UIRender_Utility.GetTownWeaponEffect(heroId, heroInfo.magicWeaponLevel, heroInfo.isMagicWeaponActive, heroInfo.curWeaponAppearanceId) return modelPath, equipTable, modelScale, animCtrlPath, heroEffectPath, heroLightEffects else local weaponData = DataSheetManager.MagicWeaponData:GetDataByMagicWeaponID(heroId) local weaponModelData = DataSheetManager.MagicWeaponModel:GetDataByID(weaponData.HomeModel) local equipTable = {} for i, v in ipairs(weaponModelData.ModelPart_Table) do local data = {} data.Prefeb = v.Prefeb data.EquipSlotStr = v.ModelSlotStr local weaponAnimPath = animCtrlPath if v.HasAnim then weaponAnimPath = string.match(v.Prefeb, "^(.*)_R[0-9]") if weaponAnimPath then weaponAnimPath = weaponAnimPath .. ".controller" else weaponAnimPath = string.gsub(v.Prefeb, ".prefab", ".controller") end data.animCtrlPath = weaponAnimPath end table.insert(equipTable, data) end return modelPath, equipTable, modelScale, animCtrlPath, heroEffectPath, heroLightEffects end end function UIRender_Utility.LoadArrayHero(heroId, index, isShowAppearance) local heroInfo = MDL.HeroSelect.GetHeroInfo(heroId) local heroWearAppearanceID = isShowAppearance and MDL.HeroSelect.GetAppearanceIDByHeroID(heroId) or nil local showHeroId, modelPath, modelScale, heroEffectPath, lightPath, animCtrlPath = UIRender_Utility.GetBattleHeroData(heroId, ScaleType.Team, index, nil, heroWearAppearanceID) if heroId ~= showHeroId then heroId = showHeroId heroInfo = MDL.HeroSelect.GetHeroInfo(heroId) end local weaponAppearance = isShowAppearance and heroInfo.curWeaponAppearanceId or heroId local equipTable = UIRender_Utility.GetTownWeaponEffect(heroId, heroInfo.magicWeaponLevel, heroInfo.isMagicWeaponActive, weaponAppearance) local heroLightEffects = MDL.LightEffect.GetHeroWearLightEffectIDList(heroId) or NilTable return heroId, index, modelPath, equipTable, modelScale, animCtrlPath, heroEffectPath, heroLightEffects end --endregion *********************************** 根据自身数据准备模型数据 ************************************************** -- 提供给武将外观预览的换模型接口 function UIRender_Utility.LoadShowHeroByHeroData(heroId, heroInfo, hideWeapon) local heroShowId, modelPath, modelScale, heroEffectPath, lightPath, animCtrlPath = UIRender_Utility.GetShowHeroData(heroId, heroInfo and heroInfo.starLevel or 0, heroInfo.heroApperanceId) if heroShowId ~= heroId then heroId = heroShowId heroInfo = nil end local scenePath = nil if heroInfo and heroInfo.isMagicWeaponActive and not hideWeapon then local equipTable = UIRender_Utility.GetPreViewWeaponEffect(heroId, heroInfo.magicWeaponLevel, heroInfo.isMagicWeaponActive, heroInfo.curWeaponAppearanceId) return modelPath, equipTable, modelScale, lightPath, scenePath, heroEffectPath else local weaponData = DataSheetManager.MagicWeaponData:GetDataByMagicWeaponID(heroId) local weaponModelData = DataSheetManager.MagicWeaponModel:GetDataByID(weaponData.PreviewModel) local equipTable = {} for i, v in ipairs(weaponModelData.ModelPart_Table) do local data = {} data.Prefeb = v.Prefeb data.EquipSlotStr = v.ModelSlotStr table.insert(equipTable, data) end return modelPath, equipTable, modelScale, lightPath, scenePath, heroEffectPath end end -- 号令天下荣誉榜展示 function UIRender_Utility.LoadCommandTheWorldHonorHero(detailInfo, index) local showHeroId, modelPath, modelScale, heroEffectPath, lightPath, animCtrlPath = UIRender_Utility.GetBattleHeroData(detailInfo.mainHeroId, ScaleType.CommandTheWorldHonor, index, nil, detailInfo.HeroAppearanceID) local equipTable = UIRender_Utility.GetTownWeaponEffect(detailInfo.mainHeroId, detailInfo.MagicWeaponBreak, detailInfo.IsActiveMagicWeapon, detailInfo.WeaponAppearanceID) return showHeroId, index, modelPath, equipTable, modelScale, animCtrlPath end --heroinfo结构 对应CommonShowRoleModelInfo proto结构 --heroBreakNums 主城形象武将突破等级(大突破) --isActiveMagicWeapon, 主城形象武将神兵是否激活 --magicWeaponBreak, 主城形象武将神兵突破等级(大突破) --weaponAppearanceId, 主程形象武将时装Id,没有为武器id --heroAppearanceId, 主程形象武将神兵时装Id function UIRender_Utility.ShowBattleHero(heroId, heroInfo, isShowAppearance) local heroWearAppearanceID = isShowAppearance and heroInfo.heroAppearanceId or nil local showHeroId, modelPath, modelScale, heroEffectPath, lightPath, animCtrlPath = UIRender_Utility.GetBattleHeroData(heroId, ScaleType.Team, 1, heroInfo.heroBreakNums, heroWearAppearanceID) if heroId ~= showHeroId then heroId = showHeroId heroInfo = MDL.HeroSelect.GetHeroInfo(heroId) end local weaponAppearance = isShowAppearance and heroInfo.weaponAppearanceId or heroId local equipTable = UIRender_Utility.GetBattleWeaponEffect(heroId, heroInfo.magicWeaponBreak, heroInfo.isActiveMagicWeapon, weaponAppearance) return heroId, modelPath, equipTable, modelScale, lightPath, heroEffectPath, animCtrlPath end function UIRender_Utility.GetBattleWeaponEffect(heroId, magicWeaponLevel, isMagicWeaponActive, weaponAppearance) local equipTable = {} local weaponData = DataSheetManager.MagicWeaponData:GetDataByMagicWeaponID(heroId) local weaponId = weaponAppearance or heroId --这里用TryGet是magicWeaponLevel可能读不到数据 local _, breakData = DataSheetManager.MagicWeaponStar:TryGetDataByMagicWeaponID_Star(weaponId, magicWeaponLevel) local battleModelId = nil local effectLevel = nil if breakData then battleModelId = breakData.BattleModel effectLevel = breakData.EffectLevel else battleModelId = weaponData.BattleModel if isMagicWeaponActive then effectLevel = weaponData.EffectLevel end end local weaponModelData = DataSheetManager.MagicWeaponModel:GetDataByID(battleModelId) for i, v in ipairs(weaponModelData.ModelPart_Table) do local data = {} data.Prefeb = v.Prefeb data.EquipSlotStr = v.ModelSlotStr local animCtrlPath = "" if v.HasAnim then animCtrlPath = string.match(v.Prefeb, "^(.*)_R[0-9]") if animCtrlPath then animCtrlPath = animCtrlPath .. ".controller" else animCtrlPath = string.gsub(v.Prefeb, ".prefab", ".controller") end data.animCtrlPath = animCtrlPath end if effectLevel then data.effectPath = v.MagicWeaponInitialShowEffect[effectLevel] end table.insert(equipTable, data) end return equipTable end function UIRender_Utility.GetTownWeaponEffect(heroId, magicWeaponLevel, isMagicWeaponActive, weaponAppearance) logging.log(LTAG.LOG," GetTownWeaponEffect ",heroId, magicWeaponLevel, isMagicWeaponActive, weaponAppearance) local equipTable = {} local weaponData = DataSheetManager.MagicWeaponData:GetDataByMagicWeaponID(heroId) local weaponId = weaponAppearance or heroId local isSuccess, breakData if weaponId and weaponId>0 then isSuccess, breakData = DataSheetManager.MagicWeaponStar:TryGetDataByMagicWeaponID_Star(weaponId, magicWeaponLevel) end local battleModelId = nil local effectLevel = nil if breakData then battleModelId = breakData.HomeModel effectLevel = breakData.EffectLevel else battleModelId = weaponData.HomeModel if isMagicWeaponActive then effectLevel = weaponData.EffectLevel end end local weaponModelData = DataSheetManager.MagicWeaponModel:GetDataByID(battleModelId) for i, v in ipairs(weaponModelData.ModelPart_Table) do local data = {} data.SlotType = v.SlotType data.Prefeb = v.Prefeb data.EquipSlotStr = v.ModelSlotStr local animCtrlPath = "" if v.HasAnimCity or v.HasAnim then animCtrlPath = string.match(v.Prefeb, "^(.*)_R[0-9]") if animCtrlPath then animCtrlPath = animCtrlPath .. "_ZhuCheng.controller" else animCtrlPath = string.gsub(v.Prefeb, ".prefab", "_ZhuCheng.controller") end data.animCtrlPath = animCtrlPath end if effectLevel then data.effectPath = v.MagicWeaponInitialShowEffect[effectLevel] end table.insert(equipTable, data) end return equipTable end function UIRender_Utility.GetPreViewWeaponEffect(heroId, magicWeaponLevel, isMagicWeaponActive, weaponAppearance) local equipTable = {} local weaponData = DataSheetManager.MagicWeaponData:GetDataByMagicWeaponID(heroId) local weaponId = heroId == weaponAppearance and heroId or weaponAppearance local _, breakData = DataSheetManager.MagicWeaponStar:TryGetDataByMagicWeaponID_Star(weaponId, magicWeaponLevel) local battleModelId = nil local effectLevel = nil if breakData then battleModelId = breakData.PreviewModel effectLevel = breakData.EffectLevel else battleModelId = weaponData.PreviewModel if isMagicWeaponActive then effectLevel = weaponData.EffectLevel end end local weaponModelData = DataSheetManager.MagicWeaponModel:GetDataByID(battleModelId) for i, v in ipairs(weaponModelData.ModelPart_Table) do local data = {} data.Prefeb = v.Prefeb data.EquipSlotStr = v.ModelSlotStr if effectLevel then data.effectPath = v.MagicWeaponInitialShowEffect[effectLevel] end table.insert(equipTable, data) end return equipTable end -- 尽量不要依赖自身数据 function UIRender_Utility.GetShowHeroData(heroId, breakNums, heroWearAppearanceID) heroId, heroWearAppearanceID = UIRender_Utility.PreprocessHeroData(heroId, true, heroWearAppearanceID) local modelId, previewModelLight if heroWearAppearanceID and heroWearAppearanceID > 0 then local appearanceData = DataSheetManager.HeroAppearance:GetDataByID(heroWearAppearanceID) modelId = appearanceData.PreviewModel previewModelLight = appearanceData.PreviewModelLight else local heroData = DataSheetManager.HeroNum:GetDataByID(heroId) modelId = heroData.PreviewModel previewModelLight = heroData.PreviewModelLight end local monsterData = DataSheetManager.MonsterModelData:GetDataByID(modelId) local modelScale = monsterData.ModelScale if not breakNums then breakNums = MDL.HeroStar.GetHeroStarLevel(heroId) end local dir, actorDir,prefab = string.match(monsterData.Path, "(%S*)/(%S*)/(%S*)") local animCtrlPath = string.gsub(monsterData.Path, prefab ,actorDir.."_ZhuCheng.controller") --local heroEffectPath = DataSheetManager.HeroStar:GetDataByHeroID_Star(heroId, breakNums).HeroStarShowEffect 已废弃,但是数据还在所以不删除只注释掉 local heroEffectPath = "" if not string.isNilOrEmpty(monsterData.ModelPsEffect) then heroEffectPath = string.format(PsGroupPath,monsterData.ModelPsEffect) end return heroId, monsterData.Path, modelScale, heroEffectPath, previewModelLight, animCtrlPath end -- 尽量不要依赖自身数据 function UIRender_Utility.GetBattleHeroData(heroId, scaleType, index, breakNums, heroWearAppearanceID) heroId, heroWearAppearanceID = UIRender_Utility.PreprocessHeroData(heroId, true, heroWearAppearanceID) local modelId, previewModelLight if heroWearAppearanceID and heroWearAppearanceID > 0 then local appearanceData = DataSheetManager.HeroAppearance:GetDataByID(heroWearAppearanceID) modelId = appearanceData.BattleModel previewModelLight = appearanceData.PreviewModelLight else local heroData = DataSheetManager.HeroData:GetDataByID(heroId) modelId = heroData.ModelID local heroNum = DataSheetManager.HeroNum:GetDataByID(heroId) previewModelLight = heroNum.PreviewModelLight end local monsterData = DataSheetManager.MonsterModelData:GetDataByID(modelId) local modelScale = private.GetScaleValue(monsterData, scaleType, index) if not breakNums then breakNums = MDL.HeroStar.GetHeroStarLevel(heroId) end --local heroEffectPath = DataSheetManager.HeroStar:GetDataByHeroID_Star(heroId, breakNums).HeroStarShowEffect 已废弃,但是数据还在所以不删除只注释掉 local heroEffectPath = "" if not string.isNilOrEmpty(monsterData.ModelPsEffect) then heroEffectPath = string.format(PsGroupPath,monsterData.ModelPsEffect) end local dir, actorDir,prefab = string.match(monsterData.Path, "(%S*)/(%S*)/(%S*)") local animCtrlPath = string.gsub(monsterData.Path, prefab ,actorDir.."_ZhuCheng.controller") return heroId, monsterData.Path, modelScale, heroEffectPath, previewModelLight, animCtrlPath end function UIRender_Utility.GetModelScale() if UIUtils.GetScreenResolutionRatio() == LuaConst.ScreenResolutionRatio.RatioPad4_3 then return 0.95 end return 1 end function private.GetScaleValue(monsterData, scaleType, index) if scaleType == ScaleType.Normal then return monsterData.ModelScale elseif scaleType == ScaleType.SoloFight then return monsterData.TeamModelScale and monsterData.TeamModelScale*1.5 or 1 elseif scaleType == ScaleType.Team then return monsterData.TeamModelScale or 1 elseif scaleType == ScaleType.CommandTheWorldHonor then return monsterData.ModelScale * 0.8 end end function UIRender_Utility.SceneBackgroundFitScreen(sceneBg, screenScaling, ratioScaling) local defaultScaleX, defaultScaleY = 11.115, 5.13 local w, h = UIUtils.GetScreenSize(1,1) local screenDelta = w / h if screenDelta > 2340/1080 then local scale = screenScaling * screenDelta - 0.27; sceneBg:SetLocalScale(defaultScaleX * scale, defaultScaleY * scale, 1) else sceneBg:SetLocalScale(defaultScaleX, defaultScaleY, 1) end end function UIRender_Utility.SetBgTextureFitScreen(handle, screenScaling, ratioScaling) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end local sceneTrans = modelComponentData["sceneTrans"] local defaultScaleX, defaultScaleY = 11.115, 5.13 sceneTrans:Find("BlackPlane"):SetLocalScale(defaultScaleX * screenScaling, defaultScaleY * screenScaling, 1) end ---------- Start 以下为新版展示3D UI接口 Start ---------- UIRender_Utility.LayerActiveType = { HeroShow = 0, HeroSelect = 1, UI2DBGCommonShow = 2, HeroFormation = 3, BossChallenge = 4, HorseShow = 7, -- 坐骑养成界面 RTShow = 8, CountryOfficial = 9, Other = 10, } private.modelComponentDatasDic = {} private.modelComponentDatasHandle = 0 --[[ ModelComponentDatas 中的 结构及作用(外界尽量少的访问) modelComponent:ModelComponent组件 scenePath:加载的场景路径,防止相同路径的重复加载 sceneTrans:场景Transform modelRoot:模型节点 lightObj:灯光节点 layerActiveType:界面类型 cameraParent:相机的父节点(目前) blendTime:相机的切换混合时间 --]] -- 创建加载模型所需数据表 -- 返回的是一个数字句柄,并不是数据本身 function UIRender_Utility.CreateModelComponentDatas(modelComponent) if not modelComponent then logging.error(LTAG.ERROR, "在创建 ModelComponentDatas 的时候 请传入正确的 modelComponent") end local datas = {} datas["modelComponent"] = modelComponent private.modelComponentDatasHandle = private.modelComponentDatasHandle + 1 -- 全局句柄自增 private.modelComponentDatasDic[private.modelComponentDatasHandle] = datas return private.modelComponentDatasHandle -- 返回数字句柄 end function private.CreateNormalSceneTrans(handle, scenePath, sceneParent) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end local modelComponent = modelComponentData.modelComponent local sceneTrans = modelComponentData.sceneTrans if sceneTrans then if modelComponentData.scenePath ~= scenePath then UIRender_Utility.DisposeSceneTrans(handle) sceneTrans = modelComponent:CreateModelObject(scenePath, nil) end else sceneTrans = modelComponent:CreateModelObject(scenePath, nil) end return sceneTrans end -- 创建通用的2DCommnon场景 ---@param textureBg 2D背景图片 ---@param baseScenePath 其他Obj ---@param scenePath 创建的场景,默认为通用的 function UIRender_Utility.Create2DTextureBgScene(handle, textureBg, baseScenePath, scenePath, baseScaleVal) local modelComponentData = private.modelComponentDatasDic[handle] --创建台子 if not string.isNilOrEmpty(baseScenePath) and not modelComponentData["sceneBackgroundTrans"] then modelComponentData["sceneBackgroundTrans"] = private.CreateNormalSceneTrans(handle, baseScenePath) modelComponentData["sceneBackgroundTrans"]:SetLocalScale(baseScaleVal or 1, baseScaleVal or 1, baseScaleVal or 1) modelComponentData["sceneBackgroundTrans"]:SetLocalPosition(0, 0, 0) modelComponentData["sceneBackgroundTrans"]:SetLocalEulerAngles(0, 0, 0) end -- 场景 if not modelComponentData["scenePath"] then UIRender_Utility.Create2DSceneTrans(handle, scenePath or Common2DScenePrefab, 1600, 0, 1600, textureBg, false) UIRender_ModelComponentHelper.SetLayerActiveByType(handle, modelComponentData, UIRender_Utility.LayerActiveType.UI2DBGCommonShow) modelComponentData.modelComponent:OnLayerActive(true) end if modelComponentData["sceneBackgroundTrans"] then modelComponentData["sceneBackgroundTrans"]:SetParent(modelComponentData.modelRoot, false) end end --创建2D场景 --Assets/GameLevels/Dynamic_ScenePrefab/UI2DCommonScene.prefab function UIRender_Utility.Create2DSceneTrans(handle, scenePath, posX, posY, posZ, texturePath, isShadow) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end local modelComponent = modelComponentData.modelComponent -- 加载通用2D场景 并 设置位置 local sceneTrans = private.CreateNormalSceneTrans(handle, scenePath) sceneTrans:SetLocalPosition(posX, posY, posZ) -- 加载模型节点 并 设置位置 local modelRoot = modelComponentData.modelRoot if not modelRoot then modelRoot = modelComponent:CreateRootObject() end --设置挂载模型的节点信息 modelComponentData["HeroParent"] = sceneTrans:Find("HeroParent") modelComponentData.HeroParent:SetLocalPosition(0.45, 0, 0) modelComponentData.HeroParent:SetLocalEulerAngles(0, 0, 0) modelRoot:SetParent(modelComponentData.HeroParent, false) --设置模型EMPTY_GAME_OBJECT信息 modelRoot:SetLocalPosition(0, 0, 0) modelRoot:SetLocalEulerAngles(0, 0, 0) -- 设置背景图 以及 适配 modelComponent:SetSceneTexture(texturePath, sceneTrans, "BlackPlane") local blackPlane = sceneTrans:Find("BlackPlane") UTL.UIRender.SceneBackgroundFitScreen(blackPlane, 0.6, -0.27) -- 设置阴影 UIUtils.SetActive(sceneTrans:Find("HeroParent/ShadowPlane"), isShadow) -- 先设置LayerActive方法的参数列表 modelComponentData["scenePath"] = scenePath modelComponentData["sceneTrans"] = sceneTrans modelComponentData["modelRoot"] = modelRoot modelComponentData["blackPlane"] = blackPlane -- 再设置LayerActive方法 UIRender_ModelComponentHelper.SetLayerActiveByType(handle, modelComponentData, UIRender_Utility.LayerActiveType.UI2DBGCommonShow) modelComponent:OnLayerActive(true) end -- 创建3D场景 function UIRender_Utility.Create3DSceneTrans(handle, scenePath, posX, posY, posZ, rotX, rotY, rotZ, layerActiveType) -- Editor下,方便美术预览展示场景 if UNITY_EDITOR then local customTimelinePath, customHeroPath, customHeroScenePath = private.GetEditorCustomModelPath() if customHeroScenePath ~= nil and customHeroScenePath ~= "" then scenePath = customHeroScenePath end end local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end local modelComponent = modelComponentData.modelComponent -- 加载3D场景 并 设置位置 if modelComponentData.sceneTrans then UIModelUtils.StopSceneParam(modelComponentData.sceneTrans) end local sceneTrans = private.CreateNormalSceneTrans(handle, scenePath) if layerActiveType ~= UIRender_Utility.LayerActiveType.CountryOfficial then sceneTrans:SetLocalPosition(posX, posY, posZ) end UIModelUtils.PlaySceneParam(sceneTrans) -- 加载模型节点 并 设置位置 local modelRoot = modelComponentData.modelRoot if not modelRoot then modelRoot = modelComponent:CreateRootObject() end modelRoot:SetLocalPosition(posX, posY, posZ) modelRoot:SetLocalEulerAngles(rotX, rotY, rotZ) -- 先设置LayerActive方法的参数列表 modelComponentData["scenePath"] = scenePath modelComponentData["sceneTrans"] = sceneTrans modelComponentData["modelRoot"] = modelRoot -- 再设置LayerActive方法 UIRender_ModelComponentHelper.SetLayerActiveByType(handle, modelComponentData, layerActiveType) modelComponent:OnLayerActive(true) end --- 创建RT模型场景 --- @param handle modelComponentDataHandle --- @param lightPath 灯光路径 --- Assets/GameLevels/Dynamic_ScenePrefab/UI_RenderModel.prefab local RTSceneIndex = 0 --多个RT并存情况 function UIRender_Utility.CreateRTSceneTrans(handle, lightPath, scenePathParam) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end local modelComponent = modelComponentData.modelComponent local scenePath = scenePathParam or RT_SCENE_PATH local posX, posY, posZ = 1600, 1600+RTSceneIndex*20, 0 RTSceneIndex = RTSceneIndex+1 -- 加载场景 local sceneTrans = modelComponentData.sceneTrans if sceneTrans then UIModelUtils.StopSceneParam(sceneTrans) if modelComponentData.scenePath ~= scenePath then UIRender_Utility.DisposeSceneTrans(handle) sceneTrans = modelComponent:CreateModelObject(scenePath, nil) end else sceneTrans = modelComponent:CreateModelObject(scenePath, nil) end sceneTrans:SetLocalPosition(posX, posY, posZ) -- 加载模型节点 并 设置位置 local modelRootTrans = sceneTrans:Find("StageNode/ActorNode") -- 创建灯光 if lightPath and not string.isNilOrEmpty(lightPath) then local lightParentTrans = sceneTrans:Find("StageNode/LightNode") local lightObj = modelComponent:CreateModelObject(lightPath, lightParentTrans) modelComponentData["lightParentTrans"] = lightParentTrans modelComponentData["lightObj"] = lightObj end -- 打开renderCamera(旧版本:加入缓存池会关闭RenderCamera) local renderCamera = sceneTrans:Find("RenderCamera") UIUtils.SetActive(renderCamera,true) -- 先设置LayerActive方法的参数列表 modelComponentData["scenePath"] = scenePath modelComponentData["sceneTrans"] = sceneTrans modelComponentData["modelRoot"] = modelRootTrans -- 再设置LayerActive方法 UIRender_ModelComponentHelper.SetLayerActiveByType(handle, modelComponentData, UIRender_Utility.LayerActiveType.RTShow) modelComponent:OnLayerActive(true) end -- TODO 临时增加方法兼容 国家boss 之后修改国家boss 组件时需要优化掉 function UIRender_Utility.SetCountryBossSceneTrans(handle, sceneTrans) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end modelComponentData["sceneTrans"] = sceneTrans UIRender_ModelComponentHelper.SetLayerActiveByType(handle, modelComponentData, UIRender_Utility.LayerActiveType.Other) end function UIRender_Utility.GetSceneTrans(handle) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end return modelComponentData["sceneTrans"] end function UIRender_Utility.SetSceneTransPosition(handle, x, y, z) local trans = UIRender_Utility.GetSceneTrans(handle) if trans then trans:SetLocalPosition(x, y, z) end end function UIRender_Utility.SetSceneTransRotation(handle, rot) local trans = UIRender_Utility.GetSceneTrans(handle) if trans then trans:SetLocalEulerAngles(0, rot, 0) end end function UIRender_Utility.GetModelRootTrans(handle) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end return modelComponentData["modelRoot"] end -- 创建RT模型 (模型、武器) ---@param idleAnimClip 传入idle动作则相对应使用默认的状态机和IDLE动作,不传则使用原方法获取状态机路径 function UIRender_Utility.CreateRTRenderModel(handle, modelPath, modelScale, showEquipmentID, renderID, idleAnimCilp, heroEffectPath, psEffectPath) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end if not modelComponentData.heroEffectIDs then modelComponentData.heroEffectIDs = {} end local sceneTrans = modelComponentData.sceneTrans local modelComponent = modelComponentData.modelComponent local modelRootTrans = modelComponentData.modelRoot local lightParentTrans = modelComponentData.lightParentTrans -- 创建模型 local isUseDefautlCtl = not string.isNilOrEmpty(idleAnimCilp) local ctlPath = isUseDefautlCtl and DEFAULT_ANIMATOR_CONTROLLER_PATH or UTL.UIRender.GetAnimationCtlPath(modelPath) local renderEntity = private.CreateEntityModel(handle, modelPath, ctlPath, "", modelScale) local heroEffectID = private.PlayHeroModelEffect(renderEntity, heroEffectPath) table.insert(modelComponentData.heroEffectIDs, heroEffectID) renderEntity.Transform:SetLocalPosition(0, 0, 0) renderEntity.Transform:SetLocalEulerAngles(0, 0, 0) if isUseDefautlCtl then renderEntity:ReplaceAnimation(DEAFULT_IDLE_ANIMATION_CLIP_NAME, idleAnimCilp) end -- 加载武器 if showEquipmentID then UTL.UIRender.LoadEquipPart(showEquipmentID, renderEntity) end modelComponent:SetRenderModel(modelComponent.transform, sceneTrans, renderEntity.Transform, lightParentTrans, renderID) if string.isNilOrEmpty(psEffectPath) == false then modelComponentData.renderEffectId = UTL.UIRender.PlayPsEffect(handle, psEffectPath) end end function UIRender_Utility.SetRTRootParam(handle, posArr, rotVal) local modelComponentData = private.modelComponentDatasDic[handle] local modelRoot = modelComponentData.modelRoot if modelRoot == nil then return end modelRoot:SetLocalEulerAngles(0, rotVal or 0, 0) modelRoot:SetLocalPosition(posArr[1], posArr[2], posArr[3]) end --单个RT创建多个模型(战斗模) function UIRender_Utility.CreateMultiPlayerRTRenderModel(handle, showInfos, showParams, renderID, playerShowInfos) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end if not modelComponentData.heroEffectIDs then modelComponentData.heroEffectIDs = {} end local renderEntityList = {} local sceneTrans = modelComponentData.sceneTrans local modelComponent = modelComponentData.modelComponent local lightParentTrans = modelComponentData.lightParentTrans --先创建第一个模型 local modelPath, equipTable, modelScale, lightPath, heroEffectPath, heroShowId = UIRender_Utility.LoadShowOtherHeroBattleModel(showInfos[1]) local renderEntity = private.CreateEntityModel(handle, modelPath, UIRender_Utility.GetAnimationCtlPath(modelPath), "", modelScale) heroEffectPath = UIRender_Utility.GetHeroEffectName(showInfos[1].HeroID, showInfos[1].HeroAppearanceID, true) local heroEffectID = private.PlayHeroModelEffect(renderEntity, heroEffectPath) table.insert(modelComponentData.heroEffectIDs, heroEffectID) renderEntity.Transform:SetLocalPosition(showParams[1].posX, showParams[1].posY) renderEntity.Transform:SetLocalEulerAngles(0, 0, 0) renderEntity.Transform:SetLocalScale(showParams[1].scale, showParams[1].scale, showParams[1].scale) UIRender_Utility.LoadMagicWeapon(heroShowId, showInfos[1].WeaponAppearanceID, showInfos[1].MagicWeaponBreak, showInfos[1].IsActiveMagicWeapon, renderEntity, true) --天命 local weaponSoul = CTL.DivineWeaponForgeSoul.GetWeaponSoulSkillByProtoMap(showInfos[1].HeroID, playerShowInfos[1].weaponSoul) if weaponSoul then UIRender_Utility.LoadPlayerWeaponSoul(handle, weaponSoul) end modelComponent:SetRenderModel(modelComponent.transform, sceneTrans, renderEntity.Transform, lightParentTrans, renderID) UIRender_Utility.SetRenderEntityDye(renderEntity, playerShowInfos[1].HeroAppearanceID, playerShowInfos[1].dyeCurPartList, 1) table.insert(renderEntityList, renderEntity) --接着创建其他entity for i = 2, #showInfos do local modelPath, equipTable, modelScale, lightPath, heroEffectPath, heroShowId = UIRender_Utility.LoadShowOtherHeroBattleModel(showInfos[i]) local renderEntity = private.CreateEntityModel(handle, modelPath, UIRender_Utility.GetAnimationCtlPath(modelPath), "", modelScale) heroEffectPath = UIRender_Utility.GetHeroEffectName(showInfos[i].HeroID, showInfos[i].HeroAppearanceID, true) heroEffectID = private.PlayHeroModelEffect(renderEntity, heroEffectPath) table.insert(modelComponentData.heroEffectIDs, heroEffectID) renderEntity.Transform:SetLocalPosition(showParams[i].posX, showParams[i].posY) renderEntity.Transform:SetLocalEulerAngles(0, 0, 0) renderEntity.Transform:SetLocalScale(showParams[i].scale, showParams[i].scale, showParams[i].scale) UIRender_Utility.LoadMagicWeapon(heroShowId, showInfos[i].WeaponAppearanceID, showInfos[i].MagicWeaponBreak, showInfos[i].IsActiveMagicWeapon, renderEntity, true) --天命 local weaponSoul = CTL.DivineWeaponForgeSoul.GetWeaponSoulSkillByProtoMap(showInfos[i].HeroID, playerShowInfos[i].weaponSoul) if weaponSoul then UIRender_Utility.LoadPlayerWeaponSoul(handle, weaponSoul) end UIRender_Utility.SetRenderEntityDye(renderEntity, showInfos[i].HeroAppearanceID, showInfos[i].dyeCurPartList, 1) table.insert(renderEntityList, renderEntity) end return renderEntityList end --一次加载多个模型会卡顿,改为分帧多次调用 function UIRender_Utility.DelayLoadMultiBattleModel(handle, showInfo, showParam, lightPath) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end local lightObj = modelComponentData.lightObj if lightObj == nil then local lightObj = modelComponentData.modelComponent:CreateModelObject(lightPath, modelComponentData.modelRoot) modelComponentData["lightObj"] = lightObj end if not modelComponentData.renderEntityList then modelComponentData.renderEntityList = {} end if not modelComponentData.heroEffectIDs then modelComponentData.heroEffectIDs = {} end local modelPath, equipTable, modelScale, _, heroEffectPath, heroShowId = UIRender_Utility.LoadShowOtherHeroBattleModel(showInfo) --战斗模+主城状态机 local dir, actorDir, prefab = string.match(modelPath, "(%S*)/(%S*)/(%S*)") local animCtrlPath = string.gsub(modelPath, prefab, actorDir .. "_ZhuCheng.controller") local renderEntity = private.CreateEntityModel(handle, modelPath, animCtrlPath, "", modelScale) heroEffectPath = UIRender_Utility.GetHeroEffectName(showInfo.HeroID, showInfo.HeroAppearanceID, true) local heroEffectID = private.PlayHeroModelEffect(renderEntity, heroEffectPath) table.insert(modelComponentData.heroEffectIDs, heroEffectID) table.insert(modelComponentData.renderEntityList, renderEntity) renderEntity.Transform:SetLocalPosition(showParam.posX, showParam.posY, showParam.posZ or 0) renderEntity.Transform:SetLocalEulerAngles(0, 0, 0) renderEntity.Transform:SetLocalScale(showParam.scale, showParam.scale, showParam.scale) local showEquipmentID, effectLevel = UIRender_Utility.GetTownWeaponEffectId(heroShowId, showInfo.MagicWeaponBreak, showInfo.IsActiveMagicWeapon, showInfo.WeaponAppearanceID) local equipData = DataSheetManager.MagicWeaponModel:GetDataByID(showEquipmentID) private.RenderEntitySetWeapon(equipData, renderEntity, effectLevel, showInfo.IsActiveMagicWeapon, true) --天命 local weaponSoul = CTL.DivineWeaponForgeSoul.GetWeaponSoulSkillByProtoMap(showInfo.HeroID, showInfo.weaponSoul) if weaponSoul then UIRender_Utility.LoadPlayerWeaponSoul(handle, weaponSoul) end UIRender_Utility.SetRenderEntityDye(renderEntity, showInfo.HeroAppearanceID, showInfo.dyeCurPartList, 1) end function UIRender_Utility.PlayPsEffectByRenderEntityIndex(handle, path, index) local modelComponentData = private.modelComponentDatasDic[handle] if modelComponentData and modelComponentData.renderEntityList then local renderEntity = modelComponentData.renderEntityList[index] if renderEntity then return AuxUtil.PlayPsEffect(path, renderEntity.Transform, LuaConst.Layer.Character) end end return nil end -- 创建角色(非玩家角色,包括模型、武器、灯光) function UIRender_Utility.CreateNonPlayerModel(handle, modelPath, modelScale, showEquipmentID, lightPath, posOffset) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end -- 创建模型 local renderEntity = private.CreateEntityModel(handle, modelPath, UTL.UIRender.GetAnimationCtlPath(modelPath), lightPath, modelScale) if posOffset then renderEntity.Transform:SetLocalPosition(posOffset[1], posOffset[2], posOffset[3]) end -- 加载武器 UTL.UIRender.LoadEquipPart(showEquipmentID, renderEntity) end --创建上面非玩家角色的跟随者,不新建灯光,共享之前的 function UIRender_Utility.CreateNonPlayerFollower(handle, modelPath, modelScale, showEquipmentID, posOffset) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end -- 创建模型 local followerEntity = UTL.UIRender.CreateRenderEntity(modelComponentData.modelRoot, modelPath, modelScale, UTL.UIRender.GetAnimationCtlPath(modelPath), true) modelComponentData.followerEntityKey = modelComponentData.modelComponent:AddEntity(followerEntity) modelComponentData.followerEntity = followerEntity if posOffset then followerEntity.Transform:SetLocalPosition(posOffset[1], posOffset[2], posOffset[3]) end -- 加载武器 UTL.UIRender.LoadEquipPart(showEquipmentID, followerEntity) end -- 创建角色(玩家角色,包括模型、武器、灯光) function UIRender_Utility.CreatePlayerModel(handle, heroId, modelPath, lightPath, isPreviewWeaponModel, heroEffectPath, forceWeaponId, noDye) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end local modelComponent = modelComponentData.modelComponent heroId = UIRender_Utility.PreprocessHeroData(heroId, true) if not modelComponentData.heroEffectIDs then modelComponentData.heroEffectIDs = {} end local scenePath, _modelPath, equipTable, modelScale, _lightPath, _heroEffectPath, heroLightEffects = CTL.HeroDetail.GetHeroShowDetail(heroId) local heroAppearanceID = MDL.HeroSelect.GetAppearanceIDByHeroID(heroId) _heroEffectPath = UIRender_Utility.GetHeroEffectName(heroId, heroAppearanceID) if not modelPath then modelPath = _modelPath end if not lightPath then lightPath = _lightPath end if not heroEffectPath then heroEffectPath = _heroEffectPath end -- Editor下,方便美术预览展示角色 if UNITY_EDITOR then local customTimelinePath, customHeroPath, customHeroScenePath, customHeroLightPath, customHeroWeapon1Path, customHeroWeapon1Slot, customHeroWeapon2Path, customHeroWeapon2Slot = private.GetEditorCustomModelPath() if customHeroPath and customHeroPath ~= "" then modelPath = customHeroPath if customHeroLightPath and customHeroLightPath ~= "" then lightPath = customHeroLightPath end local renderEntity = private.CreateEntityModel(handle, modelPath, UTL.UIRender.GetAnimationCtlPath(modelPath), lightPath, 1) local heroEffectID = private.PlayHeroModelEffect(renderEntity, heroEffectPath) table.insert(modelComponentData.heroEffectIDs, heroEffectID) UIRender_Utility.SetModelRootLocalScale(handle, modelScale, modelScale, modelScale) if customHeroWeapon1Path and customHeroWeapon1Path ~= "" then local pathId = UTL.String.GetIdByString(customHeroWeapon1Path) renderEntity:SetEquipOrWeapon(0, pathId, tonumber(customHeroWeapon1Slot), -1, false, true) end if customHeroWeapon2Path and customHeroWeapon2Path ~= "" then local pathId = UTL.String.GetIdByString(customHeroWeapon2Path) renderEntity:SetEquipOrWeapon(0, pathId, tonumber(customHeroWeapon2Slot), -1, false, true) end renderEntity:ResetLayer() return end end -- 创建模型 local renderEntity = private.CreateEntityModel(handle, modelPath, UTL.UIRender.GetAnimationCtlPath(modelPath), lightPath, 1) local heroEffectID = private.PlayHeroModelEffect(renderEntity, heroEffectPath) table.insert(modelComponentData.heroEffectIDs, heroEffectID) UIRender_Utility.SetModelRootLocalScale(handle, modelScale, modelScale, modelScale) -- 武器设置 if forceWeaponId then UTL.UIRender.LoadMagicWeapon(heroId, forceWeaponId, 0, true, renderEntity, isPreviewWeaponModel) else local heroInfo = MDL.HeroSelect.GetHeroInfo(heroId) if heroInfo then UTL.UIRender.LoadMagicWeapon(heroId, heroInfo.curWeaponAppearanceId, heroInfo.magicWeaponLevel, heroInfo.isMagicWeaponActive, renderEntity, isPreviewWeaponModel) else UTL.UIRender.LoadMagicWeapon(heroId, heroId, 0, true, renderEntity, isPreviewWeaponModel) -- 神兵ID与武将ID保持一致 end end if noDye == nil or noDye == false then local partList = MDL.DyeAppearance.GetDyeAppearancePartList(heroAppearanceID) if partList then UIRender_Utility.SetRenderEntityDye(renderEntity, heroAppearanceID, partList, 2) end end --恢复角色层级,这次调用在武器挂载之后,可以带武器恢复Prefab原始层级 renderEntity:ResetLayer() end function UIRender_Utility.CreateOtherPlayerModel(handle, heroInfo, weaponAppearanceId, magicWeaponLevel, isMagicWeaponActive, isPreviewWeapon, modelScaleOffset) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end if not modelComponentData.heroEffectIDs then modelComponentData.heroEffectIDs = {} end local modelComponent = modelComponentData.modelComponent local modelPath, _, _modelScale, lightPath, heroEffectPath = UIRender_Utility.LoadShowOtherHeroShowModel(heroInfo) local modelScale = _modelScale + modelScaleOffset heroEffectPath = UIRender_Utility.GetHeroEffectName(heroInfo.HeroID, heroInfo.HeroAppearanceID) -- 创建模型 local renderEntity = private.CreateEntityModel(handle, modelPath, UTL.UIRender.GetAnimationCtlPath(modelPath), lightPath, 1) local heroEffectID = private.PlayHeroModelEffect(renderEntity, heroEffectPath) table.insert(modelComponentData.heroEffectIDs, heroEffectID) UIRender_Utility.SetModelRootLocalScale(handle, modelScale, modelScale, modelScale) UIRender_Utility.SetRenderEntityDye(renderEntity, heroInfo.HeroAppearanceID, heroInfo.dyeCurPartList, 2) -- 武器设置 UTL.UIRender.LoadMagicWeapon(heroInfo.HeroID, weaponAppearanceId, magicWeaponLevel, isMagicWeaponActive, renderEntity, isPreviewWeapon) end function UIRender_Utility.CreateSceneEffect(handle, effectPath, posX, posY, posZ, scale) local sceneTrans = UTL.UIRender.GetSceneTrans(handle) local modelComponentData = private.modelComponentDatasDic[handle] -- 如果出现一个页面多次调用CreateSceneEffect的情况的话,这里的处理是把原来的Effect停掉然后播放现在传入的特效 if modelComponentData.sceneEffectID then AuxUtil.StopDynamicObject(modelComponentData.sceneEffectID) end local effectID = AuxUtil.PlayDynamicObject(effectPath, -1, sceneTrans, 0) modelComponentData.sceneEffectID = effectID AuxUtil.SetDynamicObjectPos(effectID, posX, posY, posZ) AuxUtil.SetDynamicObjectScale(effectID, scale, scale, scale) end -- 播放英雄常驻特效 function private.PlayHeroModelEffect(renderEntity, effect) if string.isNilOrEmpty(effect) then return 0 end -- 主要播放英雄常驻特效(如紫吕布胸前的火焰) local effectId = UTL.String.GetIdByString(effect) local duration = -1 local timeScale = 1 local heroEffectId = renderEntity:PlayEffect(effectId, duration, true, 0, LuaConst.Layer.Character, timeScale) return heroEffectId end function private.StopHeroModelEffect(handle) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData.heroEffectIDs then return end for index, id in ipairs(modelComponentData.heroEffectIDs) do AuxUtil.StopPsEffect(id) end modelComponentData.heroEffectIDs = nil end function UIRender_Utility.PlayPsEffect(handle, effectPath) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end return AuxUtil.PlayPsEffect(effectPath, modelComponentData.modelRoot, LuaConst.Layer.Character) end function UIRender_Utility.PlayModelPsEffect(handle, effectPath) local modelComponentData = private.modelComponentDatasDic[handle] -- 一般一个页面只播放一个模型PsEffect,如果出现播放多个Effect的情况,那就把旧的特效去掉然后播放新的特效 if modelComponentData.modelEffectID then AuxUtil.StopPsEffect(modelComponentData.modelEffectID) end modelComponentData.modelEffectID = AuxUtil.PlayPsEffect(effectPath, modelComponentData.modelRoot, LuaConst.Layer.Character) end function UIRender_Utility.StopModelPsEffect(handle) local modelComponentData = private.modelComponentDatasDic[handle] if modelComponentData.modelEffectID then AuxUtil.StopPsEffect(modelComponentData.modelEffectID) end end --在坐骑上播放光环特效需要调用此接口 function UIRender_Utility.PlayDriverPsEffect(handle, effectPath) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end return AuxUtil.PlayPsEffect(effectPath, modelComponentData.driverEntity.Transform, LuaConst.Layer.Character) end function UIRender_Utility.PlayHorsePsEffect(handle, effectPath) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end local driverParent = modelComponentData.renderEntity:GetActorSlotNode(18) return AuxUtil.PlayPsEffect(effectPath, driverParent, LuaConst.Layer.Character) end -- 设置场景下 模型的位置(注:2D、3D场景下模型的节点 名字均为“HeroParent”, 尽量保持这个规则) function UIRender_Utility.SetHeroParentPos(handle, posX, posY, posZ) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end UIModelUtils.SetChildPos(modelComponentData.sceneTrans, "HeroParent", posX, posY, posZ) -- 设置位移信息 end -- 设置场景下 模型的旋转(注:2D、3D场景下模型的节点 名字均为“HeroParent”, 尽量保持这个规则) function UIRender_Utility.SetHeroParentRot(handle, rotX, rotY, rotZ) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end UIModelUtils.SetChildRot(modelComponentData.sceneTrans, "HeroParent", rotX, rotY, rotZ) -- 设置旋转信息 end -- 设置模型根节点缩放 function UIRender_Utility.SetModelRootLocalScale(handle, x, y, z) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end modelComponentData.modelRoot:SetLocalScale(x, y, z) end -- 设置场景阴影 function UIRender_Utility.SetSenceShadow(handle, isShadow) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end if modelComponentData.sceneTrans then local shadowPlane = modelComponentData.sceneTrans:Find("HeroParent/ShadowPlane") if shadowPlane then UIUtils.SetActive(shadowPlane, isShadow) end end end -- 设置modelRoot挂在HeroParent节点下 function UIRender_Utility.SetModelRootUnderHeroParent(handle) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end local sceneTrans = modelComponentData.sceneTrans local modelRoot = modelComponentData.modelRoot if modelRoot and sceneTrans then if sceneTrans:Find("HeroParent") then modelComponentData["HeroParent"] = sceneTrans:Find("HeroParent") modelRoot:SetParent(modelComponentData.HeroParent, false) end end end -- 设置绿幕效果(目前仅Cheat使用 & 需要设置USE_PC_CHEAT宏) function UIRender_Utility.SetCheatGreenBg(handle, hexColor, clearEffect, isHideSceen) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end if modelComponentData.layerActiveType == UIRender_Utility.LayerActiveType.HorseShow then UIUtils.SetActive(modelComponentData.sceneBackgroundTrans, false) end local clearHeroShowBg = modelComponentData.layerActiveType == UIRender_Utility.LayerActiveType.HeroShow local closeSceneBGRender = modelComponentData.layerActiveType == UIRender_Utility.LayerActiveType.UI2DBGCommonShow modelComponentData.modelComponent:SetCheatGreenBg(hexColor, clearEffect, modelComponentData.sceneTrans, clearHeroShowBg, closeSceneBGRender) if modelComponentData.sceneTrans and isHideSceen then UIUtils.SetActive(modelComponentData.sceneTrans, false) end end function UIRender_Utility.SetBlendTime(handle, time) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end modelComponentData["blendTime"] = time modelComponentData["isBlend"] = true end function UIRender_Utility.CancelBlend(handle) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end modelComponentData["blendTime"] = nil modelComponentData["isBlend"] = nil end -- 卸载角色(包括模型、武器、灯光、天命) -- exceptLight 不卸载灯光 function UIRender_Utility.DisposePlayerModel(handle, exceptLight) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end if modelComponentData.renderEffectId and modelComponentData.renderEffectId>0 then AuxUtil.StopPsEffect(modelComponentData.renderEffectId) modelComponentData.renderEffectId = nil end --lua端置空主entity和跟随的entity private.ResetRenderEntityList(handle) modelComponentData.renderEntityKey = nil modelComponentData.renderEntity = nil modelComponentData.followerEntityKey = nil modelComponentData.followerEntity = nil local modelComponent = modelComponentData.modelComponent -- 卸载全部Entity modelComponent:DisposeAllEntity() -- 卸载灯光 if exceptLight == nil or exceptLight == false then local lightObj = modelComponentData.lightObj if lightObj then modelComponent:DisposeModelObject(lightObj) modelComponentData.lightObj = nil end end -- 卸载英雄常驻特效 private.StopHeroModelEffect(handle) -- 卸载铸魂天命 UIRender_Utility.DisposeWeaponSoul(handle) end function UIRender_Utility.DisposeSceneEffect(handle) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData.sceneEffectID then return end AuxUtil.StopDynamicObject(modelComponentData.sceneEffectID) modelComponentData.sceneEffectID = nil end function UIRender_Utility.DisposeModelEffect(handle) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData.modelEffectID then return end AuxUtil.StopPsEffect(modelComponentData.modelEffectID) modelComponentData.modelEffectID = nil end -- 卸载场景(2D、3D都可以) function UIRender_Utility.DisposeSceneTrans(handle) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end local modelComponent = modelComponentData.modelComponent local sceneTrans = modelComponentData.sceneTrans if sceneTrans then modelComponent:DisposeModelObject(sceneTrans) modelComponentData.sceneTrans = nil end end --有些方法绑定在OnLayerActive(false),但是有些界面在LayerActive为true的情况下,切换了别的Model,会因为LayerActive没有切换导致状态不对 --比如ManualLightHelper的设置 function UIRender_Utility.SetLayerActive(handle, state) if UIRender_ModelComponentHelper.HasModelComponent(handle) then local modelComponentData = private.modelComponentDatasDic[handle] local modelComponent = modelComponentData.modelComponent modelComponent:OnLayerActive(state) end end -- 在OnClose中调用一下, 用于清空modelComponent注册的回调 以及 所需参数 function UIRender_Utility.DisposeModelComponentData(handle, isKeepHandle) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end local modelComponent = modelComponentData.modelComponent -- 先触发一次回调,因为界面的OnClose比组件的OnComponentDispose先触发 UIRender_Utility.SetLayerActive(handle, false) -- 置空回调方法 if not GameAppInfo.IsVersionGreaterThan19000() then modelComponent.onLayerActiveAction = nil end -- 卸载场景特效 UIRender_Utility.DisposeSceneEffect(handle) -- 卸载模型特效 UIRender_Utility.DisposeModelEffect(handle) -- 卸载角色 UIRender_Utility.DisposePlayerModel(handle) -- 卸载角色根节点 --把位置旋转缩放都恢复 if modelComponentData["modelRoot"] then modelComponentData["modelRoot"]:SetLocalPosition(0, 0, 0) modelComponentData["modelRoot"]:SetLocalScale(1, 1, 1) modelComponentData["modelRoot"]:SetLocalEulerAngles(0, 0, 0) end modelComponent:DisposeRootObject() -- 卸载多余空节点 UIRender_Utility.DisposeExtraEmptyObj(handle) -- 卸载所有Add的ModelObj UIRender_Utility.RemoveModelObj(handle) -- 卸载场景 UIRender_Utility.DisposeSceneTrans(handle) -- 卸载坐骑 UIRender_Utility.DisposeHorseOther(handle) UIRender_ModelComponentHelper.DisposeModelComponentData(handle) -- 清空句柄 if not isKeepHandle then table.clear(modelComponentData) private.modelComponentDatasDic[handle] = nil end end function private.CreateEntityModel(handle, modelPath, ctrlPath, lightPath, modelScale, playIdleAnimClip) local modelComponentData = private.modelComponentDatasDic[handle] local modelComponent = modelComponentData.modelComponent -- 创建模型 local renderEntity if playIdleAnimClip then renderEntity = UTL.UIRender.CreateRenderEntity(modelComponentData.modelRoot, modelPath, modelScale, DEFAULT_ANIMATOR_CONTROLLER_PATH, true) renderEntity:ReplaceAnimation(DEAFULT_IDLE_ANIMATION_CLIP_NAME, playIdleAnimClip) else renderEntity = UTL.UIRender.CreateRenderEntity(modelComponentData.modelRoot, modelPath, modelScale, ctrlPath, true) end modelComponentData["renderEntityKey"] = modelComponent:AddEntity(renderEntity) modelComponentData["renderEntity"] = renderEntity -- 加载灯光 if not string.isNilOrEmpty(lightPath) then local lightObj = modelComponent:CreateModelObject(lightPath, modelComponentData.modelRoot) modelComponentData["lightObj"] = lightObj end return renderEntity end ------------ End 以下为新版展示3D UI接口 End ------------ ---emptyTransform 父节点 一般就是emptyobj(模型节点) --isRevert 由于renderEntity 必须传layer 并且会把layer改写 但是在展示界面 层级分为身体和头 灯光不同 所以需要把layer复原 function UIRender_Utility.CreateRenderEntity(emptyTransform, modelPath, modelScale, animationCtrPath, isRevert) local layer = LuaConst.Layer.Character --层级写死 local cullingMode if GameAppInfo.IsVersionGreaterThan114000() then cullingMode = LuaConst.EntityCullingMode.NoCulling else cullingMode = false end local renderEntity = AuxUtil.LoadRenderEntity(not LevelManager.IsNoBattleLevel(), layer, -1, -1, -1, false, cullingMode, emptyTransform) local animationCtrlId = UTL.String.GetIdByString(animationCtrPath) local pathId = UTL.String.GetIdByString(modelPath) renderEntity:SetModel(0, pathId, 0, modelScale, animationCtrlId, 0, 0, 0, 0, 0) renderEntity.Transform:SetLocalPosition(0, 0, 0) renderEntity.Transform:SetLocalEulerAngles(0, 0, 0) renderEntity.Transform:SetLocalScale(1, 1, 1) renderEntity:ResetLayer() renderEntity:SetVisible(true) if isRevert then renderEntity:ResetActorParent() end return renderEntity end function UIRender_Utility.GetAnimationCtlPath(modelPath) local animCtrlPath = string.match(modelPath, "^(.*)_R[0-9]") if animCtrlPath then animCtrlPath = animCtrlPath ..".controller" else animCtrlPath = string.gsub(modelPath, ".prefab", ".controller") end return animCtrlPath end function UIRender_Utility.LoadMagicWeapon(heroId, weaponAppearance, magicWeaponLevel, isMagicWeaponActive, renderEntity, isPreviewWeaponModel, isHomeModel) local showEquipmentID, effectLevel = private.GetMagicWeaponModel(heroId, weaponAppearance, magicWeaponLevel, isMagicWeaponActive, isPreviewWeaponModel, isHomeModel) local equipData = DataSheetManager.MagicWeaponModel:GetDataByID(showEquipmentID) private.RenderEntitySetWeapon(equipData, renderEntity, effectLevel, isMagicWeaponActive) end function private.RenderEntitySetWeapon(equipData, renderEntity, effectLevel, isMagicWeaponActive, isZhuChengWeapon) if equipData then for i, v in ipairs(equipData.ModelPart_Table) do local slotInt = ExpSystemManager.GetSlotInt(v.ModelSlotStr, v.SlotType, false) if slotInt then local animCtrlPath = "" if v.HasAnim then animCtrlPath = string.match(v.Prefeb, "^(.*)_R[0-9]") if animCtrlPath then animCtrlPath = animCtrlPath .. ".controller" else animCtrlPath = string.gsub(v.Prefeb, ".prefab", ".controller") end if isZhuChengWeapon then -- 主城使用主城状态机 animCtrlPath = string.gsub(animCtrlPath, ".controller", "_ZhuCheng.controller") else -- 展示模也使用战斗模的武器状态机 animCtrlPath = string.gsub(animCtrlPath, "_Show", "") end end local animCtrlPathId = UTL.String.GetIdByString(animCtrlPath) local weaponPath = v.Prefeb local pathId = UTL.String.GetIdByString(weaponPath) renderEntity:SetEquipOrWeapon(0, pathId, slotInt, animCtrlPathId, false, true) if isMagicWeaponActive then renderEntity:ChangeWeaponEffect(0, slotInt, v.MagicWeaponInitialShowEffect[effectLevel]) end end end end end function private.GetMagicWeaponModel(heroId, weaponAppearance, magicWeaponLevel, isMagicWeaponActive, isPreviewWeaponModel, isHomeModel) local weaponData = nil if isMagicWeaponActive and weaponAppearance and weaponAppearance > 0 then weaponData = DataSheetManager.MagicWeaponStar:GetDataByMagicWeaponID_Star(weaponAppearance, magicWeaponLevel) else if isMagicWeaponActive then weaponData = DataSheetManager.MagicWeaponStar:GetDataByMagicWeaponID_Star(heroId, magicWeaponLevel) else weaponData = DataSheetManager.MagicWeaponData:GetDataByMagicWeaponID(heroId) end end if isHomeModel then return weaponData.HomeModel, weaponData.EffectLevel end if isPreviewWeaponModel then return weaponData.PreviewModel, weaponData.EffectLevel else return weaponData.BattleModel, weaponData.EffectLevel end end function UIRender_Utility.LoadEquipPart(showEquipmentID, renderEntity) local equipData = showEquipmentID>0 and DataSheetManager.EquipPartsData:GetDataByID(showEquipmentID) or nil if not equipData then return end for i, v in ipairs(equipData.EquipPart_Table) do local slotInt = ExpSystemManager.GetSlotInt(v.EquipSlotStr, v.SlotType, false) if slotInt then local animCtrlPath = "" if v.HasAnim then animCtrlPath = string.match(v.Prefeb, "^(.*)_R[0-9]") if animCtrlPath then animCtrlPath = animCtrlPath .. ".controller" else animCtrlPath = string.gsub(v.Prefeb, ".prefab", ".controller") end end local animCtrlPathId = UTL.String.GetIdByString(animCtrlPath) local weaponPath = isPVPModel and string.gsub(v.Prefeb, "_Weapon", "_PVP_Weapon") or v.Prefeb local pathId = UTL.String.GetIdByString(weaponPath) renderEntity:SetEquipOrWeapon(0, pathId, slotInt, animCtrlPathId, false, true) end end end function UIRender_Utility.ChangeWeaponEffect(renderEntity, battleModelId, effectLevel) if battleModelId then local weaponModelData = DataSheetManager.MagicWeaponModel:GetDataByID(battleModelId) if weaponModelData then for i,v in ipairs(weaponModelData.ModelPart_Table) do local slotInt = ExpSystemManager.GetSlotInt(v.ModelSlotStr, v.SlotType, false) renderEntity:ChangeWeaponEffect(0, slotInt, v.MagicWeaponInitialShowEffect[effectLevel]) end end end end function UIRender_Utility.GetBattleWeaponEffectId(heroId, magicWeaponLevel, isMagicWeaponActive, weaponAppearance) local equipTable = {} local weaponId = weaponAppearance or heroId local breakData = DataSheetManager.MagicWeaponStar:GetDataByMagicWeaponID_Star(weaponId, magicWeaponLevel) local battleModelId = nil local effectLevel = nil if breakData then battleModelId = breakData.BattleModel effectLevel = breakData.EffectLevel else local weaponData = DataSheetManager.MagicWeaponData:GetDataByMagicWeaponID(heroId) battleModelId = weaponData.BattleModel if isMagicWeaponActive then effectLevel = weaponData.EffectLevel end end return battleModelId , effectLevel end function UIRender_Utility.GetTownWeaponEffectId(heroId, magicWeaponLevel, isMagicWeaponActive, weaponAppearance) local weaponId = weaponAppearance or heroId --这里用TryGet是magicWeaponLevel可能读不到数据 local _, breakData = DataSheetManager.MagicWeaponStar:TryGetDataByMagicWeaponID_Star(weaponId, magicWeaponLevel) local battleModelId = nil local effectLevel = nil if breakData then battleModelId = breakData.HomeModel effectLevel = breakData.EffectLevel else local weaponData = DataSheetManager.MagicWeaponData:GetDataByMagicWeaponID(heroId) battleModelId = weaponData.HomeModel if isMagicWeaponActive then effectLevel = weaponData.EffectLevel end end return battleModelId , effectLevel end function UIRender_Utility.GetPreViewWeaponEffectId(heroId, magicWeaponLevel, isMagicWeaponActive, weaponAppearance) local equipTable = {} local weaponId = heroId == weaponAppearance and heroId or weaponAppearance local breakData = DataSheetManager.MagicWeaponStar:GetDataByMagicWeaponID_Star(weaponId, magicWeaponLevel) local battleModelId = nil local effectLevel = nil if breakData then battleModelId = breakData.PreviewModel effectLevel = breakData.EffectLevel else local weaponData = DataSheetManager.MagicWeaponData:GetDataByMagicWeaponID(heroId) battleModelId = weaponData.PreviewModel if isMagicWeaponActive then effectLevel = weaponData.EffectLevel end end return battleModelId , effectLevel end function UIRender_Utility.GetBossEquipTable(bossData) -- 准备武器模型数据 local equipTable = {} if bossData and bossData.ShowEquipmentID and bossData.ShowEquipmentID > 0 then local equipData = DataSheetManager.EquipPartsData:GetDataByID(bossData.ShowEquipmentID) for i,v in ipairs(equipData.EquipPart_Table) do local data = {} data.Prefeb = v.Prefeb data.EquipSlotStr = v.EquipSlotStr table.insert(equipTable,data) end end return equipTable end function UIRender_Utility.FindInChildren(transform,name) local childCount = transform.childCount local obj = transform:Find(name) if obj then return obj end for i=0, childCount-1 do local value = UIRender_Utility.FindInChildren(transform:GetChild(i),name) if value then return value end end end function private.OnModelComponentLayerActiveType(modelComponent, active) for modelDataHandle, modelComponentData in pairs(private.modelComponentDatasDic) do if modelComponentData.modelComponent == modelComponent then UIRender_ModelComponentHelper.OnModelComponentLayerActiveType(modelDataHandle, modelComponentData, active) break end end end -----------------------------------以下为各个模块的逻辑业务接口------------------------------------ function UIRender_Utility.RotateEntity(handle, rotateAngle, withLight, withScene) local modelComponentData = private.modelComponentDatasDic[handle] if withLight then private.RotateTrans(modelComponentData.modelRoot, rotateAngle) else private.RotateTrans(modelComponentData["renderEntity"].GameObject.transform, rotateAngle) end if withScene and modelComponentData.sceneTrans then private.RotateTrans(modelComponentData.sceneTrans, rotateAngle) end end function private.RotateTrans(trans, rotateAngle) local angleX, angleY, angleZ = trans:GetLocalEulerAngles() trans:SetLocalEulerAngles(angleX, angleY+rotateAngle, angleZ) end function UIRender_Utility.SetEntityEulerAngles(handle, rotVal, withLight, withScene) local modelComponentData = private.modelComponentDatasDic[handle] if withLight then modelComponentData["modelRoot"]:SetLocalEulerAngles(0, rotVal, 0) else modelComponentData["renderEntity"].GameObject.transform:SetLocalEulerAngles(0, rotVal, 0) end if withScene and modelComponentData.sceneTrans then modelComponentData.sceneTrans:SetLocalEulerAngles(0, rotVal, 0) end end function UIRender_Utility.SetEntityPos(handle, posX, posY, posZ) local modelComponentData = private.modelComponentDatasDic[handle] modelComponentData["renderEntity"].GameObject.transform:SetLocalPosition(posX, posY, posZ) end -- 显隐角色根节点(不包含场景) function UIRender_Utility.SetModelVisible(handle, isVisible) local modelComponentData = private.modelComponentDatasDic[handle] if modelComponentData.modelRoot then UIUtils.SetActive(modelComponentData.modelRoot, isVisible) end end function UIRender_Utility.RenderEntityPlayAnim(handle, animStateName) local modelComponentData = private.modelComponentDatasDic[handle] if modelComponentData.renderEntity then local animIntKey= UTL.String.GetIdByString(animStateName) modelComponentData.renderEntity:PlayAnimation(animIntKey, false) end end function UIRender_Utility.ModelPlayAnim(handle, animPath) local modelComponentData = private.modelComponentDatasDic[handle] if not string.isNilOrEmpty(animPath) then UIModelUtils.PlayModelAnimation(animPath, modelComponentData.renderEntity.Transform:GetChild(0)) end end -- 替换并播放 function UIRender_Utility.PlayRenderEntityTriggerAnim(handle, animPath) local modelComponentData = private.modelComponentDatasDic[handle] local entityTrans = modelComponentData.renderEntity.Transform if entityTrans then UIModelUtils.PlayAnimation(DEFAULT_ANIMATION_CLIP_NAME, animPath, entityTrans, "IsAction") end end -- 创建额外的空Empty_Gameobject function UIRender_Utility.CreateExtraEmptObj(handle, parentTrans, posX, posY, posZ, rotVal) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData["extraEmptyObjList"] then modelComponentData["extraEmptyObjList"] = {} end local emptyObj = AuxUtil.GetEmptyObject(parentTrans, "EXTRA_EMPTY_GAME_OBJECT") emptyObj.transform:SetLocalPosition(posX or 0, posY or 0, posZ or 0) emptyObj.transform:SetLocalScale(1, 1, 1) emptyObj.transform:SetLocalEulerAngles(0, rotVal or 0, 0) table.insert(modelComponentData["extraEmptyObjList"], emptyObj) return emptyObj end function UIRender_Utility.DisposeExtraEmptyObj(handle) local modelComponentData = private.modelComponentDatasDic[handle] if modelComponentData["extraEmptyObjList"] then for i, v in ipairs(modelComponentData["extraEmptyObjList"]) do v.transform:SetLocalScale(1, 1, 1) v.transform:SetLocalPosition(0, 0, 0) v.transform:SetLocalEulerAngles(0, 0, 0) AuxUtil.ReturnEmptyObject(v) end modelComponentData["extraEmptyObjList"] = nil end end --- 在场景中创建一个obj ---@return modelTrans Transform function UIRender_Utility.AddModelObj(handle, modelPath, parentTans, posX, posY, posZ, scaleVal) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData.modelObjList then modelComponentData.modelObjList = {} end local modelComponent = modelComponentData.modelComponent local modelTrans = modelComponent:CreateModelObject(modelPath, parentTans or modelComponentData.modelRoot) modelTrans:SetLocalPosition(posX, posY, posZ) modelTrans:SetLocalScale(scaleVal or 1, scaleVal or 1, scaleVal or 1) modelTrans:SetLocalEulerAngles(0, 0, 0) table.insert(modelComponentData.modelObjList, modelTrans) return modelTrans end function UIRender_Utility.RemoveModelObj(handle) local modelComponentData = private.modelComponentDatasDic[handle] local modelList = modelComponentData.modelObjList if modelList then for i = #modelList, 1, -1 do local modelTrans = table.remove(modelList, i) modelTrans:SetLocalPosition(0, 0, 0) modelTrans:SetLocalScale(1, 1, 1) modelTrans:SetLocalEulerAngles(0, 0, 0) modelComponentData.modelComponent:DisposeModelObject(modelTrans) end end modelComponentData.modelObjList = nil end function private.ResetRenderEntityList(handle) local modelComponentData = private.modelComponentDatasDic[handle] local renderEntityList = modelComponentData.renderEntityList if renderEntityList then for _, renderEntity in ipairs(renderEntityList) do renderEntity.Transform:SetLocalPosition(0, 0) renderEntity.Transform:SetLocalEulerAngles(0, 0, 0) renderEntity.Transform:SetLocalScale(1, 1, 1) end modelComponentData.renderEntityList = nil end end -- 修改相机参数(需激活相机后调用) function UIRender_Utility.SetCameraParam(handle, posVec3, rotVec3, FOV) local modelComponentData = private.modelComponentDatasDic[handle] local cameraParent = modelComponentData.cameraParent if cameraParent then UIModelUtils.StartUIShowSystem(cameraParent, posVec3 or v3_zero, rotVec3 or v3_zero, FOV) end end -- 修改cameraParent节点transform function UIRender_Utility.SetCameraParentTransform(handle, PosAndRot) local modelComponentData = private.modelComponentDatasDic[handle] local cameraParent = modelComponentData.cameraParent if cameraParent then cameraParent:SetLocalPosition(PosAndRot.Pos[1], PosAndRot.Pos[2], PosAndRot.Pos[3]) cameraParent:SetLocalEulerAngles(PosAndRot.Rot[1], PosAndRot.Rot[2], PosAndRot.Rot[3]) end end -- 修改blackPlane节点transform function UIRender_Utility.SetBlackPlaneTransform(handle, PosAndRot) local modelComponentData = private.modelComponentDatasDic[handle] local blackPlane = modelComponentData.blackPlane if blackPlane then blackPlane:SetLocalPosition(PosAndRot.Pos[1], PosAndRot.Pos[2], PosAndRot.Pos[3]) blackPlane:SetLocalEulerAngles(PosAndRot.Rot[1], PosAndRot.Rot[2], PosAndRot.Rot[3]) end end -- 设置摄像机投影为正交模式并设置Size function UIRender_Utility.SetCamerOrthographic(orthoGraphicSize) CameraController.Instance:ChangeCameraOrthographic(orthoGraphicSize, 0.3) end -- 在场景中播放特效 function UIRender_Utility.PlayScenePSEffect(handle, psEffectPath, duration) local modelComponentData = private.modelComponentDatasDic[handle] local sceneTrans = modelComponentData.sceneTrans if sceneTrans then return AuxUtil.PlayDynamicObject(psEffectPath, duration or -1, sceneTrans) end return 0 end -----------------------------------英雄---------------------------------------------------- --英雄的TimeLine展示 function UIRender_Utility.CreateHeroTimelineTrans(handle, timeLinePath, posX, posY, posZ) -- Editor下,方便美术预览展示Timeline if UNITY_EDITOR then local customTimelinePath = private.GetEditorCustomModelPath() if customTimelinePath ~= nil and customTimelinePath ~= "" then timeLinePath = customTimelinePath end end local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end local modelComponent = modelComponentData.modelComponent if UIRender_ModelComponentHelper.HasModelComponent(handle) then modelComponent:OnLayerActive(false) end local sceneTrans = modelComponentData.sceneTrans if sceneTrans then if modelComponentData.scenePath ~= timeLinePath then UIRender_Utility.DisposeSceneTrans(handle) sceneTrans = modelComponent:CreateModelObject(timeLinePath, nil) end else sceneTrans = modelComponent:CreateModelObject(timeLinePath, nil) end sceneTrans:SetLocalPosition(posX, posY, posZ) modelComponentData["scenePath"] = timeLinePath modelComponentData["sceneTrans"] = sceneTrans UIRender_ModelComponentHelper.SetLayerActiveByType(handle, modelComponentData, UIRender_Utility.LayerActiveType.HeroSelect) modelComponent:OnLayerActive(true) end function UIRender_Utility.CreateDynamicHeroTimeline(handle, timeLinePath, modelPath, appearanceID, showEquipmentID, posX, posY, posZ) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end local modelComponent = modelComponentData.modelComponent if UIRender_ModelComponentHelper.HasModelComponent(handle) then modelComponent:OnLayerActive(false) end local sceneTrans = modelComponentData.sceneTrans if sceneTrans then if modelComponentData.scenePath ~= timeLinePath then UIRender_Utility.DisposeSceneTrans(handle) UIRender_Utility.DisposePlayerModel(handle) sceneTrans = modelComponent:CreateModelObject(timeLinePath, nil) private.LoadTimelineModel(handle, sceneTrans, modelPath, string.gsub(timeLinePath, ".prefab", ".controller"), showEquipmentID, appearanceID) end else sceneTrans = modelComponent:CreateModelObject(timeLinePath, nil) private.LoadTimelineModel(handle, sceneTrans, modelPath, string.gsub(timeLinePath, ".prefab", ".controller"), showEquipmentID, appearanceID) end sceneTrans:SetLocalPosition(posX, posY, posZ) modelComponentData["scenePath"] = timeLinePath modelComponentData["sceneTrans"] = sceneTrans UIRender_ModelComponentHelper.SetLayerActiveByType(handle, modelComponentData, UIRender_Utility.LayerActiveType.HeroSelect) modelComponent:OnLayerActive(true) end function private.LoadTimelineModel(handle, timelineRoot, modelPath, modelCtrlPath, showEquipmentID, appearanceID) local renderEntity = private.CreateEntityModel(handle, modelPath, modelCtrlPath, nil, 1) renderEntity.Transform:SetParent(timelineRoot, false) renderEntity.Transform:SetLocalPosition(0, 0, 0) local partList = MDL.DyeAppearance.GetDyeAppearancePartList(appearanceID) if partList then UIRender_Utility.SetRenderEntityDye(renderEntity, appearanceID, partList, 2) end local isSuccess, equipData = DataSheetManager.MagicWeaponModel:TryGetDataByID(showEquipmentID) if isSuccess then for i, v in ipairs(equipData.ModelPart_Table) do local slotInt = ExpSystemManager.GetSlotInt(v.ModelSlotStr, v.SlotType, false) if slotInt then local weaponPath = v.Prefeb local pathId = UTL.String.GetIdByString(weaponPath) renderEntity:SetEquipOrWeapon(0, pathId, slotInt, -1, false, true) end end end UIRender_Utility.RenderEntityPlayAnim(handle, "timeline") end --todo 目前动态加载模型的timeline只有典藏皮肤,暂时通过appearanceId来区分兼容,后续全部替换成动态加载可以直接替换掉旧接口 function UIRender_Utility.GetHeroTimelineParam(heroId, appearanceId, weaponAppearanceId) local weaponId local heroId, heroWearAppearanceID = UIRender_Utility.PreprocessHeroData(heroId, true, appearanceId) local modelPath = UIRender_Utility.GetModelPath(heroId, true, heroWearAppearanceID) local timelinePath if heroWearAppearanceID and heroWearAppearanceID > 0 then timelinePath = DataSheetManager.HeroAppearance:GetDataByID(heroWearAppearanceID).PreviewTimeline else timelinePath = DataSheetManager.HeroNum:GetDataByID(heroId).PreviewTimeline end if weaponAppearanceId and weaponAppearanceId > 0 then local isSuccess, cfg = DataSheetManager.MagicWeaponStar:TryGetDataByMagicWeaponID_Star(weaponAppearanceId, 0) if isSuccess then weaponId = cfg.PreviewModel else weaponId = DataSheetManager.MagicWeaponData:GetDataByMagicWeaponID(heroId).PreviewModel end else weaponId = DataSheetManager.MagicWeaponData:GetDataByMagicWeaponID(heroId).PreviewModel end local isDynamic = DataSheetManager.CollectionAP:TryGetDataByID(appearanceId) return timelinePath, modelPath, weaponId, isDynamic end function UIRender_Utility.SetRenderEntityParent(handle, parentTf) local modelComponentData = private.modelComponentDatasDic[handle] if modelComponentData then local renderEntity = modelComponentData.renderEntity renderEntity.Transform:SetParent(parentTf, false) renderEntity.Transform:SetLocalPosition(0, 0, 0) end end function UIRender_Utility.SetRenderEntityParentByIndex(handle, parentTf, index) local modelComponentData = private.modelComponentDatasDic[handle] if modelComponentData then if modelComponentData.renderEntityList then local renderEntity = modelComponentData.renderEntityList[index] if renderEntity then renderEntity.Transform:SetParent(parentTf, false) renderEntity.Transform:SetLocalPosition(0, 0, 0) end end end end function UIRender_Utility.SetRenderEntityModelEffect(handle, heroId, heroAppearanceId, isBattleModel) local modelComponentData = private.modelComponentDatasDic[handle] if modelComponentData then local renderEntity = modelComponentData.renderEntity local effectName = UIRender_Utility.GetHeroEffectName(heroId, heroAppearanceId, isBattleModel) local heroEffectID = private.PlayHeroModelEffect(renderEntity, effectName) if not modelComponentData.heroEffectIDs then modelComponentData.heroEffectIDs = {} end table.insert(modelComponentData.heroEffectIDs, heroEffectID) end end function UIRender_Utility.GetHeroEffectName(heroId, heroAppearanceId, isBattleModel) heroId, heroAppearanceId = UIRender_Utility.PreprocessHeroData(heroId, not isBattleModel, heroAppearanceId) local modelId if heroAppearanceId and heroAppearanceId > 0 then local heroAppearanceData = DataSheetManager.HeroAppearance:GetDataByID(heroAppearanceId) if isBattleModel then modelId = heroAppearanceData.BattleModel else modelId = heroAppearanceData.PreviewModel end else if isBattleModel then local heroData = DataSheetManager.HeroData:GetDataByID(heroId) modelId = heroData.ModelID else local heroData = DataSheetManager.HeroNum:GetDataByID(heroId) modelId = heroData.PreviewModel end end local monsterData = DataSheetManager.MonsterModelData:GetDataByID(modelId) return monsterData.ModelPsEffect end --useServerAppearance:使用服务器数据的外观 function private.GetHeroShowData(heroId, heroAppearanceID, useServerAppearance, isBattleModel) if useServerAppearance then local serverHeroData = MDL.HeroSelect.GetHeroInfo(heroId) if serverHeroData and serverHeroData.curAppearanceId>0 then heroAppearanceID = serverHeroData.curAppearanceId end end heroId, heroAppearanceID = UIRender_Utility.PreprocessHeroData(heroId, true, heroAppearanceID) local modelId, previewModelLight if heroAppearanceID and heroAppearanceID > 0 then local appearanceData = DataSheetManager.HeroAppearance:GetDataByID(heroAppearanceID) if isBattleModel then modelId = appearanceData.BattleModel else modelId = appearanceData.PreviewModel end previewModelLight = appearanceData.PreviewModelLight else local heroData = DataSheetManager.HeroNum:GetDataByID(heroId) previewModelLight = heroData.PreviewModelLight if isBattleModel then local heroDataTmp = DataSheetManager.HeroData:GetDataByID(heroId) modelId = heroDataTmp.ModelID else modelId = heroData.PreviewModel end end local monsterData = DataSheetManager.MonsterModelData:GetDataByID(modelId) --目前看界面展示都是用的场景模型 local dir, actorDir, prefab = string.match(monsterData.Path, "(%S*)/(%S*)/(%S*)") local animCtrlPath = string.gsub(monsterData.Path, prefab, actorDir.."_ZhuCheng.controller") local heroEffectPath = "" if not string.isNilOrEmpty(monsterData.ModelPsEffect) then heroEffectPath = string.format(PsGroupPath,monsterData.ModelPsEffect) end return heroId, monsterData.Path, monsterData.ModelScale, heroEffectPath, previewModelLight, animCtrlPath end function UIRender_Utility.HeroEquipMagicWeapon(handle, heroId, weaponAppearanceId, magicWeaponLevel, isMagicWeaponActive, isPreviewWeapon) local modelComponentData = private.modelComponentDatasDic[handle] local newHeroId = UIRender_Utility.PreprocessHeroData(heroId, true) if newHeroId ~= heroId then weaponAppearanceId = SHOW_HERO_ID end UTL.UIRender.LoadMagicWeapon(heroId, weaponAppearanceId, magicWeaponLevel, isMagicWeaponActive, modelComponentData.renderEntity, isPreviewWeapon) end function UIRender_Utility.CreateHeroRenderTexture(handle, heroId, heroAppearanceID, renderModelId, lightPath, isBattleModel, dyeCurPartList) UIRender_Utility.DisposePlayerModel(handle) local newHeroId, modelPath, modelScale, heroEffectPath, heroLightPath, animCtrlPath = private.GetHeroShowData(heroId, heroAppearanceID, false, isBattleModel) heroEffectPath = UIRender_Utility.GetHeroEffectName(newHeroId, heroAppearanceID) if not string.isNilOrEmpty(lightPath) then heroLightPath = lightPath end UTL.UIRender.CreateRTSceneTrans(handle, heroLightPath) UTL.UIRender.CreateRTRenderModel(handle, modelPath, modelScale, nil, renderModelId, nil, heroEffectPath) if dyeCurPartList then UIRender_Utility.SetModelDye(handle, heroAppearanceID, dyeCurPartList, isBattleModel and 1 or 2) end end function UIRender_Utility.CreateHeroFollowerTexture(handle, followerCfgId) local modelComponentData = private.modelComponentDatasDic[handle] local modelDataCfg = DataSheetManager.MonsterModelData:GetDataByID(followerCfgId) --设置主模型位置信息 modelComponentData.renderEntity.Transform:SetLocalPosition(0.65, 0, 0) modelComponentData.renderEntity.Transform:SetLocalEulerAngles(0, -21, 0) local followerEntity = UTL.UIRender.CreateRenderEntity(modelComponentData.renderEntity.Transform.parent, modelDataCfg.Path, modelDataCfg.ModelScale, UIRender_Utility.GetAnimationCtlPath(modelDataCfg.Path), true) modelComponentData.followerEntityKey = modelComponentData.modelComponent:AddEntity(followerEntity) modelComponentData.followerEntity = followerEntity modelComponentData.followerEntity.Transform:SetLocalPosition(-0.3, 0, 0) modelComponentData.followerEntity.Transform:SetLocalEulerAngles(0, 48, 0) modelComponentData.followerEntity.Transform:SetLocalScale(0.93, 0.93, 0.93) UTL.UIRender.LoadEquipPart(modelDataCfg.EquipmentID, followerEntity) end function UIRender_Utility.ShowOrHideHeroModel(handle, isShow) local modelComponentData = private.modelComponentDatasDic[handle] UIUtils.SetActive(modelComponentData.renderEntity.Transform, isShow) end --显示3D宝物 function UIRender_Utility.CreateTreasure3DModel(handle, treasureId) UIRender_Utility.DisposePlayerModel(handle) local modelComponentData = private.modelComponentDatasDic[handle] local treasureData = DataSheetManager.TreasureData:GetDataByTreasureID(treasureId) UTL.UIRender.Create2DSceneTrans(handle, Common2DScenePrefab, 1600, 0, 1600, Common2DSceneTexture, false) local renderEntity = private.CreateEntityModel(handle, treasureData.TreasureMode, "", treasureData.TreasurePreviewModelLight, 1) renderEntity.Transform:SetLocalEulerAngles(0, treasureData.Angle, 0) UIModelUtils.SetChildRot(modelComponentData.sceneTrans, "HeroParent", treasureData.AngleX, 0, treasureData.AngleZ) modelComponentData.renderEffectId = UTL.UIRender.PlayPsEffect(handle, treasureData.TreasureShowEffect) UIRender_Utility.ModelPlayAnim(handle, treasureData.TreasureAnim) end --宝物做的一个调整距离 function UIRender_Utility.GetDistanceFixValue(handle) local ratio = private.GetCustomScreenRadio() local modelComponentData = private.modelComponentDatasDic[handle] local HeroParent = modelComponentData.sceneTrans:Find("HeroParent") local CameraParent = modelComponentData.sceneTrans:Find("CameraParent") local HeroParentPos = Vector3.New(HeroParent:GetPosition()) local CameraParentPos = Vector3.New(CameraParent:GetPosition()) return (0.182*Vector3.Distance(HeroParentPos, CameraParentPos) + 0.078) * ratio end function private.GetCustomScreenRadio() local screenWidth, screenHeight = UIUtils.GetScreenSize(1, 1) local ratio = screenWidth/screenHeight if ratio<1.7778 then ratio = 0.226*ratio-0.49 else ratio=0 end return ratio end function UIRender_Utility.CreateTreasureRenderTexture(handle, treasureCfgId, renderModelId) local modelComponentData = private.modelComponentDatasDic[handle] UIRender_Utility.DisposePlayerModel(handle) local treasureData = DataSheetManager.TreasureData:GetDataByTreasureID(treasureId) UTL.UIRender.CreateRTSceneTrans(handle, treasureData.TreasurePreviewModelLight) UTL.UIRender.CreateRTRenderModel(handle, treasureData.TreasureMode, 1, nil, renderModelId) UIModelUtils.CreateModelAnimAgent(modelComponentData.renderEntity.Transform, treasureData.TreasureAnim) modelComponentData.renderEffectId = UTL.UIRender.PlayPsEffect(handle, treasureData.TreasureShowEffect) end -----------------------------------坐骑---------------------------------------------------- function UIRender_Utility.CreateHorse3DModel(handle, horseCfgId, horseAppearanceID, layerActiveType, withoutSenceAndBg) UIRender_Utility.DisposePlayerModel(handle) UIRender_Utility.EndRideHorse(handle) local modelComponentData = private.modelComponentDatasDic[handle] local horseCfg = nil if horseAppearanceID then if horseAppearanceID > 0 then horseCfg = MDL.WarHorse.GetAppearanceInfoByID(horseAppearanceID) else horseCfg = DataSheetManager.HorseData:GetDataByHorseID(horseCfgId) end else horseCfg = CTL.WarHorse.GetCurRealHorseDataByHorseID(horseCfgId) end if not withoutSenceAndBg then --创建坐骑脚下的台子 local scenePath = ConstAssetPathConfig.scenePath modelComponentData["sceneTrans"] = private.CreateNormalSceneTrans(handle, scenePath) modelComponentData["scenePath"] = scenePath modelComponentData["sceneTrans"]:SetLocalPosition(1600, 0, 1600) modelComponentData["sceneTrans"]:SetLocalScale(horseCfg.GroundScale, horseCfg.GroundScale, horseCfg.GroundScale) modelComponentData["sceneTrans"]:SetLocalEulerAngles(0, horseCfg.ModelRot, 0) --创建背景 if not modelComponentData["sceneBackgroundTrans"] then local sceneBackgroundPath = ConstAssetPathConfig.sceneBackgroundPath modelComponentData["sceneBackgroundTrans"] = modelComponentData.modelComponent:CreateModelObject(sceneBackgroundPath, AuxUtil.MainCameraTrans) end end local modelRoot = modelComponentData.modelRoot if not modelRoot then modelRoot = modelComponentData.modelComponent:CreateRootObject() modelComponentData["modelRoot"] = modelRoot end if not UIRender_Utility.CanLoadHorse(horseCfg) then horseCfg = DataSheetManager.HorseData:GetDataByHorseID(1) end local modelPath, horseShowEffect = UIRender_Utility.GetHorseModelPathAndEffect(horseCfg) local modelRot = horseCfg.SettingModelRot local scale = horseCfg.SettingModelScale local x,y,z = 1600, 0, 1600 if layerActiveType == UIRender_Utility.LayerActiveType.HorseShow then modelRot = horseCfg.ModelRot scale = horseCfg.ModelScale if horseCfg.ModelXYZ and #horseCfg.ModelXYZ > 0 then x,y,z = CTL.WarHorse.GetHorseBattleAppearanceXYZ(horseCfg) end end local renderEntity = private.CreateEntityModel(handle, modelPath, ConstAssetPathConfig.DEFAULT_ANIMATOR_CONTROLLER_PATH, horseCfg.HorsePreviewModelLight, scale) modelRoot:SetPosition(x,y,z) modelRoot:SetLocalEulerAngles(0, modelRot, 0) renderEntity:ReplaceAnimation("Hero_CaoCao_idle_loop", horseCfg.ModelIdleAnim) modelComponentData.renderEffectId = UTL.UIRender.PlayPsEffect(handle, horseShowEffect) UIRender_ModelComponentHelper.SetLayerActiveByType(handle, modelComponentData, UIRender_Utility.LayerActiveType.HorseShow) modelComponentData.modelComponent:OnLayerActive(true) end function UIRender_Utility.HorsePlayAnim(handle, animStateName) local modelComponentData = private.modelComponentDatasDic[handle] if modelComponentData.renderEntity then modelComponentData.renderEntity:ReplaceAnimation("Hero_CaoCao_NPC_Plot_no", animStateName) local animIntKey= UTL.String.GetIdByString("IsAction") modelComponentData.renderEntity:PlayAnimation(animIntKey, false) end end function UIRender_Utility.DriverEntityPlayAnim(handle, animStateName) local modelComponentData = private.modelComponentDatasDic[handle] if modelComponentData.driverEntity then if not GameAppInfo.IsVersionGreaterThan114000() and modelComponentData.heroId == 41 then -- 典韦动画播放需要特殊处理 UIModelUtils.PlayAnimByTrigger(animStateName, animStateName, modelComponentData.driverEntity.Transform) else local animIntKey = UTL.String.GetIdByString(animStateName) modelComponentData.driverEntity:PlayAnimationState(animStateName, 0, 0) end end end function UIRender_Utility.SetConfigLayers(handle, configLayer) local modelComponentData = private.modelComponentDatasDic[handle] if modelComponentData then local layers = RendererLayerCfg.GetRendererLayers(configLayer) if layers then modelComponentData.renderEntity:SetRendererLayers(layers) end end end function UIRender_Utility.StartRideHorse(handle, horseId, heroId, headInfo) local modelComponentData = private.modelComponentDatasDic[handle] local heroID = heroId if not heroId then local activeInfo = MDL.WarHorse.GetInfoByID(horseId) if activeInfo and activeInfo.HeroID then heroID = activeInfo.HeroID else heroID = MDL.Player.GetCurShowId() end end if not modelComponentData.heroEffectIDs then modelComponentData.heroEffectIDs = {} end modelComponentData.heroId = heroID local modelPath, equipTable, modelScale, animCtrlPath, heroEffectPath, heroLightEffects if headInfo then modelPath, equipTable, modelScale, animCtrlPath, heroEffectPath, heroLightEffects = UTL.UIRender.LoadRankListOtherHorseHero(headInfo) else modelPath, equipTable, modelScale, animCtrlPath, heroEffectPath, heroLightEffects = UTL.UIRender.LoadHorseHero(heroID, true) end if not modelComponentData.driverEntityPath or modelComponentData.driverEntityPath ~= modelPath then UIRender_Utility.EndRideHorse(handle) modelComponentData.driverEntityPath = modelPath local driverModelParent = modelComponentData.renderEntity:GetActorSlotNode(13) local driverEntity = UTL.UIRender.CreateRenderEntity(driverModelParent, modelPath, modelScale, animCtrlPath, false) modelComponentData.driverEntity = driverEntity local heroAppearanceId = headInfo and headInfo.HeroAppearanceID or MDL.HeroSelect.GetAppearanceIDByHeroID(heroID) heroEffectPath = UIRender_Utility.GetHeroEffectName(heroID, heroAppearanceId, true) if headInfo and headInfo.dyeCurPartList then UIRender_Utility.SetRenderEntityDye(driverEntity, headInfo.HeroAppearanceID, headInfo.dyeCurPartList, 1) end local heroEffectID = private.PlayHeroModelEffect(driverEntity, heroEffectPath) table.insert(modelComponentData.heroEffectIDs, heroEffectID) -- 武器设置 for i, v in ipairs(equipTable) do local slotInt = ExpSystemManager.GetSlotInt(v.EquipSlotStr, v.SlotType, false) if slotInt then local animCtrlPath = v.animCtrlPath or "" local animCtrlPathId = UTL.String.GetIdByString(animCtrlPath) local weaponPath = v.Prefeb local pathId = UTL.String.GetIdByString(weaponPath) driverEntity:SetEquipOrWeapon(0, pathId, slotInt, animCtrlPathId, false, true) if v.effectPath then driverEntity:ChangeWeaponEffect(0, slotInt, v.effectPath) end end end end end function UIRender_Utility.EndRideHorse(handle) local modelComponentData = private.modelComponentDatasDic[handle] if modelComponentData["driverEntity"] then modelComponentData["driverEntity"]:Dispose(false) end modelComponentData.driverEntityPath = nil modelComponentData.driverEntity = nil end --清理掉坐骑模型相关的,单独给坐骑创建非公用的 function UIRender_Utility.DisposeHorseOther(handle) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end UIRender_Utility.EndRideHorse(handle) if modelComponentData.sceneBackgroundTrans then modelComponentData.modelComponent:DisposeModelObject(modelComponentData.sceneBackgroundTrans) modelComponentData.sceneBackgroundTrans = nil end if modelComponentData.HorseCamTarget then AuxUtil.ReturnEmptyObject(modelComponentData.HorseCamTarget) modelComponentData.HorseCamTarget = nil end end function UIRender_Utility.CreateOtherHorseRenderTexture(handle, renderModelID, headInfo) local horseData local modelComponentData = private.modelComponentDatasDic[handle] if headInfo.horseAppearanceId > 0 then horseData = MDL.WarHorse.GetAppearanceInfoByID(headInfo.horseAppearanceId) else horseData =DataSheetManager.HorseData:GetDataByHorseID(headInfo.HorseID) end local horseModelData = DataSheetManager.HorseModelData:GetDataByHorseModelID(horseData.HorseModelID) UIRender_Utility.CreateRTSceneTrans(handle, horseData.HorsePreviewModelLight) UIRender_Utility.CreateRTRenderModel(handle, horseModelData.HorseModel, 1, nil, renderModelID) modelComponentData.renderEffectId = UTL.UIRender.PlayPsEffect(handle, horseModelData.HorseShowEffect) end function UIRender_Utility.CreateHorseRenderTexture(handle, horseCfgId, renderModelId) local modelComponentData = private.modelComponentDatasDic[handle] UIRender_Utility.DisposeHorseRenderTexutureOther(handle) local config = DataSheetManager.HorseData:GetDataByHorseID(horseCfgId) local horseModeData = DataSheetManager.HorseModelData:GetDataByHorseModelID(config.HorseModelID) UTL.UIRender.CreateRTSceneTrans(handle, config.HorsePreviewModelLight) UTL.UIRender.CreateRTRenderModel(handle, horseModeData.HorseModel, 1, nil, renderModelId) modelComponentData.renderEntity.Transform:SetLocalEulerAngles(0, config.ActivationModelRot, 0) UIModelUtils.CreateModelAnimAgent(modelComponentData.renderEntity.Transform, config.ModelAnim) modelComponentData.renderEffectId = UTL.UIRender.PlayPsEffect(handle, horseModeData.HorseShowEffect) end function UIRender_Utility.DisposeHorseRenderTexutureOther(handle) UIModelUtils.DisposeModelAnimAgent() UIRender_Utility.DisposePlayerModel(handle) end -----------------------------------神兵GameAppInfo.IsVersionGreaterThan19000()使用---------------------------------------------------- function UIRender_Utility.CreateMagicWeapon3DModel(handle, magicWeaponModelId, effectLevel, bgPath) UIRender_Utility.DisposeMagicWeaponOther(handle) if not CTL.DivineWeapon.IsDivineWeaponAssetAllLoadedByModelId(magicWeaponModelId) then magicWeaponModelId = DataSheetManager.MagicWeaponData:GetDataByMagicWeaponID(SHOW_HERO_ID).PreviewModel end local weaponModelData = DataSheetManager.MagicWeaponModel:GetDataByID(magicWeaponModelId) local modelComponentData = private.modelComponentDatasDic[handle] UTL.UIRender.Create2DSceneTrans(handle, Common2DScenePrefab, 1600, 0, 1600, bgPath or Common2DSceneTexture, false) if modelComponentData["lightObj"] then modelComponentData.modelComponent:DisposeModelObject(modelComponentData.lightObj) end modelComponentData["lightObj"] = modelComponentData.modelComponent:CreateModelObject(weaponModelData.ModelLight, modelComponentData.modelRoot) UIModelUtils.SetChildPos(modelComponentData.sceneTrans, "HeroParent", 1, 0, 0) modelComponentData.weaponNode = modelComponentData.modelComponent:CreateModelObject(weaponModelData.ModelNode, modelComponentData.modelRoot) modelComponentData.weaponNode:SetLocalPosition(private.GetCustomScreenRadio()-0.34, 0, 0) for i, v in ipairs(weaponModelData.ModelPart_Table) do UIModelUtils.AddMagicWeaponPartData(modelComponentData.weaponNode, v.Prefeb, v.MagicWeaponInitialShowEffect[effectLevel], i-1, v.MagicWeaponAction) end UIRender_ModelComponentHelper.SetLayerActiveByType(handle, modelComponentData, UIRender_Utility.LayerActiveType.UI2DBGCommonShow) modelComponentData.modelComponent:OnLayerActive(true) end function UIRender_Utility.ChangeMagicWeaponnEffect(handle, effectPath, index) local modelComponentData = private.modelComponentDatasDic[handle] UIModelUtils.ChangeMagicWeaponnEffect(modelComponentData.weaponNode, effectPath, index) end function UIRender_Utility.CreateMagicWeaponRTByWeaponId(handle, magicWeaponModelId, magicWeaponAppearanceID, renderModelId) if not CTL.DivineWeapon.IsDivineWeaponAssetAllLoaded(magicWeaponModelId, magicWeaponAppearanceID) then magicWeaponModelId = SHOW_HERO_ID magicWeaponAppearanceID = 0 end local magicWeaponData = nil if magicWeaponAppearanceID == 0 then magicWeaponData = DataSheetManager.MagicWeaponData:GetDataByMagicWeaponID(magicWeaponModelId) else magicWeaponData = DataSheetManager.MagicWeaponStar:GetDataByMagicWeaponID_Star(magicWeaponAppearanceID, 15) end UTL.UIRender.CreateMagicWeaponRenderTexture(handle, magicWeaponData.PreviewModel, magicWeaponData.EffectLevel, renderModelId) end function UIRender_Utility.CreateMagicWeaponRenderTexture(handle, magicWeaponModelId, effectLevel, renderModelId) local modelComponentData = private.modelComponentDatasDic[handle] UIRender_Utility.DisposeMagicWeaponOther(handle) local weaponModelData = DataSheetManager.MagicWeaponModel:GetDataByID(magicWeaponModelId) local modelComponentData = private.modelComponentDatasDic[handle] UTL.UIRender.CreateRTSceneTrans(handle, weaponModelData.ModelLight) modelComponentData.weaponNode = modelComponentData.modelComponent:CreateModelObject(weaponModelData.ModelNode, modelComponentData.modelRoot) modelComponentData.weaponNode:SetLocalPosition(0, 0, 0) for i, v in ipairs(weaponModelData.ModelPart_Table) do UIModelUtils.AddMagicWeaponPartData(modelComponentData.weaponNode, v.Prefeb, v.MagicWeaponInitialShowEffect[effectLevel], i-1, v.MagicWeaponAction) end modelComponentData.modelComponent:SetRenderModel(modelComponentData.modelComponent.transform, modelComponentData.sceneTrans, modelComponentData.weaponNode, modelComponentData.lightObj, renderModelId) end function UIRender_Utility.RotateMagicWeapon(handle, rotateAngle) local modelComponentData = private.modelComponentDatasDic[handle] if modelComponentData.weaponNode then private.RotateTrans(modelComponentData.weaponNode, rotateAngle) end end --清理掉坐骑模型相关的,单独给坐骑创建非公用的 function UIRender_Utility.DisposeMagicWeaponOther(handle) local modelComponentData = private.modelComponentDatasDic[handle] if modelComponentData.weaponNode then UIModelUtils.DisposeMagicWeapon(modelComponentData.weaponNode) modelComponentData.modelComponent:DisposeModelObject(modelComponentData.weaponNode) modelComponentData.weaponNode = nil end end function UIRender_Utility.TryGetModelRoot(handle) local modelComponentData = private.modelComponentDatasDic[handle] if modelComponentData then return modelComponentData.modelRoot end return nil end --region ---------------------------------- 神兽3D模型相关-------------------------------------------- local FORMATION_LIGHT_PATH = ConstAssetPathConfig.FORMATION_LIGHT_PATH -- 神兽布阵界面模型 function UIRender_Utility.LoadGodBeastFormationModel(handle, godBeastID, posArr, posRot) local modelComponentData = private.modelComponentDatasDic[handle] local modelComponent = modelComponentData.modelComponent local modelParentRoot = modelComponentData.HeroParent if not modelComponentData["lightObj"] then local lightObj = modelComponent:CreateModelObject(FORMATION_LIGHT_PATH, modelComponentData.modelRoot) modelComponentData["lightObj"] = lightObj end local godBeastData = DataSheetManager.GodBeastData:GetDataByID(godBeastID) local godBeastModelData = DataSheetManager.MonsterModelData:GetDataByID(godBeastData.GodBeastModelID) local modelPath, modelScale= godBeastModelData.Path, godBeastData.FormationModelScale local emptyObj = UIRender_Utility.CreateExtraEmptObj(handle, modelParentRoot, posArr[1], posArr[2], posArr[3], posRot) local renderEntity = UIRender_Utility.CreateRenderEntity( emptyObj.transform, modelPath, godBeastData.FormationModelScale, DEFAULT_ANIMATOR_CONTROLLER_PATH, true ) modelComponent:AddEntity(renderEntity) renderEntity:ReplaceAnimation(DEAFULT_IDLE_ANIMATION_CLIP_NAME, godBeastData.ModelIdleAnim) end -- 养成模型加载 function UIRender_Utility.LoadDevelop3DModel(handle, modelPath, modelPreviewLight, posArr, scaleVal, rotVal, groundScale, showEffectPath, idleAnimationClip) local modelComponentData = private.modelComponentDatasDic[handle] -- 卸载模型 UIRender_Utility.DisposePlayerModel(handle) -- 加载模型 local modelRoot = modelComponentData.modelRoot -- 重置旋转 modelComponentData["sceneTrans"]:SetLocalEulerAngles(0, 0, 0) modelComponentData["modelRoot"]:SetLocalEulerAngles(0, 0, 0) -- 设置神兽对应的台子 if groundScale then modelComponentData["sceneBackgroundTrans"]:SetLocalScale(groundScale, groundScale, groundScale) end local renderEntity if idleAnimationClip then renderEntity = private.CreateEntityModel(handle, modelPath, nil, modelPreviewLight, scaleVal, idleAnimationClip) else renderEntity = private.CreateEntityModel(handle, modelPath, UIRender_Utility.GetAnimationCtlPath(modelPath), modelPreviewLight, scaleVal) end if showEffectPath then modelComponentData.renderEffectId = UIRender_Utility.PlayPsEffect(handle, showEffectPath) end -- 设置模型和台子整体缩放 modelComponentData["modelRoot"]:SetLocalEulerAngles(0, rotVal or 0, 0) modelComponentData["modelRoot"]:SetLocalPosition(posArr[1], posArr[2], posArr[3]) end --endregion function private.GetEditorCustomModelPath() local customCfgFilePath = "EditorModelConfig.json" if LuaExt.FileExists(customCfgFilePath) then local content = LuaExt.FileReadText(customCfgFilePath) local cfg = JSON.decode(content) local timelinePath = cfg["EditorCustomTimelinePath"] local heroPath = cfg["EditorCustomHeroPath"] local scenePath = cfg["EditorCustomHeroScenePath"] local lightPath = cfg["EditorCustomHeroLightPath"] local weapon1Path = cfg["EditorCustomHeroWeapon1Path"] local weapon1Slot = cfg["EditorCustomHeroWeapon1Slot"] local weapon2Path = cfg["EditorCustomHeroWeapon2Path"] local weapon2Slot = cfg["EditorCustomHeroWeapon2Slot"] return timelinePath, heroPath, scenePath, lightPath, weapon1Path, weapon1Slot, weapon2Path, weapon2Slot end end function UIRender_Utility.LoadEntityArrayModel(handle, modelPath, modelLight, posArr, scaleVal, rotVal, idleAnimationClip, ctrlPath) local modelComponentData = private.modelComponentDatasDic[handle] local lightObj = modelComponentData.lightObj if lightObj == nil and not string.isNilOrEmpty(modelLight) then local lightObj = modelComponentData.modelComponent:CreateModelObject(modelLight, modelComponentData.modelRoot) modelComponentData["lightObj"] = lightObj end -- 重置旋转 modelComponentData["sceneTrans"]:SetLocalEulerAngles(0, 0, 0) modelComponentData["modelRoot"]:SetLocalEulerAngles(0, 0, 0) local renderEntity if idleAnimationClip then renderEntity = private.CreateEntityModel(handle, modelPath, nil, nil, scaleVal, idleAnimationClip) else renderEntity = private.CreateEntityModel(handle, modelPath, ctrlPath or UIRender_Utility.GetAnimationCtlPath(modelPath), nil, scaleVal) end if not modelComponentData.renderEntityList then modelComponentData.renderEntityList = {} end if posArr then renderEntity.Transform:SetLocalPosition(posArr[1], posArr[2], posArr[3]) else renderEntity.Transform:SetLocalPosition(0, 0, 0) end renderEntity.Transform:SetLocalEulerAngles(0, rotVal or 0, 0) table.insert(modelComponentData.renderEntityList, renderEntity) end function UIRender_Utility.RemoveEntityWeapon(handle) local modelComponentData = private.modelComponentDatasDic[handle] if modelComponentData then local renderEntity = modelComponentData.renderEntity --先移除武器 renderEntity:SetEquipAndWeaponVisible(false) renderEntity:RemoveAllWeapon() end end function UIRender_Utility.ChangeEntityWeapon(handle, weaponId, weaponAppearanceId, magicWeaponLevel, isMagicWeaponActive, isPreviewWeaponModel, isHomeModel) local modelComponentData = private.modelComponentDatasDic[handle] if modelComponentData then local renderEntity = modelComponentData.renderEntity --先移除武器 renderEntity:SetEquipAndWeaponVisible(false) renderEntity:RemoveAllWeapon() if weaponAppearanceId > 0 then UIRender_Utility.LoadMagicWeapon(weaponId, weaponAppearanceId, magicWeaponLevel, isMagicWeaponActive, renderEntity, isPreviewWeaponModel, isHomeModel) else UIRender_Utility.LoadMagicWeapon(weaponId, weaponId, 0, true, renderEntity, isPreviewWeaponModel, isHomeModel) -- 神兵ID与武将ID保持一致 end end end --region 铸魂天命 --指定Entity加载铸魂天命 function UIRender_Utility.LoadWeaponSoulByEntity(handle, renderEntity, weaponSoulSkill) local haloParent = renderEntity:GetActorSlotNode(0) UIRender_Utility.LoadWeaponSoul(handle, weaponSoulSkill, haloParent) end --加载角色铸魂天命 function UIRender_Utility.LoadPlayerWeaponSoul(handle, weaponSoulSkill) local modelComponentData = private.modelComponentDatasDic[handle] local haloParent if modelComponentData.driverEntity then haloParent = modelComponentData.driverEntity:GetActorSlotNode(0) else haloParent = modelComponentData.renderEntity:GetActorSlotNode(0) end UIRender_Utility.LoadWeaponSoul(handle, weaponSoulSkill, haloParent) end function UIRender_Utility.SetModelDye(handle, appearanceId, partList, mode) local modelComponentData = private.modelComponentDatasDic[handle] if modelComponentData then UIRender_Utility.SetRenderEntityDye(modelComponentData.renderEntity, appearanceId, partList, mode) end end --设置染色 --mode:0=PVP模 1=战斗模 2=展示模 function UIRender_Utility.SetRenderEntityDye(renderEntity, appearanceId, partList, mode) CTL.DyeAppearance.SetModelDye(renderEntity, appearanceId, partList, mode) end function UIRender_Utility.LoadWeaponSoul(handle, weaponSoulSkill, haloParent) local modelComponentData = private.modelComponentDatasDic[handle] if not modelComponentData then return end if not CTL.HotFix.CanAssetLoad(WEAPON_HALO_PATH) then return end local weaponHaloObj = modelComponentData.modelComponent:CreateModelObject(WEAPON_HALO_PATH, haloParent) modelComponentData.modelWeaponSoulObj = weaponHaloObj weaponHaloObj:SetLocalPosition(0, 0, 0) if not modelComponentData.weaponSoulEffectIDs then modelComponentData.weaponSoulEffectIDs = {} end local plateParent = weaponHaloObj.transform:Find("Plate") local haloPlatEffectId = AuxUtil.PlayPsEffect(WEAPON_HALO_WHEEL_PATH, plateParent, LuaConst.Layer.Character) table.insert(modelComponentData.weaponSoulEffectIDs, haloPlatEffectId) if weaponSoulSkill then local lightBallParent = weaponHaloObj.transform:Find("LightBall") local activeCount = 0 for i, skillLv in ipairs(weaponSoulSkill) do if skillLv > 0 then activeCount = activeCount + 1 local cfg = DataSheetManager.MagicWeaponForgeSoulEffect:GetDataByMagicWeaponForgeSoulSkillLevel(skillLv) local effectId = AuxUtil.PlayPsEffect(cfg.SkillEffect, lightBallParent:GetChild(activeCount-1), LuaConst.Layer.Character) table.insert(modelComponentData.weaponSoulEffectIDs, effectId) end end local pos = WeaponHaloBallPos[activeCount] for i = 1, activeCount do lightBallParent:GetChild(i-1):SetLocalPosition(pos[i][1], pos[i][2], 0) end end end function UIRender_Utility.DisposeWeaponSoul(handle) local modelComponentData = private.modelComponentDatasDic[handle] if modelComponentData.weaponSoulEffectIDs then for _, id in ipairs(modelComponentData.weaponSoulEffectIDs) do AuxUtil.StopPsEffect(id) end modelComponentData.weaponSoulEffectIDs = nil end if modelComponentData.modelWeaponSoulObj then modelComponentData.modelComponent:DisposeModelObject(modelComponentData.modelWeaponSoulObj) modelComponentData.modelWeaponSoulObj = nil end end --endregion return UIRender_Utility