C# UnityEvent不接受以接口为参数的函数

C# UnityEvent不接受以接口为参数的函数,c#,unity3d,C#,Unity3d,我有一个脚本,它的函数有一个作为参数的接口 拼图条件 但是看起来这个函数没有出现在UnityEvent中 尝试使用脚本添加按钮操作 public Button btn; void Start() { btn.onClick.AddListener(delegate{ Execute_IfPuzzleCompleted(YourObjectHere);}) } 我的unity版本是2017.3,运行在Window10上。使用下面的代码没有问题 在我的一个代码文件

我有一个脚本,它的函数有一个作为参数的接口

拼图条件 但是看起来这个函数没有出现在UnityEvent中


尝试使用脚本添加按钮操作

public Button btn;
void Start()
{
    btn.onClick.AddListener(delegate{  
           Execute_IfPuzzleCompleted(YourObjectHere);})
}

我的unity版本是2017.3,运行在Window10上。使用下面的代码没有问题

在我的一个代码文件中:定义接口和事件

        public interface TestPara { }
        [System.Serializable]
        public class TestInterfaceEvent : UnityEvent<TestPara>
        {

        }
在OnEventEffect.cs中定义两个函数

        public void Test(TestPara para)
        {
        }
        public void Test()
        {
        }
如图所示,unityevent可以选择接口作为参数但请注意 它标志着动态。

在Inspector中配置UnityEvent时,有两种类型的 支持的函数调用:

静态的。静态调用是预配置的调用,具有在UI中设置的预配置值。这意味着在调用回调时,将使用已输入到 用户界面

动态的。使用从代码发送的参数调用动态调用,该参数绑定到正在调用的UnityEvent类型 调用。UI过滤回调并仅显示动态调用 对UnityEvent有效的

-------------------------------------更新-------------------------------------------

更新原因: 我尝试过许多特殊情况,例如struct、enum或多个基类型作为参数。它们都不会显示在静态列表中。经过数小时的研究,我找到了一份约书亚·麦肯齐表格来解答这些问题

Unity的UnityEventBaseInspector类

//UnityEventBase has this field that it serializes
       PersistentCallGroup m_PersistentCalls;// holds a list of all the methods to call when the event is invoked

//and PersistentCallgroup has this
       List<PersistentCall> m_Calls;

//each PersistentCall has these fields
       UnityEventCallState m_CallState // an enum for off, editor and runtime, or runtime only
       PersistentListenerMode m_Mode // enum determining which internal delegate to call and which inputs to draw in inspector
       UnityEngine.Object m_Target // the instance which to call the method on
       string m_TypeName // the concrete type name of the target (needed for polymorphism)
       string m_MethodName // the name of the method to call in target

       ArgumentCache m_Arguments //container class which holds the arguments that are passed into the calling function, used for static calls

//ArgumentCache has the following variables
       UnityEngine.Object m_ObjectArgument
       string m_ObjectArgumentAssemblyTypeName // used to confirm if objectArgument is valid
       int m_IntArgument
       float m_FloatArgument
       string m_StringArgument
       bool m_BoolArgument
//UnityEventBase有一个它序列化的字段
PersistentCallGroup m_PersistentCalls;//保存在调用事件时要调用的所有方法的列表
//PersistentCallgroup有以下功能
列出m_呼叫;
//每个PersistentCall都有以下字段
UnityEventCallState m_CallState//用于关闭、编辑器和运行时或仅用于运行时的枚举
PersistentListenerMode m_Mode//enum确定要调用的内部委托以及要在inspector中绘制的输入
Object m\u Target//要对其调用方法的实例
string m_TypeName//目标的具体类型名(多态性需要)
string m_MethodName//要在目标中调用的方法的名称
ArgumentCache m_Arguments//容器类,该类保存传递到调用函数的参数,用于静态调用
//ArgumentCache具有以下变量
UnityEngine.Object m_ObjectArgument
字符串m_ObjectArgumentAssemblyTypeName//用于确认objectArgument是否有效
int m_IntArgument
浮点m_浮点参数
字符串m_StringArgument
布尔穆布拉古门特酒店
正如您在ArgumentCache类中看到的,它实际上只有足够的内存 存储每种数据类型中的一种,以及当您真正进入 编辑器脚本,没有干净的方式显示多个字段 可用的有限字段(不能显示任何函数(int,int)调用 例如,因为每个调用中只有一个intArgument字段) ArgumentCache类


对于自定义类,只支持UnityEngine.Object的子类。

Puzzbase和IPuzzleMain之间的关系是什么?似乎其他的都可以。我不想让它继承PuzzleBase中未使用的部分,所以我创建了
IPuzzleMain
接口来添加函数,比如,
GetPuzzleState
,etcSo您可能忘了为新接口创建新的事件类?因为一旦事件有任何参数,您就需要为其定义。@Rotang为接口创建新的事件类是什么意思?因为我已经有了接口定义,接口也已经在脚本中实现了。我在unity中进行了测试。它对接口有效。我不知道为什么unityevent不能。问题不是设置unityevent时使用接口作为参数,而是设置一个使用接口作为参数的公共函数。在静态参数上,Unity不显示以接口为参数的函数。
        public void Test(TestPara para)
        {
        }
        public void Test()
        {
        }
//UnityEventBase has this field that it serializes
       PersistentCallGroup m_PersistentCalls;// holds a list of all the methods to call when the event is invoked

//and PersistentCallgroup has this
       List<PersistentCall> m_Calls;

//each PersistentCall has these fields
       UnityEventCallState m_CallState // an enum for off, editor and runtime, or runtime only
       PersistentListenerMode m_Mode // enum determining which internal delegate to call and which inputs to draw in inspector
       UnityEngine.Object m_Target // the instance which to call the method on
       string m_TypeName // the concrete type name of the target (needed for polymorphism)
       string m_MethodName // the name of the method to call in target

       ArgumentCache m_Arguments //container class which holds the arguments that are passed into the calling function, used for static calls

//ArgumentCache has the following variables
       UnityEngine.Object m_ObjectArgument
       string m_ObjectArgumentAssemblyTypeName // used to confirm if objectArgument is valid
       int m_IntArgument
       float m_FloatArgument
       string m_StringArgument
       bool m_BoolArgument