| prefabRoot | 预制体资源的根 GameObject。 |
| scene | 搜索预制体实例的场景。您指定的场景必须有效且已加载。 |
GameObject[] 根为 prefabRoot 的所有预制体资源实例的根 GameObjects。
检索在所有当前加载的场景中找到的,根为 prefabRoot 的所有预制体资源实例的根 GameObjects。如果 prefabRoot 不是有效的预制体资源根 GameObject,则会抛出 ArgumentException。
FindAllInstancesOfPrefab 不会返回嵌套的预制体实例。
using UnityEditor; using UnityEngine; using UnityEngine.SceneManagement; using NUnit.Framework;
public class Example : MonoBehaviour { public GameObject prefabAssetRoot; private void Start() { var expectedInstance = (GameObject)PrefabUtility.InstantiatePrefab(prefabAssetRoot); var instances = PrefabUtility.FindAllInstancesOfPrefab(prefabAssetRoot); Assert.AreEqual(1, instances.Length); Assert.AreEqual(expectedInstance, instances[0]); } }
返回在 scene 中找到的,根为 prefabRoot 的所有预制体资源实例的根 GameObjects。如果 prefabRoot 不是有效的预制体资源根 GameObject,或者 scene 无效且未加载,则会抛出 ArgumentException。
FindAllInstancesOfPrefab 不会返回嵌套的预制体实例。
using UnityEditor; using UnityEngine; using UnityEngine.SceneManagement; using NUnit.Framework;
public class Example : MonoBehaviour { public GameObject prefabAssetRoot; private void Start() { var expectedInstance = (GameObject)PrefabUtility.InstantiatePrefab(prefabAssetRoot); var instances = PrefabUtility.FindAllInstancesOfPrefab(prefabAssetRoot, SceneManager.GetActiveScene()); Assert.AreEqual(1, instances.Length); Assert.AreEqual(expectedInstance, instances[0]); } }