using MMMaellon.LightSync; using UdonSharp; using UnityEngine; using VRC.SDKBase; using VRC.Udon; [UdonBehaviourSyncMode(BehaviourSyncMode.Manual)] public class CameraAnchor : UdonSharpBehaviour { [SerializeField] private float FOV = 60.0f; [SerializeField] private float NearClippingPlane = 0.3f; [SerializeField] private float FarClippingPlane = 1000.0f; [Space] [Tooltip("Changing the Z scale of this object will change the FOV of the attached camera.")] [SerializeField] private Transform CameraRoot; private Camera _AttachedCamera = null; void LateUpdate() { if (_AttachedCamera) { if (CameraRoot.childCount <= 0) { _AttachedCamera = null; } else { _AttachedCamera.fieldOfView = FOV * CameraRoot.transform.localScale.z; } } } public void AttachCamera(Camera CameraComponent) { _AttachedCamera = CameraComponent; _AttachedCamera.gameObject.SetActive(true); _AttachedCamera.transform.parent = CameraRoot; _AttachedCamera.fieldOfView = FOV; _AttachedCamera.nearClipPlane = NearClippingPlane; _AttachedCamera.farClipPlane = FarClippingPlane; _AttachedCamera.GetComponent().TeleportToLocalSpace(Vector3.zero, Quaternion.identity, true); } #if UNITY_EDITOR private void OnDrawGizmos() { Gizmos.DrawIcon(transform.position, "CameraAnchor", true); } #endif }