1
0
mirror of https://github.com/xiaopeng12138/MaiDXR.git synced 2024-12-18 11:55:52 +01:00
MaiDXR/Assets/Scripts/Configs/NoneVRSettingManager.cs

150 lines
4.7 KiB
C#
Raw Normal View History

2022-08-17 18:58:08 +02:00
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using Newtonsoft.Json.Linq;
2022-08-17 18:58:08 +02:00
public class NoneVRSettingManager : MonoBehaviour
{
2022-08-17 23:15:59 +02:00
public GameObject NVRCameraObj;
public Camera NVRCamera;
public Transform NVRCameraTargetFP;
public Transform NVRCameraTargetTP;
public CameraSmooth CameraSmooth;
2022-08-17 18:58:08 +02:00
private TMP_Dropdown Dropdown;
private Slider Slider;
void Start()
{
Dropdown = GetComponent<TMP_Dropdown>();
Slider = GetComponent<Slider>();
switch (gameObject.name)
{
case "NVRModeDropdown":
2022-08-17 23:15:59 +02:00
GetNVRMode();
2022-08-17 18:58:08 +02:00
break;
case "NVRFOV":
2022-08-17 23:15:59 +02:00
GetNVRFOV();
2022-08-17 18:58:08 +02:00
break;
case "NVRFPSDropdown":
2022-08-17 23:15:59 +02:00
GetNVRFPS();
break;
case "TPCameraCube":
GetTPCamTransform();
2022-08-17 18:58:08 +02:00
break;
2022-08-27 02:19:29 +02:00
case "NVRCamera":
GetNVRSmoothSpeed();
break;
2022-08-17 18:58:08 +02:00
}
}
public void GetNVRMode()
{
if (Dropdown == null) return;
2022-08-17 18:58:08 +02:00
if (JsonConfig.HasKey("NVRMode"))
Dropdown.value = JsonConfig.GetInt("NVRMode");
2022-08-27 02:19:29 +02:00
SetNVRMode();
}
void GetNVRSmoothSpeed()
{
2022-08-27 00:17:18 +02:00
if (JsonConfig.HasKey("NVRCameraSmooth"))
2022-08-27 00:21:23 +02:00
CameraSmooth.smoothSpeed = (float)JsonConfig.GetDouble("NVRCameraSmooth");
2022-08-27 02:19:29 +02:00
SetNVRSmoothSpeed();
2022-08-17 18:58:08 +02:00
}
public void GetNVRFOV()
{
if (JsonConfig.HasKey("NVRFOV"))
Slider.value = (float)JsonConfig.GetDouble("NVRFOV");
2022-08-17 23:15:59 +02:00
SetNVRFOV(Slider.value);
2022-08-17 18:58:08 +02:00
}
2022-08-17 23:15:59 +02:00
public void GetNVRFPS()
2022-08-17 18:58:08 +02:00
{
QualitySettings.vSyncCount = 0;
2022-08-17 18:58:08 +02:00
if (JsonConfig.HasKey("NVRFPS"))
Dropdown.value = JsonConfig.GetInt("NVRFPS");
2022-08-17 23:15:59 +02:00
SetNVRFPS();
}
public void GetTPCamTransform()
{
if (JsonConfig.HasKey("TPCamPosition"))
gameObject.transform.position = JsonConfig.GetVector3("TPCamPosition");
if (JsonConfig.HasKey("TPCamRotation"))
gameObject.transform.rotation = JsonConfig.GetQuaternion("TPCamRotation");
SetTPCamTransform();
2022-08-17 18:58:08 +02:00
}
public void SetNVRMode()
{
if (NVRCameraObj == null || NVRCamera == null || CameraSmooth == null || NVRCameraTargetFP == null || NVRCameraTargetTP == null)
return;
2022-08-17 18:58:08 +02:00
switch (Dropdown.value)
{
case 0:
if (NVRCameraObj.activeSelf)
NVRCameraObj.SetActive(false);
2022-08-17 18:58:08 +02:00
break;
case 1:
if (!NVRCameraObj.activeSelf)
NVRCameraObj.SetActive(true);
2022-08-17 23:15:59 +02:00
CameraSmooth.target = NVRCameraTargetFP;
2022-08-27 02:19:29 +02:00
NVRCamera.cullingMask |= 1 << LayerMask.NameToLayer("TPSBlock"); // Enable TPBlock Layer Mask
NVRCamera.cullingMask &= ~(1 << LayerMask.NameToLayer("FPSBlock")); // Disable FPBlock Layer Mask
2022-08-17 18:58:08 +02:00
break;
case 2:
if (!NVRCameraObj.activeSelf)
NVRCameraObj.SetActive(true);
2022-08-17 23:15:59 +02:00
CameraSmooth.target = NVRCameraTargetTP;
2022-08-27 02:19:29 +02:00
NVRCamera.cullingMask |= 1 << LayerMask.NameToLayer("FPSBlock"); // Enable FPBlock Layer Mask
NVRCamera.cullingMask &= ~(1 << LayerMask.NameToLayer("TPSBlock")); // Disable TPBlock Layer Mask
2022-08-17 18:58:08 +02:00
break;
}
JsonConfig.SetInt("NVRMode", Dropdown.value);
2022-08-27 02:19:29 +02:00
}
void SetNVRSmoothSpeed()
{
2022-08-27 00:24:28 +02:00
JsonConfig.SetDouble("NVRCameraSmooth", CameraSmooth.smoothSpeed);
2022-08-17 18:58:08 +02:00
}
2022-08-17 23:15:59 +02:00
public void SetNVRFOV(float fov)
2022-08-17 18:58:08 +02:00
{
2022-08-17 23:15:59 +02:00
NVRCamera.fieldOfView = fov;
JsonConfig.SetDouble("NVRFOV", fov);
2022-08-17 18:58:08 +02:00
}
2022-08-17 23:15:59 +02:00
public void SetNVRFPS()
2022-08-17 18:58:08 +02:00
{
switch (Dropdown.value)
{
case 0:
Application.targetFrameRate = 15;
2022-08-17 18:58:08 +02:00
break;
case 1:
Application.targetFrameRate = 30;
2022-08-17 18:58:08 +02:00
break;
case 2:
Application.targetFrameRate = 45;
2022-08-17 18:58:08 +02:00
break;
case 3:
Application.targetFrameRate = 60;
2022-08-17 18:58:08 +02:00
break;
case 4:
2022-08-27 02:19:29 +02:00
Application.targetFrameRate = 72;
2022-08-17 18:58:08 +02:00
break;
case 5:
2022-08-27 02:19:29 +02:00
Application.targetFrameRate = 90;
2022-08-17 18:58:08 +02:00
break;
case 6:
2022-08-27 02:19:29 +02:00
Application.targetFrameRate = 120;
break;
case 7:
Application.targetFrameRate = 144;
2022-08-17 18:58:08 +02:00
break;
}
JsonConfig.SetInt("NVRFPS", Dropdown.value);
}
2022-08-17 23:15:59 +02:00
public void SetTPCamTransform()
{
JsonConfig.SetVector3("TPCamPosition", gameObject.transform.position);
JsonConfig.SetQuaternion("TPCamRotation", gameObject.transform.rotation);
}
2022-08-17 18:58:08 +02:00
}