quantum-space-buddies/QSB/PoolSync/CustomNomaiRemoteCamera.cs

78 lines
1.9 KiB
C#
Raw Normal View History

2021-03-07 10:00:58 +00:00
using UnityEngine;
2021-03-06 23:59:44 +00:00
2022-03-03 03:46:33 +00:00
namespace QSB.PoolSync;
2023-07-28 18:30:57 +00:00
public class CustomNomaiRemoteCamera : MonoBehaviour
2021-03-06 23:59:44 +00:00
{
2023-06-25 14:07:48 +00:00
public OWCamera _camera;
2022-03-03 03:46:33 +00:00
private AudioListener _audioListener;
private NomaiViewerImageEffect _viewerImageEffect;
private CustomNomaiRemoteCameraPlatform _owningPlatform;
private CustomNomaiRemoteCameraPlatform _controllingPlatform;
private OWCamera _controllingCamera;
2021-03-06 23:59:44 +00:00
2022-03-03 03:46:33 +00:00
private void Awake()
{
_camera = GetComponent<OWCamera>();
_audioListener = GetComponent<AudioListener>();
_viewerImageEffect = _camera.GetComponent<NomaiViewerImageEffect>();
_owningPlatform = GetComponentInParent<CustomNomaiRemoteCameraPlatform>();
enabled = false;
}
2021-03-06 23:59:44 +00:00
2022-03-03 03:46:33 +00:00
private void OnEnable()
{
_camera.enabled = true;
_audioListener.enabled = true;
GlobalMessenger<OWCamera>.FireEvent("SwitchActiveCamera", _camera);
}
2022-03-03 03:46:33 +00:00
private void OnDisable()
{
_camera.enabled = false;
_audioListener.enabled = false;
}
2021-03-06 23:59:44 +00:00
2022-03-03 03:46:33 +00:00
private void LateUpdate()
{
if (_owningPlatform == null)
{
2022-03-03 03:46:33 +00:00
_owningPlatform = GetComponentInParent<CustomNomaiRemoteCameraPlatform>();
}
2022-03-03 03:46:33 +00:00
if (_owningPlatform != null && _controllingPlatform != null)
{
2022-03-03 03:46:33 +00:00
transform.position = CustomNomaiRemoteCameraPlatform.TransformPoint(_controllingCamera.transform.position, _controllingPlatform, _owningPlatform);
transform.rotation = CustomNomaiRemoteCameraPlatform.TransformRotation(_controllingCamera.transform.rotation, _controllingPlatform, _owningPlatform);
_camera.fieldOfView = _controllingCamera.fieldOfView;
}
2022-03-03 03:46:33 +00:00
else
{
enabled = false;
}
2022-03-03 03:46:33 +00:00
}
2022-03-03 03:46:33 +00:00
public void Activate(CustomNomaiRemoteCameraPlatform controllingPlatform, OWCamera viewer)
{
_controllingPlatform = controllingPlatform;
_controllingCamera = viewer;
enabled = true;
}
2022-03-03 03:46:33 +00:00
public void Deactivate()
{
_controllingPlatform = null;
enabled = false;
}
public bool IsActive()
=> enabled;
public void SetImageEffectFade(float fade)
{
if (_viewerImageEffect != null)
2021-03-06 23:59:44 +00:00
{
2022-03-03 03:46:33 +00:00
_viewerImageEffect.SetFade(fade);
2021-03-06 23:59:44 +00:00
}
}
}