Created
April 5, 2013 09:29
-
-
Save anchan828/5317953 to your computer and use it in GitHub Desktop.
Editor.CreateEditor の使い方その1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using System.Collections.Generic; | |
public class CloneInspecotr : EditorWindow | |
{ | |
[MenuItem("Window/CloneInspecotr")] | |
static void Open () | |
{ | |
GetWindow<CloneInspecotr> (); | |
} | |
Dictionary<Object , Editor> editors = new Dictionary<Object, Editor> () ; | |
Dictionary<Object, bool> foldouts = new Dictionary<Object, bool> (); | |
void OnGUI () | |
{ | |
GameObject[] gameobjects = Selection.gameObjects; | |
if (gameobjects.Length == 0) | |
return; | |
GameObject gameobject = gameobjects [0]; | |
{ | |
//Add Editors | |
if (!editors.ContainsKey (gameobject)) | |
editors.Add (gameobject, Editor.CreateEditor (gameobject)); | |
foreach (Component c in gameobject.GetComponents<Component> ()) { | |
if (!editors.ContainsKey (c)) | |
editors.Add (c, Editor.CreateEditor (c)); | |
} | |
} | |
{ | |
if (editors.ContainsKey (gameobject)) | |
editors [gameobject].OnInspectorGUI (); | |
foreach (Component c in gameobject.GetComponents<Component> ()) { | |
if (editors.ContainsKey (c)) { | |
foldouts [c] = EditorGUILayout.InspectorTitlebar (foldouts.ContainsKey (c) ? foldouts [c] : true, c); | |
if (foldouts [c]) | |
editors [c].OnInspectorGUI (); | |
} | |
} | |
} | |
} | |
void OnInspectorUpdate () | |
{ | |
Repaint (); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment