From e4e502816f0641ee6b76cfae38f290ba8b803af1 Mon Sep 17 00:00:00 2001 From: yyl <yyl> Date: 星期四, 22 五月 2025 18:12:17 +0800 Subject: [PATCH] 登录流程前的所有预备流程 --- Assets/Editor/UI/PSDTOUGUIProcessor.cs | 91 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 91 insertions(+), 0 deletions(-) diff --git a/Assets/Editor/UI/PSDTOUGUIProcessor.cs b/Assets/Editor/UI/PSDTOUGUIProcessor.cs index f95457b..42da342 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,93 @@ g.raycastTarget = false; } } + + [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; + string targetFolder = Path.Combine(Application.dataPath, "Scripts/Main/UI"); + + // 纭繚鐩爣鏂囦欢澶瑰瓨鍦� + 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 Awake()"); + sb.AppendLine(" {"); + sb.AppendLine(" base.Awake();"); + sb.AppendLine(" // 鍒濆鍖栫粍浠跺紩鐢�"); + sb.AppendLine(" }"); + sb.AppendLine(""); + sb.AppendLine(" protected override void Start()"); + sb.AppendLine(" {"); + sb.AppendLine(" base.Start();"); + sb.AppendLine(" // 鍒濆鍖栨暟鎹�"); + sb.AppendLine(" }"); + sb.AppendLine(""); + sb.AppendLine(" // UI浜嬩欢"); + 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(" {"); + sb.AppendLine(" base.Refresh();"); + sb.AppendLine(" // 鍒锋柊UI鏄剧ず"); + 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