[편집기 확장] 카메라 리스트(카메라 리스트)
14307 단어 Unity
Assets/Editor/CameraChecker.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class CameraChecker {
public class CameraComparer : IComparer
{
public int Compare(object x, object y) {
Camera c1 = x as Camera;
Camera c2 = y as Camera;
if (c1 == null && c2 == null) {
return 0;
}
if (c1 == null) {
return -1;
}
if (c2 == null) {
return 1;
}
return c1.depth.CompareTo (c2.depth);
}
}
public class BackgroundColorScope : GUI.Scope
{
private readonly Color color;
public BackgroundColorScope(Color color) {
this.color = GUI.backgroundColor;
GUI.backgroundColor = color;
}
protected override void CloseScope() {
GUI.backgroundColor = color;
}
}
static int windowID = 1001;
static Rect windowRect = new Rect(10, 10, 200, 100);
static CameraComparer comp = new CameraComparer();
[MenuItem("Tools/CameraChecker")]
static void SwitchCameraChecker() {
string menuPath = "Tools/CameraChecker";
bool val = Menu.GetChecked(menuPath);
Menu.SetChecked(menuPath, !val);
SceneView.RepaintAll ();
}
[InitializeOnLoadMethod]
static void InitCameraChecker() {
SceneView.onSceneGUIDelegate += OnGUI;
}
static void OnGUI(SceneView sceneView ) {
if (!Menu.GetChecked ("Tools/CameraChecker")) {
return;
}
Handles.BeginGUI ();
windowRect = GUILayout.Window (windowID, windowRect, WindowFunction, "CameraChecker");
Handles.EndGUI ();
}
static void WindowFunction(int _windowID) {
Camera[] cameras = Object.FindObjectsOfType<Camera> ();
System.Array.Sort (cameras, comp);
System.Array.Reverse (cameras);
if (cameras != null) {
for (int i = 0; i < cameras.Length; i++) {
string cameraName = cameras [i].name;
if (cameraName.Length > 10) {
cameraName = cameraName.Substring (0, 10);
}
string txt = string.Format("D({0}) {1} [{2}]", cameras[i].depth, cameraName, (cameras [i].enabled ? "ON" : "OFF"));
if (cameras [i].gameObject == Selection.activeGameObject) {
using (new BackgroundColorScope (Color.green)) {
if (GUILayout.Button (txt, GUILayout.Width (200))) {
Selection.activeGameObject = cameras [i].gameObject;
}
}
} else {
if (GUILayout.Button (txt, GUILayout.Width (200))) {
Selection.activeGameObject = cameras [i].gameObject;
}
}
}
}
GUI.DragWindow ();
}
}
Reference
이 문제에 관하여([편집기 확장] 카메라 리스트(카메라 리스트)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/hkomo746/items/e3a9b8ef788c02f1f3e2텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)