【发布时间】:2017-11-06 09:32:15
【问题描述】:
我做了一个这样的自定义事件:
public delegate void ResponseReceivedDelegate(string textToSpeak, string offeringText, string offeringImageNo, string animationName, string emotion);
public static event ResponseReceivedDelegate ResponseReceivedEvent;
if (ResponseReceivedEvent != null)
{
ResponseReceivedEvent (textToSpeak, offeringText, offeringImageNo, animationName, emotion);
}
我已经将此事件注册到多个其他脚本中,以便我知道该事件已经发生。
现在的问题是,有不同的参数(如上所示)。我的每个脚本都需要一个参数,特定脚本不需要其他参数。就像一个脚本使用 textToSpeak,而另一个脚本使用 offeringText 等等。 .随着事件的发生。我的问题是我需要编写单独的事件还是这个事件就足够了。?哪个是正确的方法?
ResponseReceivedEventForSpeak (textToSpeak);
ResponseReceivedEventForOfferingText (offeringText);
ResponseReceivedEventForImageNo (offeringImageNo,);
//and so on...
或
ResponseReceivedEvent (textToSpeak, offeringText, offeringImageNo, animationName, emotion);
?????????????
【问题讨论】:
-
这是一个基于意见的东西——你可以制作一个包罗万象的东西,也可以有个人......这是你的设计。
-
也许吧,但我认为只有一种专业的方法我想知道它的优缺点。
-
“我认为只有一种专业的方法”——这也是固执己见。
-
如果事件同时发生,您可以创建一个大事件。我宁愿使用派生自
EventArgs的类的标准方式@
标签: c# custom-events