From 0941d5584dbb4287005d541588fb956155c71365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=80=9D=E6=B5=B7?= <10001@qq.com> Date: Fri, 21 Feb 2025 10:22:11 +0800 Subject: [PATCH] aaa --- Editor/AlicizaX.UI.Extension.Editor.asmdef | 3 +- Editor/UIExtension/StaticKey.meta | 3 - .../StaticKey/LocalizeStaticKey.cs | 90 ------- .../StaticKey/LocalizeStaticKey.cs.meta | 3 - .../UIExtension/Text/UXTextMeshProEditor.cs | 77 +++--- Editor/UIExtension/UIButtonSuper.cs | 56 ++++ Editor/UIExtension/UIButtonSuper.cs.meta | 3 + Runtime/UGUIExtension/Button.meta | 3 + Runtime/UGUIExtension/Button/UIButtonSuper.cs | 242 ++++++++++++++++++ .../Button/UIButtonSuper.cs.meta | 3 + Runtime/UGUIExtension/Text/UXTextMeshPro.cs | 1 - 11 files changed, 355 insertions(+), 129 deletions(-) delete mode 100644 Editor/UIExtension/StaticKey.meta delete mode 100644 Editor/UIExtension/StaticKey/LocalizeStaticKey.cs delete mode 100644 Editor/UIExtension/StaticKey/LocalizeStaticKey.cs.meta create mode 100644 Editor/UIExtension/UIButtonSuper.cs create mode 100644 Editor/UIExtension/UIButtonSuper.cs.meta create mode 100644 Runtime/UGUIExtension/Button.meta create mode 100644 Runtime/UGUIExtension/Button/UIButtonSuper.cs create mode 100644 Runtime/UGUIExtension/Button/UIButtonSuper.cs.meta diff --git a/Editor/AlicizaX.UI.Extension.Editor.asmdef b/Editor/AlicizaX.UI.Extension.Editor.asmdef index cc40850..917e3d4 100644 --- a/Editor/AlicizaX.UI.Extension.Editor.asmdef +++ b/Editor/AlicizaX.UI.Extension.Editor.asmdef @@ -5,7 +5,8 @@ "GUID:6546d7765b4165b40850b3667f981c26", "GUID:760f1778adc613f49a4394fb41ff0bbc", "GUID:75b6f2078d190f14dbda4a5b747d709c", - "GUID:a19b414bea3b97240a91aeab9a8eab36" + "GUID:a19b414bea3b97240a91aeab9a8eab36", + "GUID:83a193b118cfbef48a344187e07f53bb" ], "includePlatforms": [ "Editor" diff --git a/Editor/UIExtension/StaticKey.meta b/Editor/UIExtension/StaticKey.meta deleted file mode 100644 index 6e981ab..0000000 --- a/Editor/UIExtension/StaticKey.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 618191a0ed5f4928a1686d6954d7cd1a -timeCreated: 1738834271 \ No newline at end of file diff --git a/Editor/UIExtension/StaticKey/LocalizeStaticKey.cs b/Editor/UIExtension/StaticKey/LocalizeStaticKey.cs deleted file mode 100644 index 74367fd..0000000 --- a/Editor/UIExtension/StaticKey/LocalizeStaticKey.cs +++ /dev/null @@ -1,90 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using AlicizaX.Localization.Runtime; -using AlicizaX.Runtime; -using Newtonsoft.Json; -using UnityEditor; -using UnityEngine; - -namespace AlicizaX.UI.Extension.Editor -{ - internal class LocalizeItem - { - public string key; - public string ChineseSimplified; - public string English; - public string Japanese; - } - - internal static class LocalizeStaticKey - { - static readonly string LocalizeStaticConfigPath = "Assets/AssetArt/Configs/json/tables_tblocalization.json"; - - private static bool IsLoaded = false; - - private static List LocalizeItems; - private static Dictionary> LocalizeDic; - - - /// - /// 获取所有静态Keys - /// - /// - public static string[] GetAllStaticKeys() - { - LoadStaticKey(); - List keys = LocalizeItems.Select(v => v.key).ToList(); - keys.Insert(0, "None"); - return keys.ToArray(); - } - - public static string GetText(string key) - { - LoadStaticKey(); - Language languageType = (Language)EditorPrefs.GetInt(LocalizationComponent.PrefsKey); - string value = key; - - if (LocalizeDic.TryGetValue(key, out Dictionary dic)) - { - dic.TryGetValue(languageType, out value); - } - - return value; - } - - [MenuItem("开发工具/Force Reload多语言静态Key")] - public static void ForceReload() - { - IsLoaded = false; - LoadStaticKey(); - } - - static void LoadStaticKey() - { - if (IsLoaded) return; - if (!File.Exists(LocalizeStaticConfigPath)) - { - Debug.LogError("静态多语言文本文件不存在!"); - return; - } - - TextAsset textAsset = - UnityEditor.AssetDatabase.LoadAssetAtPath(LocalizeStaticConfigPath); - - LocalizeItems = JsonConvert.DeserializeObject>(textAsset.text); - - LocalizeDic = new Dictionary>(); - foreach (var v in LocalizeItems) - { - Dictionary valueDic = new Dictionary(); - valueDic.Add(Language.ChineseSimplified, v.ChineseSimplified); - valueDic.Add(Language.English, v.English); - valueDic.Add(Language.Japanese, v.Japanese); - LocalizeDic.Add(v.key, valueDic); - } - - IsLoaded = true; - } - } -} diff --git a/Editor/UIExtension/StaticKey/LocalizeStaticKey.cs.meta b/Editor/UIExtension/StaticKey/LocalizeStaticKey.cs.meta deleted file mode 100644 index 53e7bd0..0000000 --- a/Editor/UIExtension/StaticKey/LocalizeStaticKey.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: d65abc05d0b640199d1f55346b3c4f1b -timeCreated: 1738834272 \ No newline at end of file diff --git a/Editor/UIExtension/Text/UXTextMeshProEditor.cs b/Editor/UIExtension/Text/UXTextMeshProEditor.cs index 959010e..1e39395 100644 --- a/Editor/UIExtension/Text/UXTextMeshProEditor.cs +++ b/Editor/UIExtension/Text/UXTextMeshProEditor.cs @@ -1,5 +1,8 @@ -using AlicizaX.UI.Extension.Editor; +using System.Collections.Generic; +using AlicizaX.Localization.Editor; +using AlicizaX.Localization.Runtime; using UnityEditor; +using UnityEngine; namespace UnityEngine.UI { @@ -9,59 +12,71 @@ namespace UnityEngine.UI { private SerializedProperty text; private SerializedProperty localizationID; + private List _entries; protected override void OnEnable() { text = serializedObject.FindProperty("m_text"); localizationID = serializedObject.FindProperty("m_localizationID"); base.OnEnable(); + _entries = LocalizationMasterConfig.GetAllEntries(); } - protected override void OnDisable() - { - base.OnDisable(); - } - - public override void OnInspectorGUI() { serializedObject.Update(); bool isPlay = Application.isPlaying; - EditorGUI.BeginDisabledGroup(isPlay); - string[] keys = LocalizeStaticKey.GetAllStaticKeys(); - int index = -1; - for (int i = 0; i < keys.Length; i++) + // 准备Key列表 + string[] keys = new string[_entries.Count]; + for (int i = 0; i < _entries.Count; i++) { - if (localizationID.stringValue == keys[i]) + keys[i] = _entries[i].ID; + } + + // Key选择逻辑 + EditorGUI.BeginDisabledGroup(isPlay); + { + int currentIndex = -1; + for (int i = 0; i < keys.Length; i++) { - index = i; - break; + if (localizationID.stringValue == keys[i]) + { + currentIndex = i; + break; + } + } + + // 显示警告如果Key不存在 + if (currentIndex == -1 && !string.IsNullOrEmpty(localizationID.stringValue)) + { + EditorGUILayout.HelpBox("当前Key在配置文件中不存在", MessageType.Warning); + } + + // 绘制Key下拉菜单 + int newIndex = EditorGUILayout.Popup("本地化Key", currentIndex, keys); + if (newIndex != currentIndex && newIndex >= 0) + { + localizationID.stringValue = keys[newIndex]; + text.stringValue = _entries[newIndex].ChineseSimplified; } } - - if (index == -1) - { - EditorGUILayout.HelpBox("对应的多语言Key找不到!请重新配置", MessageType.Warning); - } - - int selectedIndex = EditorGUILayout.Popup("Key", index, keys); - if (selectedIndex != index) - { - localizationID.stringValue = keys[selectedIndex]; - } - - EditorGUI.EndDisabledGroup(); + // 显示预览信息 EditorGUI.BeginDisabledGroup(true); - EditorGUILayout.PropertyField(localizationID, new GUIContent("key")); - if (!string.IsNullOrEmpty(localizationID.stringValue) && localizationID.stringValue != "None") { - text.stringValue = LocalizeStaticKey.GetText(localizationID.stringValue); + EditorGUILayout.PropertyField(localizationID); + if (!string.IsNullOrEmpty(localizationID.stringValue)) + { + var entry = _entries.Find(e => e.ID == localizationID.stringValue); + if (entry != null) + { + EditorGUILayout.TextField("当前文本预览", entry.ChineseSimplified); + } + } } - EditorGUI.EndDisabledGroup(); serializedObject.ApplyModifiedProperties(); diff --git a/Editor/UIExtension/UIButtonSuper.cs b/Editor/UIExtension/UIButtonSuper.cs new file mode 100644 index 0000000..5508a34 --- /dev/null +++ b/Editor/UIExtension/UIButtonSuper.cs @@ -0,0 +1,56 @@ +namespace AlicizaX.UI.Extension.Editor +{ + using AlicizaX.UI.Extension; + using UnityEditor; + using UnityEditor.UI; + + [CustomEditor(typeof(UIButtonSuper), true)] + [CanEditMultipleObjects] + public class UIButtonSuperEditor : ButtonEditor + { + private SerializedProperty m_ButtonUISounds; + private SerializedProperty m_CanClick; + private SerializedProperty m_CanDoubleClick; + private SerializedProperty m_DoubleClickIntervalTime; + private SerializedProperty onDoubleClick; + + private SerializedProperty m_CanLongPress; + private SerializedProperty m_ResponseOnceByPress; + private SerializedProperty m_LongPressDurationTime; + private SerializedProperty onPress; + + protected override void OnEnable() + { + base.OnEnable(); + + m_ButtonUISounds = serializedObject.FindProperty("m_ButtonUISounds"); + m_CanClick = serializedObject.FindProperty("m_CanClick"); + m_CanDoubleClick = serializedObject.FindProperty("m_CanDoubleClick"); + m_DoubleClickIntervalTime = serializedObject.FindProperty("m_DoubleClickIntervalTime"); + onDoubleClick = serializedObject.FindProperty("onDoubleClick"); + + m_CanLongPress = serializedObject.FindProperty("m_CanLongPress"); + m_ResponseOnceByPress = serializedObject.FindProperty("m_ResponseOnceByPress"); + m_LongPressDurationTime = serializedObject.FindProperty("m_LongPressDurationTime"); + onPress = serializedObject.FindProperty("onPress"); + } + + public override void OnInspectorGUI() + { + base.OnInspectorGUI(); + serializedObject.Update(); + EditorGUILayout.PropertyField(m_ButtonUISounds); //显示我们创建的属性 + EditorGUILayout.PropertyField(m_CanClick); //显示我们创建的属性 + EditorGUILayout.Space(); //空行 + EditorGUILayout.PropertyField(m_CanDoubleClick); //显示我们创建的属性 + EditorGUILayout.PropertyField(m_DoubleClickIntervalTime); //显示我们创建的属性 + EditorGUILayout.PropertyField(onDoubleClick); //显示我们创建的属性 + EditorGUILayout.Space(); //空行 + EditorGUILayout.PropertyField(m_CanLongPress); //显示我们创建的属性 + EditorGUILayout.PropertyField(m_ResponseOnceByPress); //显示我们创建的属性 + EditorGUILayout.PropertyField(m_LongPressDurationTime); //显示我们创建的属性 + EditorGUILayout.PropertyField(onPress); //显示我们创建的属性 + serializedObject.ApplyModifiedProperties(); + } + } +} diff --git a/Editor/UIExtension/UIButtonSuper.cs.meta b/Editor/UIExtension/UIButtonSuper.cs.meta new file mode 100644 index 0000000..dd542e2 --- /dev/null +++ b/Editor/UIExtension/UIButtonSuper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f9c7e374daba4ee8a1092a930327fa2f +timeCreated: 1740102365 \ No newline at end of file diff --git a/Runtime/UGUIExtension/Button.meta b/Runtime/UGUIExtension/Button.meta new file mode 100644 index 0000000..0ce2e6c --- /dev/null +++ b/Runtime/UGUIExtension/Button.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6959ce6dfcdb41dbb548a7472f65626a +timeCreated: 1740102262 \ No newline at end of file diff --git a/Runtime/UGUIExtension/Button/UIButtonSuper.cs b/Runtime/UGUIExtension/Button/UIButtonSuper.cs new file mode 100644 index 0000000..925059a --- /dev/null +++ b/Runtime/UGUIExtension/Button/UIButtonSuper.cs @@ -0,0 +1,242 @@ +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.EventSystems; +using System; +using UnityEngine.UI; + +namespace AlicizaX.UI.Extension +{ + public enum ButtonSoundType + { + Down, + Up, + Click, + Enter, + Exit, + Drag + } + + [Serializable] + public class ButtonSoundCell + { + public ButtonSoundType ButtonSoundType = ButtonSoundType.Click; + public int ButtonUISoundName = 10007; + } + + public delegate void ButtonBeginDragCallback(PointerEventData eventData); + + public delegate void ButtonDragCallback(PointerEventData eventData); + + public delegate void ButtonEndDragCallback(PointerEventData eventData); + + public class UIButtonSuper : Button, IBeginDragHandler, IDragHandler, IEndDragHandler + { + + public List m_ButtonUISounds = new List(); + + [Tooltip("是否可以点击")] public bool m_CanClick = true; + [Tooltip("是否可以双击")] public bool m_CanDoubleClick = false; + [Tooltip("双击间隔时长")] public float m_DoubleClickIntervalTime = 0.1f; + [Tooltip("双击事件")] public ButtonClickedEvent onDoubleClick; + [Tooltip("是否可以长按")] public bool m_CanLongPress = false; + [Tooltip("长按是否只响应一次")] public bool m_ResponseOnceByPress = false; + [Tooltip("长按满足间隔")] public float m_LongPressDurationTime = 1; + + [Tooltip("长按事件")] public ButtonClickedEvent onPress; + + //public ButtonClickedEvent onClick; + public ButtonBeginDragCallback onBeginDrag; + public ButtonDragCallback onDrag; + public ButtonEndDragCallback onEndDrag; + + private bool isDown = false; + private bool isPress = false; + private bool isDownExit = false; + private float downTime = 0; + + private int fingerId = int.MinValue; + + public bool IsDraging + { + get { return fingerId != int.MinValue; } + } //摇杆拖拽状态 + + public int FingerId + { + get { return fingerId; } + } + + private float clickIntervalTime = 0; + private int clickTimes = 0; + + void Update() + { + if (isDown) + { + if (!m_CanLongPress) + { + return; + } + + if (m_ResponseOnceByPress && isPress) + { + return; + } + + downTime += Time.deltaTime; + if (downTime > m_LongPressDurationTime) + { + isPress = true; + onPress.Invoke(); + } + } + + if (clickTimes >= 1) + { + if (!m_CanLongPress && !m_CanDoubleClick && m_CanClick) + { + onClick.Invoke(); + clickTimes = 0; + } + else + { + clickIntervalTime += Time.deltaTime; + if (clickIntervalTime >= m_DoubleClickIntervalTime) + { + if (clickTimes >= 2) + { + if (m_CanDoubleClick) + { + onDoubleClick.Invoke(); + } + } + else + { + if (m_CanClick) + { + onClick.Invoke(); + } + } + + clickTimes = 0; + clickIntervalTime = 0; + } + } + } + } + + /// + /// 是否按钮按下 + /// + public bool IsDown + { + get { return isDown; } + } + + /// + /// 是否按钮长按 + /// + public bool IsPress + { + get { return isPress; } + } + + /// + /// 是否按钮按下后离开按钮位置 + /// + public bool IsDownExit + { + get { return isDownExit; } + } + + public ButtonSoundCell GetButtonSound(ButtonSoundType buttonSoundType) + { + foreach (var buttonSound in m_ButtonUISounds) + { + if (buttonSound.ButtonSoundType == buttonSoundType) + { + return buttonSound; + } + } + + return null; + } + + private void PlayButtonSound(ButtonSoundType buttonSoundType) + { + ButtonSoundCell buttonSound = GetButtonSound(buttonSoundType); + if (buttonSound == null) + { + return; + } + // AlicizaFramework.SystemModule.Audio.Play(buttonSound.ButtonUISoundName); + } + + public override void OnPointerEnter(PointerEventData eventData) + { + base.OnPointerEnter(eventData); + PlayButtonSound(ButtonSoundType.Enter); + } + + public override void OnPointerDown(PointerEventData eventData) + { + base.OnPointerDown(eventData); + if (eventData.pointerId < -1 || IsDraging) return; //适配 Touch:只响应一个Touch;适配鼠标:只响应左键 + fingerId = eventData.pointerId; + isDown = true; + isDownExit = false; + downTime = 0; + PlayButtonSound(ButtonSoundType.Down); + } + + public override void OnPointerUp(PointerEventData eventData) + { + base.OnPointerUp(eventData); + if (fingerId != eventData.pointerId) return; //正确的手指抬起时才会; + fingerId = int.MinValue; + isDown = false; + isDownExit = true; + PlayButtonSound(ButtonSoundType.Up); + } + + public override void OnPointerExit(PointerEventData eventData) + { + base.OnPointerExit(eventData); + if (fingerId != eventData.pointerId) return; //正确的手指抬起时才会; + isPress = false; + isDownExit = true; + PlayButtonSound(ButtonSoundType.Exit); + } + + public override void OnPointerClick(PointerEventData eventData) + { + if (!isPress) + { + clickTimes += 1; + } + else + isPress = false; + + PlayButtonSound(ButtonSoundType.Click); + } + + public void OnBeginDrag(PointerEventData eventData) + { + onBeginDrag?.Invoke(eventData); + } + + public void OnDrag(PointerEventData eventData) + { + PlayButtonSound(ButtonSoundType.Drag); + onDrag?.Invoke(eventData); + } + + public void OnEndDrag(PointerEventData eventData) + { + onEndDrag?.Invoke(eventData); + } + } +} + + + diff --git a/Runtime/UGUIExtension/Button/UIButtonSuper.cs.meta b/Runtime/UGUIExtension/Button/UIButtonSuper.cs.meta new file mode 100644 index 0000000..e0896e4 --- /dev/null +++ b/Runtime/UGUIExtension/Button/UIButtonSuper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: fa4f44179d534f148b96822ead9e9b8f +timeCreated: 1673928618 \ No newline at end of file diff --git a/Runtime/UGUIExtension/Text/UXTextMeshPro.cs b/Runtime/UGUIExtension/Text/UXTextMeshPro.cs index 5adc27f..06397d7 100644 --- a/Runtime/UGUIExtension/Text/UXTextMeshPro.cs +++ b/Runtime/UGUIExtension/Text/UXTextMeshPro.cs @@ -6,7 +6,6 @@ namespace UnityEngine.UI public class UXTextMeshPro : TextMeshProUGUI { [SerializeField] private string m_localizationID = ""; - protected override void Start() { base.Start();