【问题标题】:Find all GameObjects in the scene containing scripts, which are derived from an abstract class查找场景中包含脚本的所有游戏对象,这些脚本派生自一个抽象类
【发布时间】:2014-07-10 14:33:43
【问题描述】:

在场景中查找包含脚本的所有游戏对象时遇到问题,这些脚本派生自抽象类。

情况如下:

public abstract class IAbstractInterface: MonoBehaviour
{
}

public class Item_I_Need_To_Find1 : IAbstractInterface
{
}

public class Item_I_Need_To_Find2 : IAbstractInterface
{
}

....

如何找到场景中包含Item_I_Need_To_Find(%number%) 脚本的所有游戏对象?

非常感谢任何帮助。

提前致谢。

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    嗯,我找到了统一答案的解决方案。

    UnityEngine.Object.FindObjectsOfType< IAbstractInterface >(); 就像一个魅力!

    【讨论】:

      【解决方案2】:

      “is”运算符是你的朋友。

      if (myobject is IAbstractInterface)
      {
         ...
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-03-31
        • 2015-03-05
        • 1970-01-01
        • 2015-08-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多