| | |
| | | // } |
| | | instance.transform.SetParentEx(parent, Vector3.zero, Quaternion.identity, Vector3.one); |
| | | // PrefabUtility.DisconnectPrefabInstance(instance); |
| | | |
| | | // 设置UI对象的Layer为UI |
| | | instance.layer = LayerMask.NameToLayer("UI"); |
| | | |
| | | // 递归设置所有子对象的Layer为UI |
| | | foreach (Transform child in instance.transform) |
| | | { |
| | | SetLayerRecursively(child.gameObject, "UI"); |
| | | } |
| | | |
| | | Selection.activeGameObject = instance; |
| | | } |
| | | |
| | | // 递归设置GameObject及其所有子对象的Layer |
| | | private static void SetLayerRecursively(GameObject obj, string layerName) |
| | | { |
| | | if (obj == null) |
| | | return; |
| | | |
| | | obj.layer = LayerMask.NameToLayer(layerName); |
| | | |
| | | foreach (Transform child in obj.transform) |
| | | { |
| | | SetLayerRecursively(child.gameObject, layerName); |
| | | } |
| | | } |
| | | |
| | | public static GameObject LoadUIPattern(string name) |
| | | { |
| | | return AssetDatabase.LoadAssetAtPath<GameObject>(string.Format("Assets/Editor/UIPattern/{0}.prefab", name)); |