SceneViewのカメラ位置を、特定のカメラ位置と合わせるコンポーネント
SceneViewのOverDrawやMipMapを確認する時に、結局現在のGameViewカメラで見た時の具合を確認したい時があります。
なので、特定のカメラの位置情報をSceneViewカメラに渡すためのコンポーネントを書いてみました。
#if UNITY_EDITOR using UnityEditor; #endif using UnityEngine; namespace ScreenPocket { /// <summary> /// カメラの位置をSceneViewのカメラに流し込む /// </summary> [DisallowMultipleComponent] [RequireComponent(typeof(Camera))] public class SyncSceneViewCamera : MonoBehaviour { #if UNITY_EDITOR public bool isSync = false; void OnGUI() { if (!isSync) { return; } var view = SceneView.lastActiveSceneView; if ( view == null ) { return; } var myTransform = transform; var forward = myTransform.forward; var myCamera = GetComponent<Camera>(); view.pivot = myTransform.position + forward * myCamera.farClipPlane; view.rotation = Quaternion.LookRotation(forward); view.size = myCamera.farClipPlane; view.orthographic = myCamera.orthographic; } #endif } }
これで大体の見た目は合わせられます。
GameViewの位置サイズを取ってきてSceneViewの位置サイズも合わせようかと思いましたが、
エディタのレイアウトが崩れてしまったので、コレくらいの処理で止めておきます。