| | |
| | | //-------------------------------------------------------- |
| | | // [Author]: 第二世界 |
| | | // [Author]: 玩个游戏 |
| | | // [ Date ]: Tuesday, October 31, 2017 |
| | | //-------------------------------------------------------- |
| | | using UnityEngine; |
| | | using UnityEditor; |
| | | using System.Collections; |
| | | using UnityEngine.UI; |
| | | using vnxbqy.UI; |
| | | |
| | | |
| | | public class PrefabCreateTool |
| | |
| | | // } |
| | | 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) |
| | |
| | | [MenuItem("GameObject/UI/特效")] |
| | | public static void CreateUIEffect() |
| | | { |
| | | var instance = new GameObject("UIEffect"); |
| | | instance.AddComponent<UIEffect>(); |
| | | var instance = new GameObject("UIEffectPlayer"); |
| | | instance.AddComponent<UIEffectPlayer>(); |
| | | instance.AddComponent<RectTransform>(); |
| | | SetParent(instance); |
| | | } |
| | |
| | | public static void CreateTextEx() |
| | | { |
| | | var instance = new GameObject("TextEx"); |
| | | instance.AddComponent<TextEx>(); |
| | | var text = instance.AddComponent<TextEx>(); |
| | | text.font = FontUtility.preferred; |
| | | text.fontSize = 22; |
| | | text.alignment = TextAnchor.MiddleCenter; |
| | | text.raycastTarget = false; |
| | | SetParent(instance); |
| | | } |
| | | |
| | |
| | | public static void CreateImageEx() |
| | | { |
| | | var instance = new GameObject("ImageEx"); |
| | | instance.AddComponent<ImageEx>(); |
| | | var image = instance.AddComponent<ImageEx>(); |
| | | image.raycastTarget = false; |
| | | SetParent(instance); |
| | | } |
| | | |
| | |
| | | SetParent(button); |
| | | } |
| | | |
| | | [MenuItem("GameObject/UI/SecondFrameLoad")] |
| | | [MenuItem("GameObject/UI/二级框")] |
| | | public static void CreateSecondFrameLoad() |
| | | { |
| | | var prefab = LoadUIPattern("SecondFrameLoad"); |