Last active
April 8, 2024 09:29
-
-
Save baba-s/864f7f1f513aabeb1c94 to your computer and use it in GitHub Desktop.
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 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 ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
すばらしい拡張をありがとうございます。
最後の行ですが、現状だとトグルで変更してそのままシーンを切り替えると、保存されずに切り替わってしまいますので、Undoの登録とSetDirty()をするとより便利になると思います。
Undo.RecordObject(go, string.Format("{0} GameObject '{1}'", (newActive ? "Activate" : "Deactivate"), go.name));
go.SetActive(newActive);
EditorUtility.SetDirty(go);