private void FindInternal(GameObject[] prefabs) { GameObject canvasRoot = FindCanvasRootInScene(); if (canvasRoot == null) { Debug.LogWarning("Not found canvas root in scene."); } // 获取场景里的预制体引用,如果不存在就克隆一个预制体 for (int i = 0; i < prefabs.Length; i++) { GameObject prefab = prefabs[i]; GameObject cloneObject = EditorTools.GetClonePrefabInScene(prefab); if (cloneObject == null) { cloneObject = PrefabUtility.InstantiatePrefab(prefab) as GameObject; if (cloneObject == null) { cloneObject = GameObject.Instantiate <GameObject>(prefab); } // 如果是UI面板就放到Canvas底下 var bhvUI = cloneObject.GetComponent <Canvas>(); if (bhvUI != null) { if (canvasRoot != null) { cloneObject.transform.SetParent(canvasRoot.transform, false); } } } } EditorTools.FindReferencesInPrefabs(_searchObject, prefabs); }