ソースコード
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( "scenePaintTargetChanged", BINDING_ATTR ); public static event Action<GameObject> scenePaintTargetChanged { add => m_info.AddEventHandler( null, value ); remove => m_info.RemoveEventHandler( null, value ); } }
使い方
using UnityEditor; using UnityEngine; [InitializeOnLoad] public static class Example { static Example() { EditorApplicationUtility.scenePaintTargetChanged += OnChanged; } private static void OnChanged( GameObject gameObject ) { Debug.Log( gameObject.name ); } }
Tile Palette の Active Tilemap が変更された時に呼び出されます
引数には新しく Active Tilemap に設定されたゲームオブジェクトが渡ってきます