Why choose UnityEvent over native C# events?

前端 未结 2 2099
攒了一身酷
攒了一身酷 2021-02-18 13:25

I mean, UnityEvents are slower than the native C# events and they still store a strong reference to the receivers. So, the only valid reason I can find to use UnityEvents over n

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-18 13:38

    UnityEvent is mainly used with Unity UI system, because ugui need to serialize callbacks configuration in ui system, such as the button's OnClick callback.

    Serialization is a most important feature in unity game engine, with c# builtin event system, you can't do serialize.

    So if you work with unity UI System, you must use the UnityEvent, if you want to serialize callback function configuration, you must use the UnityEvent.

    In other situation, just use the c# builtin event.

提交回复
热议问题