using System.Collections;
using System.Collections.Generic;
using Framework.Utils;
using Gameplay;
using PhxhSDK;
using Sirenix.OdinInspector;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public enum ECameraOperationType
{
[LabelText("固定机位")]
Fixed,
[LabelText("自由机位")]
Free,
}
///
/// 记录一个相机的机位
///
public class CameraStand : MonoBehaviour
{
private const string CAMERA_UNDO_NAME = "cameraStandTest";
[LabelText("是否正交")]
[SerializeField]
private bool _isOrthographic;
[ShowIf("_isOrthographic")]
[LabelText("正交size")]
[SerializeField]
private float _size;
[HideIf("_isOrthographic")]
[LabelText("FOV")]
[SerializeField]
private float _fov;
[LabelText("相机操作类型")]
[SerializeField]
private ECameraOperationType _cameraOperationType = ECameraOperationType.Fixed;
public float Fov { get { return _fov; } }
public Camera DefaultCamera => FrameWorkUtils.GetSceneRootComponent(gameObject.scene) ??
Camera.main ?? CameraManager.Instance.MainCamera;
[Button("测试机位")]
private void TestStand()
{
Apply();
}
public void Apply(Camera targetCamera = null)
{
targetCamera = targetCamera ? targetCamera : DefaultCamera;
#if UNITY_EDITOR
Undo.RecordObject(targetCamera.transform, CAMERA_UNDO_NAME);
Undo.RecordObject(targetCamera, CAMERA_UNDO_NAME);
#endif
var trans = transform;
targetCamera.transform.SetPositionAndRotation(trans.position, trans.rotation);
targetCamera.orthographic = _isOrthographic;
targetCamera.orthographicSize = _size > 0 ? _size : targetCamera.orthographicSize;
targetCamera.fieldOfView = _fov > 0 ? _fov : targetCamera.fieldOfView;
var cameraController = targetCamera.GetComponent();
if (cameraController is not null)
{
#if UNITY_EDITOR
Undo.RecordObject(cameraController, CAMERA_UNDO_NAME);
#endif
cameraController.enabled = _cameraOperationType != ECameraOperationType.Fixed;
}
if (CameraManager.Instance.MainCamera == targetCamera)
CameraManager.Instance.SetMainCameraActive(targetCamera);
}
}