Created
July 26, 2018 08:06
-
-
Save RomainKurtz/dd585fb7a1f3fccfc3b2bed76fd91346 to your computer and use it in GitHub Desktop.
This file contains 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; | |
using UnityEditor; | |
[InitializeOnLoad] | |
public class AlignCameraView : MonoBehaviour { | |
public bool Enable; | |
public static List<AlignCameraView> list; | |
static AlignCameraView() | |
{ | |
EditorApplication.update += UpdateFunction; | |
list = new List<AlignCameraView>(); | |
} | |
public AlignCameraView() | |
{ // regular constructor where we add this to static list | |
AlignCameraView.list.Add(this); | |
} | |
static void UpdateFunction() | |
{ | |
foreach (AlignCameraView mc in list) | |
{ | |
mc.UpdatePosition(); | |
} | |
} | |
public void UpdatePosition() | |
{ | |
if (Enable) { | |
transform.position = SceneView.lastActiveSceneView.camera.transform.position; | |
transform.rotation = SceneView.lastActiveSceneView.camera.transform.rotation; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment