| | |
| | | |
| | | 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"); |
| | | if (instance != null) |
| | | { |
| | | 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>(); |
| | | } |
| | | |
| | | Transform 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; |
| | | } |
| | | |
| | | SetParent(instance); |
| | | } |
| | | |
| | | [MenuItem("GameObject/UI/GeneralWin_1")] |
| | | public static void CreateWindowPattern1() |
| | | { |
| | | var prefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Editor/UIPattern/GeneralWin.prefab"); |
| | | var prefab = LoadUIPattern("GeneralWin"); |
| | | var instance = GameObject.Instantiate(prefab) as GameObject; |
| | | instance.name = "GeneralWin"; |
| | | |
| | | if (instance != null) |
| | | { |
| | | var uiroot = GameObject.FindObjectOfType<UIRoot>(); |
| | | if (uiroot == null) |
| | | { |
| | | var rootPrefab = Resources.Load<GameObject>("UI/Prefabs/UIRoot"); |
| | | var root = GameObject.Instantiate(rootPrefab, Vector3.zero, Quaternion.identity); |
| | | root.name = "UIRoot"; |
| | | uiroot = root.GetComponent<UIRoot>(); |
| | | } |
| | | |
| | | Transform 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; |
| | | } |
| | | SetParent(instance); |
| | | } |
| | | |
| | | [MenuItem("GameObject/UI/RewardGroup")] |
| | | public static void CreateRewardGroup() |
| | | { |
| | | var prefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Editor/UIPattern/Container_Rewards.prefab"); |
| | | var prefab = LoadUIPattern("Container_Rewards"); |
| | | var instance = GameObject.Instantiate(prefab) as GameObject; |
| | | instance.name = "Container_Rewards"; |
| | | |
| | | if (instance != null) |
| | | { |
| | | var uiroot = GameObject.FindObjectOfType<UIRoot>(); |
| | | if (uiroot == null) |
| | | { |
| | | var rootPrefab = Resources.Load<GameObject>("UI/Prefabs/UIRoot"); |
| | | var root = GameObject.Instantiate(rootPrefab, Vector3.zero, Quaternion.identity); |
| | | root.name = "UIRoot"; |
| | | uiroot = root.GetComponent<UIRoot>(); |
| | | } |
| | | |
| | | Transform 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; |
| | | } |
| | | SetParent(instance); |
| | | } |
| | | |
| | | [MenuItem("GameObject/UI/CommonItemCell")] |
| | | public static void CreateCommonItemCell() |
| | | { |
| | | var prefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Editor/UIPattern/CommonItemCell.prefab"); |
| | | var prefab = LoadUIPattern("CommonItemCell"); |
| | | var instance = GameObject.Instantiate(prefab) as GameObject; |
| | | instance.name = "CommonItemCell"; |
| | | |
| | | if (instance != null) |
| | | { |
| | | var uiroot = GameObject.FindObjectOfType<UIRoot>(); |
| | | if (uiroot == null) |
| | | { |
| | | var rootPrefab = Resources.Load<GameObject>("UI/Prefabs/UIRoot"); |
| | | var root = GameObject.Instantiate(rootPrefab, Vector3.zero, Quaternion.identity); |
| | | root.name = "UIRoot"; |
| | | uiroot = root.GetComponent<UIRoot>(); |
| | | } |
| | | |
| | | Transform 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; |
| | | } |
| | | |
| | | SetParent(instance); |
| | | } |
| | | |
| | | [MenuItem("GameObject/UI/SortTable")] |
| | | public static void CreateSortTable() |
| | | { |
| | | var prefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Editor/UIPattern/SortTable.prefab"); |
| | | var prefab = LoadUIPattern("SortTable"); |
| | | var instance = GameObject.Instantiate(prefab) as GameObject; |
| | | instance.name = "SortTable"; |
| | | |
| | | if (instance != null) |
| | | { |
| | | var uiroot = GameObject.FindObjectOfType<UIRoot>(); |
| | | if (uiroot == null) |
| | | { |
| | | var rootPrefab = Resources.Load<GameObject>("UI/Prefabs/UIRoot"); |
| | | var root = GameObject.Instantiate(rootPrefab, Vector3.zero, Quaternion.identity); |
| | | root.name = "UIRoot"; |
| | | uiroot = root.GetComponent<UIRoot>(); |
| | | } |
| | | |
| | | Transform 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; |
| | | } |
| | | 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/SecondFrameLoad")] |
| | | public static void CreateSecondFrameLoad() |
| | | { |
| | | var prefab = LoadUIPattern("SecondFrameLoad"); |
| | | var instance = GameObject.Instantiate(prefab) as GameObject; |
| | | instance.name = "SecondFrameLoad"; |
| | | SetParent(instance); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |