相机机位控制

main
pengjunwu 2024-01-17 19:18:23 +08:00
parent e98f3eb1ce
commit 95fd22f2d8
5 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 905277e7c44a6ed4bb97265276a54938
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,44 @@
using System.Collections;
using System.Collections.Generic;
using Gameplay;
using PhxhSDK;
using Sirenix.OdinInspector;
using UnityEngine;
/// <summary>
/// 记录一个相机的机位
/// </summary>
public class CameraStand : MonoBehaviour
{
[LabelText("是否正交")]
[SerializeField]
private bool _isOrthographic;
[ShowIf("isOrthographic")]
[LabelText("正交size")]
[SerializeField]
private float _size;
[HideIf("isOrthographic")]
[LabelText("FOV")]
[SerializeField]
private float _fov;
private Camera DefaultCamera => CommonUtils.GetSceneRootComponent<Camera>(gameObject.scene) ?? Camera.main;
[Button("测试机位")]
private void TestStand()
{
Apply();
}
public void Apply(Camera targetCamera = null)
{
targetCamera = targetCamera ? targetCamera : DefaultCamera;
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;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4f06003f27e2f0046bc4ef474712ceea
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: