Skip to content

Instantly share code, notes, and snippets.

@anchan828
Created April 5, 2013 09:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anchan828/5317953 to your computer and use it in GitHub Desktop.
Save anchan828/5317953 to your computer and use it in GitHub Desktop.
Editor.CreateEditor の使い方その1
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