1
This commit is contained in:
@@ -4,8 +4,8 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEditor.UIElements;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor.UIElements;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEditor;
|
||||
#endif
|
||||
@@ -30,14 +30,24 @@ namespace BITKit.Events
|
||||
{
|
||||
foreach (var x in Targets)
|
||||
{
|
||||
var method =x.Target.GetType().GetMethod(x.MethodName);
|
||||
var methodName = x.MethodName;
|
||||
var target = x.Target;
|
||||
var split = methodName.Split('/');
|
||||
if (x.Target is GameObject gameObject&& split.Length is 2 && BITSharp.TryGetTypeFromFullName(split[0],out var type) && gameObject.TryGetComponent(type,out var _target))
|
||||
{
|
||||
target = _target;
|
||||
methodName = split[1];
|
||||
}
|
||||
|
||||
|
||||
var method =target.GetType().GetMethod(methodName);
|
||||
try
|
||||
{
|
||||
method?.Invoke(x.Target, objects);
|
||||
method?.Invoke(target, objects);
|
||||
}
|
||||
catch (TargetParameterCountException e)
|
||||
{
|
||||
Debug.LogWarning(string.Join(",",method?.GetParameters().Select(x=>x.Name)));
|
||||
BIT4Log.Log<UnityEvent>(string.Join(",",method?.GetParameters().Select(x=>x.Name)));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@@ -114,14 +124,45 @@ namespace BITKit.Events
|
||||
|
||||
if (x.Target is not null)
|
||||
{
|
||||
field.choices = x.Target
|
||||
.GetType()
|
||||
.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
|
||||
.Where(x=>x.IsSpecialName is false)
|
||||
.Where(x=>x.GetCustomAttribute<ObsoleteAttribute>() is null)
|
||||
.Select(x => x.Name)
|
||||
//.Where(x=>_unityMethodNames.Contains(x) is false)
|
||||
.ToList();
|
||||
switch (x.Target)
|
||||
{
|
||||
case GameObject gameObject:
|
||||
var methodNames = new List<string>();
|
||||
foreach (var mono in gameObject.GetComponents<MonoBehaviour>())
|
||||
{
|
||||
foreach (var methodInfo in mono.GetComponents<MonoBehaviour>().Cast<object>().Append(gameObject)
|
||||
.SelectMany(_mono => _mono
|
||||
.GetType()
|
||||
.GetMethods(BindingFlags.Instance | BindingFlags.Public |
|
||||
BindingFlags.NonPublic))
|
||||
.Where(info =>info.IsSpecialName is false && info.GetCustomAttribute<ObsoleteAttribute>() is null)
|
||||
)
|
||||
{
|
||||
methodNames.Add($"{mono.GetType().FullName}/{methodInfo.Name}");
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var VARIABLE in gameObject
|
||||
.GetType()
|
||||
.GetMethods()
|
||||
.Where(info =>info.IsSpecialName is false && info.GetCustomAttribute<ObsoleteAttribute>() is null)
|
||||
)
|
||||
{
|
||||
methodNames.Add(VARIABLE.Name);
|
||||
}
|
||||
field.choices = methodNames;
|
||||
break;
|
||||
default:
|
||||
field.choices = x.Target
|
||||
.GetType()
|
||||
.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
|
||||
.Where(x=>x.IsSpecialName is false)
|
||||
.Where(x=>x.GetCustomAttribute<ObsoleteAttribute>() is null)
|
||||
.Select(x => $"{x.Name}")
|
||||
//.Where(x=>_unityMethodNames.Contains(x) is false)
|
||||
.ToList();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user