local UIRender_ModelComponentHelper = {} local private = { modelDataHandleActiveType = {} } local v3_zero = Vector3.New(0, 0, 0) function UIRender_ModelComponentHelper.DisposeModelComponentData(handle) private.modelDataHandleActiveType[handle] = nil end function UIRender_ModelComponentHelper.HasModelComponent(handle) return private.modelDataHandleActiveType[handle] ~= nil end function UIRender_ModelComponentHelper.SetLayerActiveByType(handle, modelComponentData, layerActiveType) private.modelDataHandleActiveType[handle] = layerActiveType modelComponentData["layerActiveType"] = layerActiveType local modelComponent = modelComponentData.modelComponent if GameAppInfo.IsVersionGreaterThan19000() then if layerActiveType == UTL.UIRender.LayerActiveType.UI2DBGCommonShow then modelComponentData["cameraParent"] = modelComponentData.sceneTrans:Find("CameraParent") elseif layerActiveType == UTL.UIRender.LayerActiveType.HeroSelect then modelComponentData["cameraParent"] = UTL.UIRender.FindInChildren(modelComponentData.sceneTrans, "CoreCamera") modelComponentData["camera"] = modelComponentData.cameraParent:GetComponent(typeof(UnityEngine.Camera)) UIUtils.SetActive(modelComponentData.cameraParent, false) elseif layerActiveType == UTL.UIRender.LayerActiveType.CountryOfficial then modelComponentData["cameraEnterPos"] = modelComponentData.sceneTrans:Find("location"):Find("CameraEnterPos") end return end -- 考虑到兼容性 这里暂时都使用闭包操作 if layerActiveType == UTL.UIRender.LayerActiveType.HeroSelect then modelComponentData["cameraParent"] = UTL.UIRender.FindInChildren(modelComponentData.sceneTrans, "CoreCamera") modelComponentData["camera"] = modelComponentData.cameraParent:GetComponent(typeof(UnityEngine.Camera)) modelComponent.onLayerActiveAction = function(active) private.ModelHeroSelectLayerActive(modelComponentData, active) end elseif layerActiveType == UTL.UIRender.LayerActiveType.HeroShow then modelComponent.onLayerActiveAction = function(active) private.ModelHeroShowLayerActive(modelComponentData, active) end elseif layerActiveType == UTL.UIRender.LayerActiveType.UI2DBGCommonShow then modelComponentData["cameraParent"] = modelComponentData.sceneTrans:Find("CameraParent") modelComponent.onLayerActiveAction = function(active) private.Model2DBGLayerActive(modelComponentData, active) end elseif layerActiveType == UTL.UIRender.LayerActiveType.HeroFormation then modelComponent.onLayerActiveAction = function(active) private.ModelHeroFormationLayerActive(modelComponentData, active) end elseif layerActiveType == UTL.UIRender.LayerActiveType.BossChallenge then modelComponent.onLayerActiveAction = function(active) private.ModelBossChallengeLayerActive(modelComponentData, active) end elseif layerActiveType == UTL.UIRender.LayerActiveType.HorseShow then modelComponent.onLayerActiveAction = function(active) private.ModelHorseShowLayerActive(modelComponentData, active) end elseif layerActiveType == UTL.UIRender.LayerActiveType.RTShow then modelComponent.onLayerActiveAction = function(active) private.ModelCommonLayerActive(modelComponentData, active) end elseif layerActiveType == UTL.UIRender.LayerActiveType.CountryOfficial then modelComponentData["cameraEnterPos"] = modelComponentData.sceneTrans:Find("location/CameraEnterPos") modelComponent.onLayerActiveAction = function(active) private.ModelCountryOfficialActive(modelComponentData, active) end else modelComponent.onLayerActiveAction = function(active) private.ModelCommonLayerActive(modelComponentData, active) end end end function UIRender_ModelComponentHelper.OnModelComponentLayerActiveType(modelDataHanle, modelComponentData, active) local activeType = private.modelDataHandleActiveType[modelDataHanle] if not activeType then return end if activeType == UTL.UIRender.LayerActiveType.HeroSelect then private.ModelHeroSelectLayerActive(modelComponentData, active) elseif activeType == UTL.UIRender.LayerActiveType.HeroShow then private.ModelHeroShowLayerActive(modelComponentData, active) elseif activeType == UTL.UIRender.LayerActiveType.UI2DBGCommonShow then private.Model2DBGLayerActive(modelComponentData, active) elseif activeType == UTL.UIRender.LayerActiveType.HeroFormation then private.ModelHeroFormationLayerActive(modelComponentData, active) elseif activeType == UTL.UIRender.LayerActiveType.BossChallenge then private.ModelBossChallengeLayerActive(modelComponentData, active) elseif activeType == UTL.UIRender.LayerActiveType.HorseShow then private.ModelHorseShowLayerActive(modelComponentData, active) elseif activeType == UTL.UIRender.LayerActiveType.RTShow then private.ModelCommonLayerActive(modelComponentData, active) elseif activeType == UTL.UIRender.LayerActiveType.CountryOfficial then private.ModelCountryOfficialActive(modelComponentData, active) else private.ModelCommonLayerActive(modelComponentData, active) end end -- 以下为各个类型所对应的 LayerActive function private.ModelHeroSelectLayerActive(modelComponentData, active) UIModelUtils.ActiveMainLight(not active) if active then local coreCameraPos = Vector3.New(modelComponentData.cameraParent:GetLocalPosition()) local coreCameraRot = modelComponentData.cameraParent.localRotation if UIUtils.GetScreenResolutionRatio() == 1 then UIModelUtils.StartUIShowSystem(modelComponentData.cameraParent.parent, coreCameraPos, coreCameraRot, modelComponentData.camera.fieldOfView*1.15) else UIModelUtils.StartUIShowSystem(modelComponentData.cameraParent.parent, coreCameraPos, coreCameraRot, modelComponentData.camera.fieldOfView) end UIUtils.ChangLodSettingTypeToShow(10) else UIUtils.ChangLodSettingTypeToGame() UIModelUtils.EndUIShowSystem() end end -- 以下为各个类型所对应的 LayerActive function private.ModelHeroShowLayerActive(modelComponentData, active) if active then local modelRoot = modelComponentData.modelRoot if modelRoot then UIModelUtils.SetVirtualCamera(LuaConst.VirtualCameraType.UIShowVirtualCamera, modelRoot, modelComponentData.blendTime or 0) end else if LogicUpdateManager._curEntity and LogicUpdateManager._curEntity.ExpEntity then UIModelUtils.SetCameraTargetEntity(LogicUpdateManager._curEntity.ExpEntity.RenderEntity) end end private.ModelCommonLayerActive(modelComponentData, active) end function private.Model2DBGLayerActive(modelComponentData, active) if active then local cameraParent = modelComponentData.cameraParent if cameraParent then UIModelUtils.StartUIShowSystem(cameraParent, v3_zero, v3_zero, 35) end end private.ModelCommonLayerActive(modelComponentData, active) end function private.ModelHeroFormationLayerActive(modelComponentData, active) if active then local modelRoot = modelComponentData.modelRoot if modelRoot then UIModelUtils.SetVirtualCamera(LuaConst.VirtualCameraType.UIShowForFormationVirtualCamera, modelRoot, modelComponentData.blendTime or 0) end else if LogicUpdateManager._curEntity and LogicUpdateManager._curEntity.ExpEntity then UIModelUtils.SetCameraTargetEntity(LogicUpdateManager._curEntity.ExpEntity.RenderEntity) end end private.ModelCommonLayerActive(modelComponentData, active) end function private.ModelBossChallengeLayerActive(modelComponentData, active) if active then local modelRoot = modelComponentData.modelRoot if modelRoot then UIModelUtils.SetVirtualCamera(LuaConst.VirtualCameraType.UIBossChallengeVirtualCamera, modelRoot) end else if LogicUpdateManager._curEntity and LogicUpdateManager._curEntity.ExpEntity then UIModelUtils.SetCameraTargetEntity(LogicUpdateManager._curEntity.ExpEntity.RenderEntity) end end UIModelUtils.SetLightForBattleModel(active) private.ModelCommonLayerActive(modelComponentData, active) end function private.ModelHorseShowLayerActive(modelComponentData, active) UIModelUtils.ActiveMainLight(not active) if active then UIModelUtils.OverrideShaderSettingLodMax() if not modelComponentData.HorseCamTarget then local offsetX = 0 if UIUtils.GetScreenResolutionRatio() ~= LuaConst.ScreenResolutionRatio.RatioPad4_3 then local w, h = UIUtils.GetScreenSize(1,1) offsetX = w/h * 0.51 - 0.9 end modelComponentData.HorseCamTarget = AuxUtil.GetEmptyObject(null, "HorseCamTarget") modelComponentData.HorseCamTarget.transform:SetPosition(1600+offsetX, 0, 1600) modelComponentData.HorseCamTarget.transform:SetLocalEulerAngles(0, 0, 0) end UIModelUtils.SetVirtualCamera(LuaConst.VirtualCameraType.UIiWarHorseVirtualCamera, modelComponentData.HorseCamTarget.transform, 0) else UIModelUtils.RecoverShaderSettingLevel() UIModelUtils.EndUIShowSystem() end local sceneTrans = modelComponentData.sceneTrans if sceneTrans then UIUtils.SetActive(sceneTrans, active) if active then UIModelUtils.PlaySceneParam(sceneTrans) else UIModelUtils.StopSceneParam(sceneTrans) end end end function private.ModelCountryOfficialActive(modelComponentData, active) if active then local mainTrans = AuxUtil.MainCameraTrans local cameraEnterPos = modelComponentData.cameraEnterPos UIModelUtils.StartUIShowSystem(mainTrans, v3_zero, cameraEnterPos.localRotation) mainTrans:SetPosition(cameraEnterPos:GetPosition()) CameraController.Instance:HandOutCameraControl() end private.ModelCommonLayerActive(modelComponentData, active) end function private.ModelCommonLayerActive(modelComponentData, active) UIModelUtils.ActiveMainLight(not active) if not active then if not modelComponentData.isBlend then UIModelUtils.EndUIShowSystem() end UIUtils.ChangLodSettingTypeToGame() else if modelComponentData.layerActiveType == UTL.UIRender.LayerActiveType.HorseShow then UIUtils.ChangLodSettingTypeToShow(20) else UIUtils.ChangLodSettingTypeToShow(10) end end local sceneTrans = modelComponentData.sceneTrans if sceneTrans then UIUtils.SetActive(sceneTrans, active) if active then UIModelUtils.PlaySceneParam(sceneTrans) else UIModelUtils.StopSceneParam(sceneTrans) end end local lightTrans = modelComponentData.lightObj if lightTrans then if GameAppInfo.IsVersionGreaterThan16000() then UIModelUtils.SetManualLightHelperActive(lightTrans, not active) end end end return UIRender_ModelComponentHelper