我GameObject在 Unity 中有一个应该用作某些定义的容器。

我想访问该对象并检索Def类实例(每个对象都有Def通用类的实例)。
那么,如果我有一个GameObject实例,如何检索作为特定类实例的所有对象?
我GameObject在 Unity 中有一个应该用作某些定义的容器。

我想访问该对象并检索Def类实例(每个对象都有Def通用类的实例)。
那么,如果我有一个GameObject实例,如何检索作为特定类实例的所有对象?
您可以使用GameObject.GetComponents<Def>();检索Def中的所有类型组件GameObject。
Unity 文档中的更多信息http://docs.unity3d.com/ScriptReference/GameObject.GetComponents.html
public Def[] defArray;
public Defs gameobject; ///if you want to access from another class assign this your Defs gameobject from inspector
defs = Defs.GetComponents<Def>(); ///if you want access from another game object
defs = gameObject.GetComponents<Def>(); ///if Defs is attached to this gameObject
只要您有GameObject参考,就可以使用GetComponents()。
Def [] list = gameObject.GetComponents<Def>();