修改主相机渲染

main
刘涛 2024-01-10 18:11:17 +08:00
parent 92b5472093
commit c9d54380dd
5 changed files with 157 additions and 9 deletions

View File

@ -86,6 +86,22 @@ public partial class SROptions
{
Application.targetFrameRate = _targetFrameRate;
}
[Category("性能")]
public int Resolution
{
get { return _resolution; }
set
{
_resolution = value;
}
}
private int _resolution = 0;
[Category("性能")]
public void SetResoulution()
{
PerformanceManager.SetResolution(_resolution);
}
[Category("性能")]
public bool EnableEffect

View File

@ -0,0 +1,17 @@
using System;
using UnityEngine;
namespace Gameplay.Performance.Cmp
{
public class CmpUIMainScene : MonoBehaviour
{
public static CmpUIMainScene instance;
private void Awake()
{
instance = this;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: aa34d81c7c7d4f368066f6277b67271d
timeCreated: 1704878111

View File

@ -1,9 +1,11 @@
using Cysharp.Threading.Tasks;
using Framework;
using Gameplay.Performance.Cmp;
using MagicaCloth2;
using PhxhSDK;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using UnityEngine.UI;
using Constants = Framework.Constants;
namespace Gameplay.Performance
@ -128,6 +130,7 @@ namespace Gameplay.Performance
if (resolution <= 0)
{
// don't change current resolution
_SetRsoulution(Screen.width, Screen.height);
return;
}
@ -140,7 +143,7 @@ namespace Gameplay.Performance
{
var scale = (float)resolution / nowWidth;
var newHeight = (int)(nowHeight * scale);
Screen.SetResolution(resolution, newHeight, Screen.fullScreenMode);
_SetRsoulution(resolution, newHeight);
}
}
else
@ -150,11 +153,36 @@ namespace Gameplay.Performance
{
var scale = (float)resolution / nowHeight;
var newWidth = (int)(nowWidth * scale);
Screen.SetResolution(newWidth, resolution, Screen.fullScreenMode);
_SetRsoulution(newWidth, resolution);
}
}
}
private static void _SetRsoulution(int width, int height)
{
// Screen.SetResolution(width, height, Screen.fullScreenMode);
_SetCameraRenderSize(CameraManager.Instance.MainCamera, width, height);
// _SetCameraRenderSize(CameraManager.Instance.SkillCamera, width, height);
}
private static void _SetCameraRenderSize(Camera rawCamera, int width, int height)
{
if (rawCamera == null)
{
DebugUtil.LogError("Camera is null");
return;
}
if (rawCamera.targetTexture != null)
{
// 释放旧的 RenderTexture
RenderTexture.ReleaseTemporary(rawCamera.targetTexture);
}
var renderTexture = RenderTexturePool.Instance.Create("TeamPreviewNode", width,
height, RenderTexturePool.DEFAULT_DEPTH);
rawCamera.targetTexture = renderTexture;
CmpUIMainScene.instance.GetComponent<RawImage>().texture = renderTexture;
}
private void _Init()
{
data = new PerformanceData();

View File

@ -301,6 +301,91 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &18463223
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 18463224}
- component: {fileID: 18463226}
- component: {fileID: 18463225}
- component: {fileID: 18463227}
m_Layer: 5
m_Name: MainScene
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &18463224
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 18463223}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1324946120}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &18463225
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 18463223}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1344c3c82d62a2a41a3576d8abb8e3ea, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 0
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 0
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Texture: {fileID: 0}
m_UVRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
--- !u!222 &18463226
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 18463223}
m_CullTransparentMesh: 0
--- !u!114 &18463227
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 18463223}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: aa34d81c7c7d4f368066f6277b67271d, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &59095781
GameObject:
m_ObjectHideFlags: 0
@ -1330,7 +1415,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 150.59998, y: 74.1}
m_AnchoredPosition: {x: 150.6001, y: 74.1001}
m_SizeDelta: {x: 300, y: 150}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &440271633
@ -5161,6 +5246,7 @@ RectTransform:
m_LocalScale: {x: 0, y: 0, z: 0}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 18463224}
- {fileID: 948530776}
m_Father: {fileID: 957804731}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -5203,7 +5289,7 @@ MonoBehaviour:
m_RenderShadows: 0
m_RequiresDepthTextureOption: 0
m_RequiresOpaqueTextureOption: 2
m_CameraType: 1
m_CameraType: 0
m_Cameras:
- {fileID: 110927571}
m_RendererIndex: -1
@ -6619,9 +6705,7 @@ MonoBehaviour:
m_RequiresDepthTextureOption: 2
m_RequiresOpaqueTextureOption: 2
m_CameraType: 0
m_Cameras:
- {fileID: 1338416371}
- {fileID: 110927571}
m_Cameras: []
m_RendererIndex: -1
m_VolumeLayerMask:
serializedVersion: 2
@ -8425,8 +8509,8 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
useFullCharacters: 0
selfInvincible: 0
enemyInvincible: 0
selfInvincible: 1
enemyInvincible: 1
--- !u!1 &2104671788
GameObject:
m_ObjectHideFlags: 0