三国卡牌客户端基础资源仓库
hch
8 天以前 7f957ecb475adb30eb692884d22412b765fa1a7d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Tuesday, October 31, 2017
//--------------------------------------------------------
using UnityEngine;
using UnityEditor;
using System.Collections;
using UnityEngine.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);
        
        // 设置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)
    {
        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/自选商品")]
    public static void CreateCommonItemCell()
    {
        var prefab = LoadUIPattern("CustomizedItemCell");
        var instance = GameObject.Instantiate(prefab) as GameObject;
        instance.name = "CustomizedItemCell";
        SetParent(instance);
    }
    [MenuItem("GameObject/UI/特效")]
    public static void CreateUIEffect()
    {
        var instance = new GameObject("UIEffect");
        instance.AddComponent<UIEffect>();
        instance.AddComponent<RectTransform>();
        SetParent(instance);
    }
 
    [MenuItem("GameObject/UI/ItemCell")]
    public static void CreateItemCell()
    {
        var button = UIUtility.CreateWidget("ItemCell", "ItemCell");
        SetParent(button);
    }
 
    [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");
        var text = instance.AddComponent<TextEx>();
        text.font = FontUtility.preferred;
        text.fontSize = 22;
        text.alignment = TextAnchor.MiddleCenter;
        text.raycastTarget = false;
        SetParent(instance);
    }
 
    [MenuItem("GameObject/UI/ImageEx")]
    public static void CreateImageEx()
    {
        var instance = new GameObject("ImageEx");
        var image = instance.AddComponent<ImageEx>();
        image.raycastTarget = false;
        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);
    }
 
 
}