Created
May 4, 2012 15:31
-
-
Save attrition/2595539 to your computer and use it in GitHub Desktop.
Unity3D Scene View Chase Camera
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 UnityEngine; | |
using UnityEditor; | |
public class SceneChaseCam : EditorWindow | |
{ | |
bool active = false; | |
bool followSelection = false; | |
Transform toFollow; | |
// Add menu named "Scene Chase Cam" to the Window menu | |
[MenuItem("Window/Scene Chase Cam")] | |
static void Init() | |
{ | |
// Get/create window and focus | |
(EditorWindow.GetWindow<SceneChaseCam>()).Focus(); | |
} | |
void OnGUI() | |
{ | |
// basic options | |
active = EditorGUILayout.Toggle("Active:", active); | |
followSelection = EditorGUILayout.Toggle("Follow selection:", followSelection); | |
// slight aesthetic gap | |
GUILayout.Space(10); | |
EditorGUILayout.LabelField("Transform to follow:"); | |
toFollow = EditorGUILayout.ObjectField(toFollow, typeof(Transform), true) as Transform; | |
// automatically follow selected gameobject? | |
if (followSelection && Selection.activeTransform != null) | |
toFollow = Selection.activeTransform; | |
// don't bother showing vector field unless we have a transform selected | |
if (toFollow != null) | |
toFollow.transform.position = EditorGUILayout.Vector3Field(toFollow.gameObject.name + " position", | |
toFollow.transform.position); | |
Repaint(); | |
} | |
void Update() | |
{ | |
// must be active, playing and following some object | |
if (active && Application.isPlaying && toFollow != null) | |
{ | |
foreach (SceneView scene in SceneView.sceneViews) | |
{ | |
scene.pivot = toFollow.position; | |
scene.Repaint(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment