ソースコード
using System; using System.Reflection; using UnityEditor; using UnityEngine; public static class EditorApplicationUtility { private const BindingFlags BINDING_ATTR = BindingFlags.Static | BindingFlags.Public; private static readonly Assembly m_assembly = typeof( AssetDatabase ).Assembly; private static readonly Type m_type = m_assembly.GetType( "UnityEditor.GridPaintingState" ); private static readonly EventInfo m_info = m_type.GetEvent( "brushChanged", BINDING_ATTR ); public static event Action<GridBrushBase> brushChanged { add => m_info.AddEventHandler( null, value ); remove => m_info.RemoveEventHandler( null, value ); } }
使い方
using UnityEditor; using UnityEngine; [InitializeOnLoad] public static class Example { static Example() { EditorApplicationUtility.brushChanged += OnChanged; } private static void OnChanged( GridBrushBase brush ) { Debug.Log( brush.name ); } }
Tile Palette のブラシが変更された時に呼び出されます
引数には新しく選択されたブラシが渡ってきます