-
Notifications
You must be signed in to change notification settings - Fork 1
/
BlenderCameraControlsForUnity.cs
94 lines (86 loc) · 4.28 KB
/
BlenderCameraControlsForUnity.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using UnityEngine;
using UnityEditor;
[InitializeOnLoad]
public class BlenderCameraControlsForUnity
{
/*
* This an extension of Will Traxler's CamControl script:
* http://wiki.unity3d.com/index.php/Blender_Camera_Controls_Window
*
* which is the extension of Marc Kusters BlenderCameraControls script:
* http://wiki.unity3d.com/index.php/Blender_Camera_Controls
*/
static BlenderCameraControlsForUnity()
{
SceneView.duringSceneGui += view =>
{
UnityEditor.SceneView sceneView;
Vector3 eulerAngles;
Event current;
Quaternion rotHelper;
current = Event.current;
if (!current.isKey || current.type != EventType.KeyDown)
return;
sceneView = UnityEditor.SceneView.lastActiveSceneView;
eulerAngles = sceneView.camera.transform.rotation.eulerAngles;
rotHelper = sceneView.camera.transform.rotation;
switch (current.keyCode)
{
case KeyCode.Keypad1:
if (current.control == false)
sceneView.LookAtDirect(SceneView.lastActiveSceneView.pivot, Quaternion.Euler(new Vector3(0f, 360f, 0f)));
else
sceneView.LookAtDirect(SceneView.lastActiveSceneView.pivot, Quaternion.Euler(new Vector3(0f, 180f, 0f)));
break;
case KeyCode.Keypad2:
sceneView.LookAtDirect(SceneView.lastActiveSceneView.pivot, rotHelper * Quaternion.Euler(new Vector3(-15f, 0f, 0f)));
break;
case KeyCode.Keypad3:
if (current.control == false)
sceneView.LookAtDirect(SceneView.lastActiveSceneView.pivot, Quaternion.Euler(new Vector3(0f, 270f, 0f)));
else
sceneView.LookAtDirect(SceneView.lastActiveSceneView.pivot, Quaternion.Euler(new Vector3(0f, 90f, 0f)));
break;
case KeyCode.Keypad4:
sceneView.LookAtDirect(SceneView.lastActiveSceneView.pivot, Quaternion.Euler(new Vector3(eulerAngles.x, eulerAngles.y + 15f, eulerAngles.z)));
break;
case KeyCode.Keypad5:
sceneView.orthographic = !sceneView.orthographic;
break;
case KeyCode.Keypad6:
sceneView.LookAtDirect(SceneView.lastActiveSceneView.pivot, Quaternion.Euler(new Vector3(eulerAngles.x, eulerAngles.y - 15f, eulerAngles.z)));
break;
case KeyCode.Keypad7:
if (current.control == false)
sceneView.LookAtDirect(SceneView.lastActiveSceneView.pivot, Quaternion.Euler(new Vector3(90f, 0f, 0f)));
else
sceneView.LookAtDirect(SceneView.lastActiveSceneView.pivot, Quaternion.Euler(new Vector3(270f, 0f, 0f)));
break;
case KeyCode.Keypad8:
sceneView.LookAtDirect(SceneView.lastActiveSceneView.pivot, rotHelper * Quaternion.Euler(new Vector3(15f, 0f, 0f)));
break;
case KeyCode.KeypadPeriod:
if (Selection.transforms.Length == 1)
sceneView.LookAtDirect(Selection.activeTransform.position, sceneView.camera.transform.rotation);
else if (Selection.transforms.Length > 1)
{
Vector3 tempVec = new Vector3();
for (int i = 0; i < Selection.transforms.Length; i++)
{
tempVec += Selection.transforms[i].position;
}
sceneView.LookAtDirect((tempVec / Selection.transforms.Length), sceneView.camera.transform.rotation);
}
break;
case KeyCode.KeypadMinus:
SceneView.RepaintAll();
sceneView.size *= 1.1f;
break;
case KeyCode.KeypadPlus:
SceneView.RepaintAll();
sceneView.size /= 1.1f;
break;
}
};
}
}