From 67369b670340cf6369a96857555ca643c1acde36 Mon Sep 17 00:00:00 2001 From: lwb <q3213421wrwqr> Date: 星期四, 10 十二月 2020 16:12:51 +0800 Subject: [PATCH] 9527 一些快捷创建预制件的右键菜单,去掉luaide 版本管理 --- Assets/Editor/Tool/PrefabCreateTool.cs | 193 +++++++++++++++++------------------------------ 1 files changed, 70 insertions(+), 123 deletions(-) diff --git a/Assets/Editor/Tool/PrefabCreateTool.cs b/Assets/Editor/Tool/PrefabCreateTool.cs index 2fd9ee7..bfe36ba 100644 --- a/Assets/Editor/Tool/PrefabCreateTool.cs +++ b/Assets/Editor/Tool/PrefabCreateTool.cs @@ -11,23 +11,26 @@ public class PrefabCreateTool { - - [MenuItem("GameObject/UI/FunctionButton")] - public static void CreateFunctionButton() + [MenuItem("GameObject/UI/UIRoot")] + public static UIRoot CreateUIRoot() { - var instance = UIUtility.CreateWidget("FunctionButtonPattern", "FunctionButton"); - if (instance != null) + var uiroot = GameObject.FindObjectOfType<UIRoot>(); + if (uiroot == 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>(); - } + var prefab = BuiltInLoader.LoadPrefab("UIRoot"); + var root = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity); + root.name = "UIRoot"; + uiroot = root.GetComponent<UIRoot>(); + } + return uiroot; + } - Transform parent = null; + 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]; @@ -36,12 +39,17 @@ { parent = uiroot.normalCanvas.transform; } + instance.transform.SetParentEx(parent, Vector3.zero, Quaternion.identity, Vector3.one); + // PrefabUtility.DisconnectPrefabInstance(instance); + Selection.activeGameObject = instance; + } - instance.transform.SetParentEx(parent, Vector3.zero, Quaternion.identity, Vector3.one); - PrefabUtility.DisconnectPrefabInstance(instance); - Selection.activeGameObject = instance; - } + [MenuItem("GameObject/UI/FunctionButton")] + public static void CreateFunctionButton() + { + var instance = UIUtility.CreateWidget("FunctionButtonPattern", "FunctionButton"); + SetParent(instance); } [MenuItem("GameObject/UI/GeneralWin_1")] @@ -50,32 +58,7 @@ var prefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Editor/UIPattern/GeneralWin.prefab"); var instance = GameObject.Instantiate(prefab) as GameObject; instance.name = "GeneralWin"; - - if (instance != null) - { - var uiroot = GameObject.FindObjectOfType<UIRoot>(); - if (uiroot == null) - { - var rootPrefab = BuiltInLoader.LoadPrefab("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")] @@ -84,32 +67,7 @@ var prefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Editor/UIPattern/Container_Rewards.prefab"); var instance = GameObject.Instantiate(prefab) as GameObject; instance.name = "Container_Rewards"; - - if (instance != null) - { - var uiroot = GameObject.FindObjectOfType<UIRoot>(); - if (uiroot == null) - { - var rootPrefab = BuiltInLoader.LoadPrefab("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")] @@ -118,33 +76,7 @@ var prefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Editor/UIPattern/CommonItemCell.prefab"); var instance = GameObject.Instantiate(prefab) as GameObject; instance.name = "CommonItemCell"; - - if (instance != null) - { - var uiroot = GameObject.FindObjectOfType<UIRoot>(); - if (uiroot == null) - { - var rootPrefab = BuiltInLoader.LoadPrefab("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")] @@ -153,33 +85,48 @@ var prefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Editor/UIPattern/SortTable.prefab"); var instance = GameObject.Instantiate(prefab) as GameObject; instance.name = "SortTable"; - - if (instance != null) - { - var uiroot = GameObject.FindObjectOfType<UIRoot>(); - if (uiroot == null) - { - var rootPrefab = BuiltInLoader.LoadPrefab("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/ButtonEx")] + public static void CreateButtonEx() + { + var button = new GameObject("ButtonEx"); + var btnEx = button.AddComponent<ButtonEx>(); + var imgEx = button.AddComponent<ImageEx>(); + btnEx.targetGraphic = imgEx; + SetParent(button); + var text = new GameObject("TextEx"); + text.AddComponent<TextEx>(); + SetParent(text, button.transform); + } + + [MenuItem("GameObject/UI/SecondFrameLoader")] + public static void CreateSecondFrameLoader() + { + var go = new GameObject("SecondFrameLoader"); + go.AddComponent<SecondFrameLoader>(); + SetParent(go); + } + + + } -- Gitblit v1.8.0