From 184e096ddd40d2a1d178df726501bd48078e511c Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期三, 22 十月 2025 18:14:43 +0800
Subject: [PATCH] 图集更新

---
 Assets/Editor/UI/PSDTOUGUIProcessor.cs |  133 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 133 insertions(+), 0 deletions(-)

diff --git a/Assets/Editor/UI/PSDTOUGUIProcessor.cs b/Assets/Editor/UI/PSDTOUGUIProcessor.cs
index f95457b..47d4560 100644
--- a/Assets/Editor/UI/PSDTOUGUIProcessor.cs
+++ b/Assets/Editor/UI/PSDTOUGUIProcessor.cs
@@ -4,6 +4,8 @@
 using UnityEngine;
 using UnityEditor;
 using UnityEngine.UI;
+using System.IO;
+using System.Text;
 
 public class PSDTOUGUIProcessor
 {
@@ -47,4 +49,135 @@
             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()
+    {
+        GameObject go = Selection.activeGameObject;
+        if (go == null)
+        {
+            Debug.LogError("璇峰厛閫夋嫨涓�涓狦ameObject");
+            return;
+        }
+        
+        string className = go.name;
+
+        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))
+        {
+            Directory.CreateDirectory(targetFolder);
+        }
+        
+        string filePath = Path.Combine(targetFolder, className + ".cs");
+        
+        // 妫�鏌ユ枃浠舵槸鍚﹀凡瀛樺湪
+        if (File.Exists(filePath))
+        {
+            if (!EditorUtility.DisplayDialog("鏂囦欢宸插瓨鍦�", $"鏂囦欢 {className}.cs 宸插瓨鍦紝鏄惁瑕嗙洊锛�", "瑕嗙洊", "鍙栨秷"))
+            {
+                return;
+            }
+        }
+        
+        // 鐢熸垚鑴氭湰鍐呭
+        StringBuilder sb = new StringBuilder();
+        sb.AppendLine("using UnityEngine;");
+        sb.AppendLine("using System.Collections;");
+        sb.AppendLine("using System.Collections.Generic;");
+        sb.AppendLine("using UnityEngine.UI;");
+        sb.AppendLine("using DG.Tweening;");
+        sb.AppendLine("using Cysharp.Threading.Tasks;");
+        sb.AppendLine("");
+        sb.AppendLine($"public class {className} : UIBase");
+        sb.AppendLine("{");
+        sb.AppendLine("    // 缁勪欢寮曠敤");
+        sb.AppendLine("");
+        sb.AppendLine("    // 鐢熷懡鍛ㄦ湡");
+        sb.AppendLine("    protected override void InitComponent()");
+        sb.AppendLine("    {");
+        sb.AppendLine("        base.InitComponent();");
+        sb.AppendLine("        // 鍒濆鍖栫粍浠跺紩鐢� 缁戝畾鎸夐挳绛塙I缁勪欢浜嬩欢");
+        sb.AppendLine("    }");
+        sb.AppendLine("");
+        sb.AppendLine("    protected override void OnPreOpen()");
+        sb.AppendLine("    {");
+        sb.AppendLine("        base.OnPreOpen();");
+        sb.AppendLine("    }");
+        sb.AppendLine("");
+        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("    protected override void OnClose()");
+        sb.AppendLine("    {");
+        sb.AppendLine("        base.OnClose();");
+        sb.AppendLine("    }");
+        sb.AppendLine("");
+        sb.AppendLine("    protected override void NextFrameAfterOpen()");
+        sb.AppendLine("    {");
+        sb.AppendLine("        base.NextFrameAfterOpen();");
+        sb.AppendLine("    }");
+        sb.AppendLine("");
+        sb.AppendLine("    protected override void CompleteClose()");
+        sb.AppendLine("    {");
+        sb.AppendLine("        base.CompleteClose();");
+        sb.AppendLine("    }");
+        sb.AppendLine("}");
+        
+        // 鍐欏叆鏂囦欢
+        File.WriteAllText(filePath, sb.ToString(), Encoding.UTF8);
+        
+        Debug.Log($"UI鑴氭湰宸茬敓鎴�: {filePath}");
+        
+        // 鍒锋柊璧勬簮鏁版嵁搴撲互鏄剧ず鏂版枃浠�
+        AssetDatabase.Refresh();
+        
+        // 鎵撳紑鐢熸垚鐨勮剼鏈�
+        UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(filePath, 1);
+
+    }
 }
\ No newline at end of file

--
Gitblit v1.8.0