三国卡牌客户端基础资源仓库
yyl
2025-07-03 cec146fc3fe287928e075c79ece20a20a9b16b20
Assets/Editor/Tool/PrefabCreateTool.cs
@@ -1,12 +1,11 @@
//--------------------------------------------------------
//    [Author]:           第二世界
//    [Author]:           玩个游戏
//    [  Date ]:           Tuesday, October 31, 2017
//--------------------------------------------------------
using UnityEngine;
using UnityEditor;
using System.Collections;
using UnityEngine.UI;
using vnxbqy.UI;
public class PrefabCreateTool
@@ -41,7 +40,31 @@
        // }
        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)
@@ -111,7 +134,11 @@
    public static void CreateTextEx()
    {
        var instance = new GameObject("TextEx");
        instance.AddComponent<TextEx>();
        var text = instance.AddComponent<TextEx>();
        text.font = FontUtility.preferred;
        text.fontSize = 22;
        text.alignment = TextAnchor.MiddleCenter;
        text.raycastTarget = false;
        SetParent(instance);
    }
@@ -119,7 +146,8 @@
    public static void CreateImageEx()
    {
        var instance = new GameObject("ImageEx");
        instance.AddComponent<ImageEx>();
        var image = instance.AddComponent<ImageEx>();
        image.raycastTarget = false;
        SetParent(instance);
    }