using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
namespace AV.UITK
{
public static partial class FluentUITK
{
const BindingFlags AnyBinding = BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public;
static Assembly EventAssembly { get; } = typeof(CallbackEventHandler).Assembly;
internal enum CallbackPhase
{
TargetAndBubbleUp = 1 << 0,
TrickleDownAndTarget = 1 << 1
}
/// Represents retrieved info about registered .
public class EventFunctor
{
public CallbackEventHandler handler { get; internal set; }
public Delegate callback { get; internal set; }
public long eventTypeId { get; internal set; }
public TrickleDown trickleDown => phase == CallbackPhase.TrickleDownAndTarget
? TrickleDown.TrickleDown
: TrickleDown.NoTrickleDown;
internal CallbackPhase phase;
internal object callbackRegistry;
public bool Is() => callback is EventCallback;
public bool Is(out EventCallback evt) where T : class
{
evt = callback as EventCallback;
return Is();
}
public void Unregister()
{
EventCallbackRegistryRef.UnregisterCallback(callbackRegistry, eventTypeId, callback, trickleDown);
}
}
public static void UnregisterCallback(CallbackEventHandler handler, long eventTypeId, Delegate callback, TrickleDown trickle)
{
var registry = CallbackEventHandlerRef.GetCallbackRegistry(handler);
EventCallbackRegistryRef.UnregisterCallback(registry, eventTypeId, callback, trickle);
}
/// Returns info about all callbacks registered to the event handler.
public static IEnumerable GetCallbacks(CallbackEventHandler handler)
{
var registry = CallbackEventHandlerRef.GetCallbackRegistry(handler);
var callbackList = EventCallbackRegistryRef.GetCallbackListForWriting(registry);
var list = EventCallbackListRef.GetList(callbackList);
// Avoids modified collection error on unregister
var tempList = new List