如何从产卵的GameObject中获取通用组件?
I.e我有一个基础通用类。
class Base<T> : MonoBehaviour where T : MonoBehaviour
{
public Foo() {}
}
和派生类。
class Example : Base<Example>
{
}
我不知道如何从产卵的GameObject中获取这个类,我把它作为一个组件。
我试过了,但我的结果是空的,所以我决定寻求一些帮助:)
// @object - Spawned before and exists.
Base<MonoBehaviour> tmp = @object.GetComponent<Base<MonoBehaviour>>();
尝试使用接口实现。
class Base<T> : MonoBehaviour, IBase where T : MonoBehaviour
并从GO中获取接口。
var tmp = @object.GetComponent<IBase>();