-
Notifications
You must be signed in to change notification settings - Fork 1
/
PreviewWindow.cs
96 lines (80 loc) · 2.4 KB
/
PreviewWindow.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
95
96
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.SceneManagement;
using UnityEditor.SceneManagement;
using UnityEngine.Video;
public class PreviewWindow : EditorWindow {
[MenuItem("Window/360-Tool/Preview")]
public static void Create() {
EditorWindow.GetWindow<PreviewWindow>();
}
Camera cam;
RenderTexture rt;
Rect r = new Rect(0,0,100,100);
void OnEnable() {
cam = Camera.main;
EditorSceneManager.activeSceneChangedInEditMode += UpdateCamera;
EditorApplication.update += Repaint;
Selection.selectionChanged += UpdateSelection;
}
void OnDisable() {
EditorSceneManager.activeSceneChangedInEditMode -= UpdateCamera;
EditorApplication.update -= Repaint;
}
void UpdateSelection() {
if ( Selection.activeGameObject != null ) {
HotspotPositionCalc hpc = Selection.activeGameObject.GetComponent<HotspotPositionCalc>();
if ( hpc ) {
cam.transform.LookAt(hpc.transform.position);
}
}
}
void UpdateCamera( Scene oldScene, Scene newScene ) {
cam = Camera.main;
if ( cam == null ) {
//check if there's a preview camera
PreviewCamera pcam = FindObjectOfType<PreviewCamera>();
if ( pcam ) {
cam = pcam.GetComponent<Camera>();
}
}
}
void OnGUI() {
if ( cam != null ) {
rt = RenderTexture.GetTemporary((int)position.width, (int)position.height, 24);
cam.targetTexture = rt;
cam.Render();
cam.targetTexture = null;
r.width = position.width;
r.height = position.height;
GUI.DrawTexture(r, rt);
RenderTexture.ReleaseTemporary(rt);
BeginWindows();
if ( DisplayFrameStatistics.instance ) {
DisplayFrameStatistics.instance.windowRect = GUI.Window(0, DisplayFrameStatistics.instance.windowRect, DisplayFrameStatistics.instance.SceneWindow, "Preview Controls" );
}
if ( HotspotEditor.instance ) {
HotspotEditor.instance.rect = GUI.Window(0, HotspotEditor.instance.rect, HotspotEditor.instance.GUIWindow, "Hotspot Controls" );
}
EndWindows();
if ( Event.current.type == EventType.MouseDrag ) {
float yaw = Event.current.delta.x * .2f;
float pitch = Event.current.delta.y * .2f;
Vector3 euler = cam.transform.eulerAngles;
euler.x -= pitch;
euler.y -= yaw;
euler.z = 0;
cam.transform.rotation = Quaternion.Euler(euler);
}
}
else {
cam = Camera.main;
}
}
void Window(int id) {
GUILayout.Button("AAAAAA");
GUI.DragWindow();
}
}