//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Tuesday, October 31, 2017 //-------------------------------------------------------- using UnityEngine; using UnityEditor; using System.Collections; using UnityEngine.UI; using Snxxz.UI; public class PrefabCreateTool { [MenuItem("GameObject/UI/FunctionButton")] public static void CreateFunctionButton() { var instance = UIUtility.CreateWidget("FunctionButtonPattern", "FunctionButton"); if (instance != null) { var uiroot = GameObject.FindObjectOfType(); if (uiroot == null) { var prefab = BuiltInLoader.LoadPrefab("UIRoot"); var root = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity); root.name = "UIRoot"; uiroot = root.GetComponent(); } 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; } } [MenuItem("GameObject/UI/GeneralWin_1")] public static void CreateWindowPattern1() { var prefab = AssetDatabase.LoadAssetAtPath("Assets/Editor/UIPattern/GeneralWin.prefab"); var instance = GameObject.Instantiate(prefab) as GameObject; instance.name = "GeneralWin"; if (instance != null) { var uiroot = GameObject.FindObjectOfType(); if (uiroot == null) { var rootPrefab = BuiltInLoader.LoadPrefab("UIRoot"); var root = GameObject.Instantiate(rootPrefab, Vector3.zero, Quaternion.identity); root.name = "UIRoot"; uiroot = root.GetComponent(); } 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; } } [MenuItem("GameObject/UI/RewardGroup")] public static void CreateRewardGroup() { var prefab = AssetDatabase.LoadAssetAtPath("Assets/Editor/UIPattern/Container_Rewards.prefab"); var instance = GameObject.Instantiate(prefab) as GameObject; instance.name = "Container_Rewards"; if (instance != null) { var uiroot = GameObject.FindObjectOfType(); if (uiroot == null) { var rootPrefab = BuiltInLoader.LoadPrefab("UIRoot"); var root = GameObject.Instantiate(rootPrefab, Vector3.zero, Quaternion.identity); root.name = "UIRoot"; uiroot = root.GetComponent(); } 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; } } [MenuItem("GameObject/UI/CommonItemCell")] public static void CreateCommonItemCell() { var prefab = AssetDatabase.LoadAssetAtPath("Assets/Editor/UIPattern/CommonItemCell.prefab"); var instance = GameObject.Instantiate(prefab) as GameObject; instance.name = "CommonItemCell"; if (instance != null) { var uiroot = GameObject.FindObjectOfType(); if (uiroot == null) { var rootPrefab = BuiltInLoader.LoadPrefab("UIRoot"); var root = GameObject.Instantiate(rootPrefab, Vector3.zero, Quaternion.identity); root.name = "UIRoot"; uiroot = root.GetComponent(); } 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; } } [MenuItem("GameObject/UI/SortTable")] public static void CreateSortTable() { var prefab = AssetDatabase.LoadAssetAtPath("Assets/Editor/UIPattern/SortTable.prefab"); var instance = GameObject.Instantiate(prefab) as GameObject; instance.name = "SortTable"; if (instance != null) { var uiroot = GameObject.FindObjectOfType(); if (uiroot == null) { var rootPrefab = BuiltInLoader.LoadPrefab("UIRoot"); var root = GameObject.Instantiate(rootPrefab, Vector3.zero, Quaternion.identity); root.name = "UIRoot"; uiroot = root.GetComponent(); } 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; } } }