1. 우선 새로 보여질 카메라를 하나 만든다.
2. 새 카메라의 Depth는 메인 카메라의 Depth보다 낮아야 된다.(같거나 높으면 메인 창에서도 새 카메라를 사용해버림)
3. 아래에서 m_strQuaterViewerName 은 카메라 오브젝트 이름이다. 임의로 집어넣게 만들어 놨음..
4. QuarterViewer.cs 스크립트는 Project 탭의 Editor 폴더 하위에 들어가야 한다.(에디트 시 사용될 스크립트라서..)
P.s. 예제에서는 RenderTextureFormat.ARGB32를 썼는데 Depth 문제가 있어서 RenderTextureFormat.Depth 로 고쳤다.
1 using UnityEngine;
2 using UnityEditor;
3
4 public class QuarterViewer : EditorWindow
5 {
6 private static EditorWindow editorWindow;
7
8 private string m_strQuaterViewerName;
9 private Camera m_camQuaterViewer;
10 private RenderTexture m_RenderTexture;
11
12 [MenuItem("Camera/Quarter Viewer")]
13 static void Init()
14 {
15 editorWindow = GetWindow(typeof(QuarterViewer));
16 editorWindow.autoRepaintOnSceneChange = true;
17 editorWindow.Show();
18 }
19 public void Awake()
20 {
21 m_RenderTexture = new RenderTexture((int)position.width,
22 (int)position.height,
23 (int)RenderTextureFormat.Depth);
24
25 m_strQuaterViewerName = "Camera - QuarterViewer";
26 if (GameObject.Find(m_strQuaterViewerName))
27 {
28 m_camQuaterViewer = GameObject.Find(m_strQuaterViewerName).GetComponent<Camera>();
29 if (null == m_camQuaterViewer)
30 {
31 Debug.Log("Can't Find 'Camera - QuarterView'");
32 }
33 }
34 }
35 public void Update()
36 {
37 if (null != m_camQuaterViewer && null != m_RenderTexture)
38 {
39 m_camQuaterViewer.targetTexture = m_RenderTexture;
40 m_camQuaterViewer.Render();
41 m_camQuaterViewer.targetTexture = null;
42
43 if (m_RenderTexture.width != position.width ||
44 m_RenderTexture.height != position.height)
45 {
46 m_RenderTexture = new RenderTexture((int)position.width,
47 (int)position.height,
48 (int)RenderTextureFormat.Depth);
49 }
50 }
51 }
52 void OnGUI()
53 {
54 if (null != m_camQuaterViewer && null != m_RenderTexture)
55 {
56 GUI.DrawTexture(new Rect(0.0f, 0.0f, position.width, position.height), m_RenderTexture);
57 }
58
59 }
60 }
[참조]
http://blueasa.tistory.com/943
http://docs.unity3d.com/Documentation/ScriptReference/EditorWindow-autoRepaintOnSceneChange.html
http://docs.unity3d.com/Documentation/ScriptReference/RenderTextureFormat.html