Skip to content

Instantly share code, notes, and snippets.

@baba-s
Last active April 8, 2024 09:29
Show Gist options
  • Save baba-s/864f7f1f513aabeb1c94 to your computer and use it in GitHub Desktop.
Save baba-s/864f7f1f513aabeb1c94 to your computer and use it in GitHub Desktop.
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
public static class Example
{
private const int WIDTH = 16;
static Example()
{
EditorApplication.hierarchyWindowItemOnGUI += OnGUI;
}
private static void OnGUI( int instanceID, Rect selectionRect )
{
var gameObject = EditorUtility.InstanceIDToObject( instanceID ) as GameObject;
if ( gameObject == null ) return;
var position = selectionRect;
position.x = position.xMax - WIDTH;
position.width = WIDTH;
var newActive = GUI.Toggle( position, gameObject.activeSelf, string.Empty );
if ( newActive == gameObject.activeSelf ) return;
gameObject.SetActive( newActive );
}
}
@srndpty
Copy link

srndpty commented Jul 25, 2016

すばらしい拡張をありがとうございます。
最後の行ですが、現状だとトグルで変更してそのままシーンを切り替えると、保存されずに切り替わってしまいますので、Undoの登録とSetDirty()をするとより便利になると思います。
Undo.RecordObject(go, string.Format("{0} GameObject '{1}'", (newActive ? "Activate" : "Deactivate"), go.name));
go.SetActive(newActive);
EditorUtility.SetDirty(go);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment