Started make greybox for main location
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
|
||||
public sealed class FirstPersonCameraController : NetworkBehaviour, IPlayerSystem
|
||||
{
|
||||
[SerializeField, Range(1f, 89f)] private float verticalLookLimit = 80f;
|
||||
|
||||
private Camera playerCamera;
|
||||
private AudioListener audioListener;
|
||||
private MeshRenderer playerRenderer;
|
||||
private float pitch;
|
||||
private bool isInitialized;
|
||||
|
||||
public void Initialize(PlayerFacade facade)
|
||||
{
|
||||
playerCamera = GetComponentInChildren<Camera>(true);
|
||||
audioListener = playerCamera != null ? playerCamera.GetComponent<AudioListener>() : null;
|
||||
playerRenderer = GetComponentInChildren<MeshRenderer>();
|
||||
isInitialized = playerCamera != null;
|
||||
|
||||
if (!isInitialized)
|
||||
return;
|
||||
|
||||
bool isLocalPlayer = IsOwner;
|
||||
playerCamera.gameObject.SetActive(isLocalPlayer);
|
||||
|
||||
if (!isLocalPlayer)
|
||||
return;
|
||||
|
||||
if (playerRenderer != null)
|
||||
playerRenderer.enabled = false;
|
||||
|
||||
foreach (Camera camera in FindObjectsByType<Camera>(FindObjectsSortMode.None))
|
||||
{
|
||||
if (camera != playerCamera)
|
||||
camera.enabled = false;
|
||||
}
|
||||
|
||||
if (audioListener != null)
|
||||
audioListener.enabled = true;
|
||||
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = false;
|
||||
}
|
||||
|
||||
public void ApplyPitch(float pitchDelta)
|
||||
{
|
||||
if (!isInitialized || !IsOwner)
|
||||
return;
|
||||
|
||||
pitch = Mathf.Clamp(pitch - pitchDelta, -verticalLookLimit, verticalLookLimit);
|
||||
playerCamera.transform.localRotation = Quaternion.Euler(pitch, 0f, 0f);
|
||||
}
|
||||
|
||||
public override void OnNetworkDespawn()
|
||||
{
|
||||
if (IsOwner)
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user