Skip to content

Instantly share code, notes, and snippets.

@RomainKurtz
Created July 26, 2018 08:06
Show Gist options
  • Save RomainKurtz/dd585fb7a1f3fccfc3b2bed76fd91346 to your computer and use it in GitHub Desktop.
Save RomainKurtz/dd585fb7a1f3fccfc3b2bed76fd91346 to your computer and use it in GitHub Desktop.
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