update new config system
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SpectatorManager : MonoBehaviour
|
||||
{
|
||||
@@ -14,47 +14,60 @@ public class SpectatorManager : MonoBehaviour
|
||||
{
|
||||
cameraSmooth = GetComponent<CameraSmooth>();
|
||||
SpectatorCam = GetComponent<Camera>();
|
||||
ConfigManager.onConfigChanged += ApplyConfig;
|
||||
ConfigManager.EnsureInitialization();
|
||||
ApplyConfig();
|
||||
var modeWidget = ConfigManager.GetConfigPanelWidget("SpectatorMode");
|
||||
var fovWidget = ConfigManager.GetConfigPanelWidget("SpectatorFOV");
|
||||
var fpsWidget = ConfigManager.GetConfigPanelWidget("SpectatorFPS");
|
||||
|
||||
|
||||
var modeDropdown = modeWidget.GetComponent<TMP_Dropdown>();
|
||||
var fovSlider = fovWidget.GetComponent<Slider>();
|
||||
var fpsDropdown = fpsWidget.GetComponent<TMP_Dropdown>();
|
||||
|
||||
modeDropdown.onValueChanged.AddListener((int value) => {
|
||||
if (SpectatorCam == null || cameraSmooth == null || SpectatorFPTarget == null || SpectatorTPTarget == null)
|
||||
return;
|
||||
switch (value)
|
||||
{
|
||||
case 0:
|
||||
if (gameObject.activeSelf)
|
||||
gameObject.SetActive(false);
|
||||
break;
|
||||
case 1:
|
||||
if (!gameObject.activeSelf)
|
||||
gameObject.SetActive(true);
|
||||
cameraSmooth.target = SpectatorFPTarget;
|
||||
cameraSmooth.smoothSpeed = (float)ConfigManager.config.SpectatorSmooth;
|
||||
SpectatorCam.cullingMask |= 1 << LayerMask.NameToLayer("TPBlock"); // Enable TPBlock Layer Mask
|
||||
SpectatorCam.cullingMask &= ~(1 << LayerMask.NameToLayer("FPBlock")); // Disable FPBlock Layer Mask
|
||||
break;
|
||||
case 2:
|
||||
if (!gameObject.activeSelf)
|
||||
gameObject.SetActive(true);
|
||||
cameraSmooth.target = SpectatorTPTarget;
|
||||
cameraSmooth.smoothSpeed = 1;
|
||||
SpectatorCam.cullingMask &= ~(1 << LayerMask.NameToLayer("TPBlock")); // Disable TPBlock Layer Mask
|
||||
SpectatorCam.cullingMask |= 1 << LayerMask.NameToLayer("FPBlock"); // Enable FPBlock Layer Mask
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
fovSlider.onValueChanged.AddListener((float value) => {
|
||||
SpectatorCam.fieldOfView = value;
|
||||
});
|
||||
|
||||
fpsDropdown.onValueChanged.AddListener((int value) => {
|
||||
var fpsString = Enum.GetName(typeof(CEnum.FPS), value);
|
||||
Application.targetFrameRate = int.Parse(fpsString.Remove(0, 3));
|
||||
});
|
||||
|
||||
modeDropdown.onValueChanged?.Invoke(modeDropdown.value);
|
||||
fovSlider.onValueChanged?.Invoke(fovSlider.value);
|
||||
fpsDropdown.onValueChanged?.Invoke(fpsDropdown.value);
|
||||
|
||||
ApplyTPCamTransform();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void ApplyConfig()
|
||||
{
|
||||
if (SpectatorCam == null || cameraSmooth == null || SpectatorFPTarget == null || SpectatorTPTarget == null)
|
||||
return;
|
||||
switch ((int)ConfigManager.config.SpectatorMode)
|
||||
{
|
||||
case 0:
|
||||
if (gameObject.activeSelf)
|
||||
gameObject.SetActive(false);
|
||||
break;
|
||||
case 1:
|
||||
if (!gameObject.activeSelf)
|
||||
gameObject.SetActive(true);
|
||||
cameraSmooth.target = SpectatorFPTarget;
|
||||
cameraSmooth.smoothSpeed = (float)ConfigManager.config.SpectatorSmooth;
|
||||
SpectatorCam.cullingMask |= 1 << LayerMask.NameToLayer("TPBlock"); // Enable TPBlock Layer Mask
|
||||
SpectatorCam.cullingMask &= ~(1 << LayerMask.NameToLayer("FPBlock")); // Disable FPBlock Layer Mask
|
||||
break;
|
||||
case 2:
|
||||
if (!gameObject.activeSelf)
|
||||
gameObject.SetActive(true);
|
||||
cameraSmooth.target = SpectatorTPTarget;
|
||||
cameraSmooth.smoothSpeed = 1;
|
||||
SpectatorCam.cullingMask &= ~(1 << LayerMask.NameToLayer("TPBlock")); // Disable TPBlock Layer Mask
|
||||
SpectatorCam.cullingMask |= 1 << LayerMask.NameToLayer("FPBlock"); // Enable FPBlock Layer Mask
|
||||
break;
|
||||
}
|
||||
|
||||
SpectatorCam.fieldOfView = (float)ConfigManager.config.SpectatorFOV;
|
||||
|
||||
string fpsString = Enum.GetName(typeof(Config.captureFPS), ConfigManager.config.CaptureFPS);
|
||||
Application.targetFrameRate = int.Parse(fpsString.Remove(0, 3));
|
||||
}
|
||||
void ApplyTPCamTransform()
|
||||
void ApplyTPCamTransform()
|
||||
{
|
||||
if (SpectatorTPTarget == null)
|
||||
return;
|
||||
@@ -65,7 +78,7 @@ public class SpectatorManager : MonoBehaviour
|
||||
ConfigManager.config.TPCamRotation[1],
|
||||
ConfigManager.config.TPCamRotation[2]);
|
||||
}
|
||||
public void SaveTransform()
|
||||
public void SaveTransform() // will be called from TPCameraCube
|
||||
{
|
||||
if (SpectatorTPTarget == null)
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user