从MonoBehavior不允许使用new了解Unity的继承关系

MonoBehaviorgameObject不能为static则导致抽象工厂继承自MonoBehavior的话不被允许使用new关键字传递对象。

浅显一点的原因是MonoBehavior继承自Component,所以传递的也被规定为Component

但是Unity给我们留下了口子。

感谢CSDN大佬( https://blog.csdn.net/woodengm/article/details/126472371 )整理的Unity继承关系图。

从图中我们可以知道基于ComponentMonoBehavior不行的话可以让抽象工厂继承ScriptableObject

同时

也间接告诉了我们可以通过继承ScriptableObject来实现对象传递。


调用ScriptableObject.CreateInstance替代new即可.