Created
July 29, 2019 09:37
-
-
Save brutus3017/495fb0c978f602917150499f8ac13521 to your computer and use it in GitHub Desktop.
Unity Mirror EditorCamera to MainCamera
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| #if UNITY_EDITOR | |
| using UnityEditor; | |
| #endif | |
| namespace ArtificialRome { | |
| [ExecuteInEditMode] | |
| public class MirrorEditorCamera : MonoBehaviour { | |
| public bool enableCloneCamera; | |
| // Camera sceneCamera; | |
| // Use this for initialization | |
| void OnEnable () { | |
| } | |
| void OnDisable () { | |
| if (Camera.main != null && Camera.main.transform != null) { | |
| Camera.main.transform.parent.localRotation = Quaternion.identity; | |
| Camera.main.transform.parent.localPosition = Vector3.up; | |
| } | |
| } | |
| // Update is called once per frame | |
| void OnDrawGizmos () { | |
| #if UNITY_EDITOR | |
| if (Application.isPlaying || !enableCloneCamera || !this.enabled) { | |
| return; | |
| } | |
| var views = SceneView.sceneViews; | |
| if (views.Count == 0) { | |
| return; | |
| } | |
| var currentView = views[0] as SceneView; // camera; | |
| var sceneCamera = currentView.camera; | |
| if (sceneCamera == null) { | |
| return; | |
| } | |
| Camera.main.transform.parent.position = sceneCamera.transform.position; | |
| Camera.main.transform.parent.rotation = sceneCamera.transform.rotation; | |
| #endif | |
| } | |
| } | |
| } | |
| //#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment