aaa
This commit is contained in:
parent
a75e37790a
commit
0941d5584d
@ -5,7 +5,8 @@
|
||||
"GUID:6546d7765b4165b40850b3667f981c26",
|
||||
"GUID:760f1778adc613f49a4394fb41ff0bbc",
|
||||
"GUID:75b6f2078d190f14dbda4a5b747d709c",
|
||||
"GUID:a19b414bea3b97240a91aeab9a8eab36"
|
||||
"GUID:a19b414bea3b97240a91aeab9a8eab36",
|
||||
"GUID:83a193b118cfbef48a344187e07f53bb"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
|
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 618191a0ed5f4928a1686d6954d7cd1a
|
||||
timeCreated: 1738834271
|
@ -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<LocalizeItem> LocalizeItems;
|
||||
private static Dictionary<string, Dictionary<Language, string>> LocalizeDic;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有静态Keys
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string[] GetAllStaticKeys()
|
||||
{
|
||||
LoadStaticKey();
|
||||
List<string> 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<Language, string> 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<TextAsset>(LocalizeStaticConfigPath);
|
||||
|
||||
LocalizeItems = JsonConvert.DeserializeObject<System.Collections.Generic.List<LocalizeItem>>(textAsset.text);
|
||||
|
||||
LocalizeDic = new Dictionary<string, Dictionary<Language, string>>();
|
||||
foreach (var v in LocalizeItems)
|
||||
{
|
||||
Dictionary<Language, string> valueDic = new Dictionary<Language, string>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d65abc05d0b640199d1f55346b3c4f1b
|
||||
timeCreated: 1738834272
|
@ -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<LocalizationMasterConfig.LanguageEntry> _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();
|
||||
|
56
Editor/UIExtension/UIButtonSuper.cs
Normal file
56
Editor/UIExtension/UIButtonSuper.cs
Normal file
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
3
Editor/UIExtension/UIButtonSuper.cs.meta
Normal file
3
Editor/UIExtension/UIButtonSuper.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f9c7e374daba4ee8a1092a930327fa2f
|
||||
timeCreated: 1740102365
|
3
Runtime/UGUIExtension/Button.meta
Normal file
3
Runtime/UGUIExtension/Button.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6959ce6dfcdb41dbb548a7472f65626a
|
||||
timeCreated: 1740102262
|
242
Runtime/UGUIExtension/Button/UIButtonSuper.cs
Normal file
242
Runtime/UGUIExtension/Button/UIButtonSuper.cs
Normal file
@ -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<ButtonSoundCell> m_ButtonUISounds = new List<ButtonSoundCell>();
|
||||
|
||||
[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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否按钮按下
|
||||
/// </summary>
|
||||
public bool IsDown
|
||||
{
|
||||
get { return isDown; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否按钮长按
|
||||
/// </summary>
|
||||
public bool IsPress
|
||||
{
|
||||
get { return isPress; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否按钮按下后离开按钮位置
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
3
Runtime/UGUIExtension/Button/UIButtonSuper.cs.meta
Normal file
3
Runtime/UGUIExtension/Button/UIButtonSuper.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa4f44179d534f148b96822ead9e9b8f
|
||||
timeCreated: 1673928618
|
@ -6,7 +6,6 @@ namespace UnityEngine.UI
|
||||
public class UXTextMeshPro : TextMeshProUGUI
|
||||
{
|
||||
[SerializeField] private string m_localizationID = "";
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
|
Loading…
Reference in New Issue
Block a user