Added serializable action.

This commit is contained in:
2025-11-03 20:34:21 +01:00
parent b0cd87be7d
commit 21b9cdc77c
11 changed files with 125 additions and 51 deletions

View File

@@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using SerializableFunc.Runtime;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEditorInternal;
@@ -12,11 +13,11 @@ using UnityEngine;
using UnityEngine.UIElements;
using Utilities.Extensions.SystemExtensions;
using Utilities.Extensions.UIToolkit;
using UnityUtilities.SerializableDataHelpers;
using Object = UnityEngine.Object;
namespace UnityUtilities.SerializableDataHelpers.UnityEditorUtilities
{
[CustomPropertyDrawer(typeof(SerializableAction), true)]
[CustomPropertyDrawer(typeof(SerializableFuncBase<>), true)]
public class SerializableFuncBasePropertyDrawer : PropertyDrawer
{
@@ -169,7 +170,11 @@ namespace UnityUtilities.SerializableDataHelpers.UnityEditorUtilities
|| string.IsNullOrWhiteSpace(targetMethodProperty.stringValue)) return false;
Type[] funcArguments = GetFuncTypeArguments(funcProperty);
Type returnType = funcArguments.Last();
Type returnType = typeof(void);
if (funcArguments.Length > 0)
{
returnType = funcArguments.Last();
}
MethodInfo targetMethod = targetObjectProperty.objectReferenceValue
.GetType()
@@ -561,8 +566,15 @@ namespace UnityUtilities.SerializableDataHelpers.UnityEditorUtilities
{
if (info.IsSpecialName) return false;
Type returnType = funcParameters.Last();
if (info.ReturnType != returnType) return false;
if (funcParameters.Length > 0)
{
Type returnType = funcParameters.Last();
if (info.ReturnType != returnType) return false;
}
else
{
if (info.ReturnType == typeof(void)) return true;
}
ParameterInfo[] parameters = info.GetParameters();
if (parameters.Length != (funcParameters.Length - 1)) return false;