创建事件系统时是否需要多个代表的问题

时间:2019-07-11 11:56:34

标签: events delegates

我正在玩一个尚未完成的游戏,我看到了这段代码。

//Events
public delegate void planePhase();
public static event planePhase shiftPhazeEvent;
public static event planePhase shiftPhazeEndEvent;

public delegate void walkingLeft();
public static event walkingLeft changeDiractionEvent;

public delegate void playerDied();
public static event playerDied playerDiedEvent;
public static event playerDied levelEndedEvent;
public static event playerDied levelLoadedEvent;
public static event playerDied levelResetartEvent;

现在,我的问题是,所写内容与

有什么区别
//Events
public delegate void SomeEvent();
public static event SomeEvent shiftPhazeEvent;
public static event SomeEvent shiftPhazeEndEvent;

public static event SomeEvent changeDiractionEvent;

public static event SomeEvent playerDiedEvent;
public static event SomeEvent levelEndedEvent;
public static event SomeEvent  levelLoadedEvent;
public static event SomeEvent levelResetartEvent;

如果您只订阅一个事件名称,是否有理由将事件分隔为多个代表?

我看到的唯一一种区别是,如果您想在某个阶段删除一组函数,并且不想遍历整个委托,则可以只将其中一个作空。

还有其他意义吗?还是主要原因?

0 个答案:

没有答案