| //-------------------------------------------------------- | 
| //    [Author]:           第二世界 | 
| //    [  Date ]:           Tuesday, October 31, 2017 | 
| //-------------------------------------------------------- | 
| using UnityEngine; | 
| using UnityEditor; | 
| using System.Collections; | 
| using UnityEngine.UI; | 
| using vnxbqy.UI; | 
|   | 
|   | 
| public class PrefabCreateTool | 
| { | 
|     [MenuItem("GameObject/UI/UIRoot")] | 
|     public static UIRoot CreateUIRoot() | 
|     { | 
|         var uiroot = GameObject.FindObjectOfType<UIRoot>(); | 
|         if (uiroot == null) | 
|         { | 
|             var prefab = BuiltInLoader.LoadPrefab("UIRoot"); | 
|             var root = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity); | 
|             root.name = "UIRoot"; | 
|             uiroot = root.GetComponent<UIRoot>(); | 
|         } | 
|         return uiroot; | 
|     } | 
|   | 
|     public static void SetParent(GameObject instance, Transform parent = null) | 
|     { | 
|         if (instance == null) | 
|             return; | 
|         // var uiroot = CreateUIRoot(); | 
|         if (parent == null) | 
|             if (Selection.transforms != null && Selection.transforms.Length > 0) | 
|             { | 
|                 parent = Selection.transforms[0]; | 
|             } | 
|         // else | 
|         // { | 
|         //     parent = uiroot.normalCanvas.transform; | 
|         // } | 
|         instance.transform.SetParentEx(parent, Vector3.zero, Quaternion.identity, Vector3.one); | 
|         // PrefabUtility.DisconnectPrefabInstance(instance); | 
|         Selection.activeGameObject = instance; | 
|     } | 
|   | 
|     public static GameObject LoadUIPattern(string name) | 
|     { | 
|         return AssetDatabase.LoadAssetAtPath<GameObject>(string.Format("Assets/Editor/UIPattern/{0}.prefab", name)); | 
|     } | 
|   | 
|     [MenuItem("GameObject/UI/FunctionButton")] | 
|     public static void CreateFunctionButton() | 
|     { | 
|         var instance = UIUtility.CreateWidget("FunctionButtonPattern", "FunctionButton"); | 
|         SetParent(instance); | 
|     } | 
|   | 
|     [MenuItem("GameObject/UI/GeneralWin_1")] | 
|     public static void CreateWindowPattern1() | 
|     { | 
|         var prefab = LoadUIPattern("GeneralWin"); | 
|         var instance = GameObject.Instantiate(prefab) as GameObject; | 
|         instance.name = "GeneralWin"; | 
|         SetParent(instance); | 
|     } | 
|   | 
|     [MenuItem("GameObject/UI/RewardGroup")] | 
|     public static void CreateRewardGroup() | 
|     { | 
|         var prefab = LoadUIPattern("Container_Rewards"); | 
|         var instance = GameObject.Instantiate(prefab) as GameObject; | 
|         instance.name = "Container_Rewards"; | 
|         SetParent(instance); | 
|     } | 
|   | 
|     [MenuItem("GameObject/UI/CommonItemCell")] | 
|     public static void CreateCommonItemCell() | 
|     { | 
|         var prefab = LoadUIPattern("CommonItemCell"); | 
|         var instance = GameObject.Instantiate(prefab) as GameObject; | 
|         instance.name = "CommonItemCell"; | 
|         SetParent(instance); | 
|     } | 
|   | 
|     [MenuItem("GameObject/UI/SortTable")] | 
|     public static void CreateSortTable() | 
|     { | 
|         var prefab = LoadUIPattern("SortTable"); | 
|         var instance = GameObject.Instantiate(prefab) as GameObject; | 
|         instance.name = "SortTable"; | 
|         SetParent(instance); | 
|     } | 
|   | 
|     [MenuItem("GameObject/UI/TextEx")] | 
|     public static void CreateTextEx() | 
|     { | 
|         var instance = new GameObject("TextEx"); | 
|         instance.AddComponent<TextEx>(); | 
|         SetParent(instance); | 
|     } | 
|   | 
|     [MenuItem("GameObject/UI/ImageEx")] | 
|     public static void CreateImageEx() | 
|     { | 
|         var instance = new GameObject("ImageEx"); | 
|         instance.AddComponent<ImageEx>(); | 
|         SetParent(instance); | 
|     } | 
|   | 
|     [MenuItem("GameObject/UI/通用按钮")] | 
|     public static void CreateButtonEx() | 
|     { | 
|         var button = UIUtility.CreateWidget("CommonButton", "CommonButton"); | 
|         SetParent(button); | 
|     } | 
|   | 
|     [MenuItem("GameObject/UI/红点")] | 
|     public static void CreateRedPoint() | 
|     { | 
|         var button = UIUtility.CreateWidget("RedPoint", "RedPoint"); | 
|         SetParent(button); | 
|     } | 
|   | 
|     [MenuItem("GameObject/UI/SecondFrameLoad")] | 
|     public static void CreateSecondFrameLoad() | 
|     { | 
|         var prefab = LoadUIPattern("SecondFrameLoad"); | 
|         var instance = GameObject.Instantiate(prefab) as GameObject; | 
|         instance.name = "SecondFrameLoad"; | 
|         SetParent(instance); | 
|     } | 
|   | 
|   | 
| } |