三国卡牌客户端基础资源仓库
yyl
2025-08-25 214fe94eaf7f09741a7857775dfffe8c3b83c75c
Assets/Editor/UI/PSDTOUGUIProcessor.cs
@@ -49,6 +49,35 @@
            g.raycastTarget = false;
        }
    }
    private static List<string> SplitByCamelCase(string input)
    {
        if (string.IsNullOrEmpty(input))
            return new List<string>();
        var result = new List<string>();
        var currentWord = new StringBuilder();
        currentWord.Append(input[0]);
        for (int i = 1; i < input.Length; i++)
        {
            if (char.IsUpper(input[i]))
            {
                // 遇到大写字母,表示新单词开始
                result.Add(currentWord.ToString());
                currentWord.Clear();
            }
            currentWord.Append(input[i]);
        }
        // 添加最后一个单词
        if (currentWord.Length > 0)
        {
            result.Add(currentWord.ToString());
        }
        return result;
    }
    
    [UnityEditor.MenuItem("GameObject/生成UI脚本", false, 10)]
    public static void GenerateUIScript()
@@ -61,8 +90,16 @@
        }
        
        string className = go.name;
        string targetFolder = Path.Combine(Application.dataPath, "Scripts/Main/UI");
        List<string> caseList = SplitByCamelCase(className);
        string targetFolder = Path.Combine(Application.dataPath, "Scripts/Main/System");
        
        if (Directory.Exists(targetFolder + "/" + caseList[0]))
        {
            targetFolder += "/" + caseList[0];
        }
        // 确保目标文件夹存在
        if (!Directory.Exists(targetFolder))
        {
@@ -94,35 +131,40 @@
        sb.AppendLine("    // 组件引用");
        sb.AppendLine("");
        sb.AppendLine("    // 生命周期");
        sb.AppendLine("    protected override void Awake()");
        sb.AppendLine("    protected override void InitComponent()");
        sb.AppendLine("    {");
        sb.AppendLine("        base.Awake();");
        sb.AppendLine("        // 初始化组件引用");
        sb.AppendLine("        base.InitComponent();");
        sb.AppendLine("        // 初始化组件引用 绑定按钮等UI组件事件");
        sb.AppendLine("    }");
        sb.AppendLine("");
        sb.AppendLine("    protected override void Start()");
        sb.AppendLine("    protected override void OnPreOpen()");
        sb.AppendLine("    {");
        sb.AppendLine("        base.Start();");
        sb.AppendLine("        // 初始化数据");
        sb.AppendLine("        base.OnPreOpen();");
        sb.AppendLine("    }");
        sb.AppendLine("");
        sb.AppendLine("    // UI事件");
        sb.AppendLine("    protected override void OnPreClose()");
        sb.AppendLine("    {");
        sb.AppendLine("        base.OnPreClose();");
        sb.AppendLine("    }");
        sb.AppendLine("");
        sb.AppendLine("    protected override void OnOpen()");
        sb.AppendLine("    {");
        sb.AppendLine("        base.OnOpen();");
        sb.AppendLine("        // 窗口打开时的逻辑");
        sb.AppendLine("    }");
        sb.AppendLine("");
        sb.AppendLine("    protected override void OnClose()");
        sb.AppendLine("    {");
        sb.AppendLine("        base.OnClose();");
        sb.AppendLine("        // 窗口关闭时的逻辑");
        sb.AppendLine("    }");
        sb.AppendLine("");
        sb.AppendLine("    public override void Refresh()");
        sb.AppendLine("    protected override void NextFrameAfterOpen()");
        sb.AppendLine("    {");
        sb.AppendLine("        base.Refresh();");
        sb.AppendLine("        // 刷新UI显示");
        sb.AppendLine("        base.NextFrameAfterOpen();");
        sb.AppendLine("    }");
        sb.AppendLine("");
        sb.AppendLine("    protected override void CompleteClose()");
        sb.AppendLine("    {");
        sb.AppendLine("        base.CompleteClose();");
        sb.AppendLine("    }");
        sb.AppendLine("}");