Skip to content

Instantly share code, notes, and snippets.

@HiromuKato
Created August 20, 2017 03:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Unity SceneViewのアイコンを表示・非表示するエディタ拡張
using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
public static class ChangeIconVisibility
{
// アイコンの表示・非表示フラグ
static bool visibility = false;
// ボタンに表示するテキスト
static string buttonText = "Show Icon";
[InitializeOnLoadMethod]
static void Init()
{
SceneView.onSceneGUIDelegate += OnGUI;
}
static void OnGUI(SceneView sceneView)
{
var rect = new Rect(4, 20, 100, 0);
GUI.WindowFunction func = id =>
{
if (GUILayout.Button(buttonText))
{
if(visibility == true)
{
buttonText = "Show Icon";
} else
{
buttonText = "Hide Icon";
}
Func();
}
};
GUILayout.Window(1, rect, func, string.Empty);
}
private static void Func()
{
var Annotation = Type.GetType("UnityEditor.Annotation, UnityEditor");
var ClassId = Annotation.GetField("classID");
var ScriptClass = Annotation.GetField("scriptClass");
Type AnnotationUtility = Type.GetType("UnityEditor.AnnotationUtility, UnityEditor");
var GetAnnotations = AnnotationUtility.GetMethod("GetAnnotations", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
var SetGizmoEnabled = AnnotationUtility.GetMethod("SetGizmoEnabled", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
var SetIconEnabled = AnnotationUtility.GetMethod("SetIconEnabled", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
Array annotations = (Array)GetAnnotations.Invoke(null, null);
visibility = !visibility;
foreach (var a in annotations)
{
var parameters = new object[]
{
(int)ClassId.GetValue(a),
(string)ScriptClass.GetValue(a),
Convert.ToInt32(visibility),
};
SetIconEnabled.Invoke(null, parameters);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment