-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathFollowSceneViewCamera.cs
54 lines (48 loc) · 1.16 KB
/
FollowSceneViewCamera.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using UnityEngine;
using UnityEditor;
using System.Collections;
[ExecuteInEditMode]
public class FollowSceneViewCamera : Editor
{
static bool _followSceneView = false;
static Camera _followCamera = null;
static FollowSceneViewCamera()
{
EditorApplication.update += Update;
}
[MenuItem("Tools/Toggle Camera Follow Scene View #v")]
public static void ToggleCameraFollowSceneView()
{
_followSceneView = !_followSceneView;
}
static void Update()
{
if (_followSceneView)
{
if (!_followCamera)
{
var mainCameraObj = GameObject.FindGameObjectWithTag("MainCamera");
if (mainCameraObj)
_followCamera = mainCameraObj.GetComponent<Camera>();
if(!_followCamera)
{
Debug.LogError("No Camera found to follow scene view");
_followSceneView = false;
return;
}
}
var sceneCameras = SceneView.GetAllSceneCameras();
if (sceneCameras.Length > 0)
{
_followCamera.transform.position = sceneCameras[0].transform.position;
_followCamera.transform.rotation = sceneCameras[0].transform.rotation;
}
else
{
Debug.LogError("No scene view found to follow");
_followSceneView = false;
return;
}
}
}
}