Skip to content

Commit a104838

Browse files
author
liangxiegame@163.com
committed
v1.0.118 LocaleKit: LocaleText 预览位置调整
1 parent 68d8d4b commit a104838

3 files changed

Lines changed: 24 additions & 47 deletions

File tree

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"Id": "",
3-
"Version": "v1.0.117",
3+
"Version": "v1.0.118",
44
"Type": 0,
55
"AccessRight": 0,
66
"DownloadUrl": "",
@@ -11,10 +11,10 @@
1111
],
1212
"DocUrl": "https://liangxiegame.com",
1313
"Readme": {
14-
"version": "v1.0.117",
15-
"content": "LocaleText 避免批量编辑造成的文本覆盖问题",
14+
"version": "v1.0.118",
15+
"content": "LocaleKit: LocaleText 预览位置调整",
1616
"author": "liangxie",
17-
"date": "2023 年 12 月 17 日 00:38",
17+
"date": "2023 年 12 月 17 日 14:54",
1818
"PackageId": ""
1919
}
2020
}
Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
/****************************************************************************
22
* Copyright (c) 2015 - 2022 liangxiegame UNDER MIT License
3-
*
3+
*
44
* http://qframework.cn
55
* https://github.com/liangxiegame/QFramework
66
* https://gitee.com/liangxiegame/QFramework
77
****************************************************************************/
88

99
using System.Collections.Generic;
1010
using System.Linq;
11-
#if UNITY_EDITOR
12-
using UnityEditor;
13-
#endif
1411
using UnityEngine;
1512
using UnityEngine.UI;
1613

@@ -19,19 +16,17 @@ namespace QFramework
1916
public class LocaleText : MonoBehaviour
2017
{
2118
public bool SetTextOnInit = true;
22-
19+
2320
public List<LanguageText> LanguageTexts;
2421

2522
private Text mText;
2623
private TextMesh mTextMesh;
27-
28-
24+
2925
private void Start()
3026
{
3127
mText = GetComponent<Text>();
3228
mTextMesh = GetComponent<TextMesh>();
33-
34-
29+
3530
LocaleKit.OnLanguageChanged.Register(() => { UpdateText(LocaleKit.CurrentLanguage); })
3631
.UnRegisterWhenGameObjectDestroyed(gameObject);
3732

@@ -41,7 +36,7 @@ private void Start()
4136
}
4237
}
4338

44-
void UpdateText(Language language)
39+
public void UpdateText(Language language)
4540
{
4641
if (mText)
4742
{
@@ -54,35 +49,4 @@ void UpdateText(Language language)
5449
}
5550
}
5651
}
57-
58-
59-
#if UNITY_EDITOR
60-
[CustomEditor(typeof(LocaleText))]
61-
internal class LocaleTextInspector : Editor
62-
{
63-
LocaleText mScript => target as LocaleText;
64-
65-
public override void OnInspectorGUI()
66-
{
67-
base.OnInspectorGUI();
68-
69-
serializedObject.Update();
70-
71-
if (mScript.LanguageTexts != null)
72-
{
73-
foreach (var scriptLanguageText in mScript.LanguageTexts)
74-
{
75-
if (GUILayout.Button("Preview " + scriptLanguageText.Language))
76-
{
77-
Debug.Log(scriptLanguageText.Language);
78-
Debug.Log((int)scriptLanguageText.Language);
79-
mScript.GetComponent<Text>().text = scriptLanguageText.Text;
80-
}
81-
}
82-
}
83-
84-
serializedObject.ApplyModifiedProperties();
85-
}
86-
}
87-
#endif
8852
}

QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/LocaleKit/Scripts/Data/LanguageText.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public override float GetPropertyHeight(SerializedProperty property, GUIContent
3535

3636
var textProperty = property.FindPropertyRelative("Text");
3737
var height = EditorGUI.GetPropertyHeight(textProperty);
38-
return height;
38+
return height + EditorGUIUtility.singleLineHeight;
3939
}
4040

4141

@@ -70,10 +70,23 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
7070
textHeight - EditorGUIUtility.singleLineHeight - 12);
7171
text.stringValue = EditorGUI.TextArea(textRect, text.stringValue);
7272

73-
73+
74+
var previewButtonRect = new Rect(position.x, position.y + 10
75+
+ textHeight - 12,
76+
position.width, EditorGUIUtility.singleLineHeight);
77+
if (GUI.Button(previewButtonRect, Locale.Preview))
78+
{
79+
var localeText = property.serializedObject.targetObject as LocaleText;
80+
if (localeText != null) localeText.UpdateText((Language)language.intValue);
81+
}
7482
EditorGUI.indentLevel = indent;
7583
EditorGUI.EndProperty();
7684
}
85+
86+
public class Locale
87+
{
88+
public static string Preview => LocaleKitEditor.IsCN.Value ? "预览 " : "Preview ";
89+
}
7790
}
7891
#endif
7992
}

0 commit comments

Comments
 (0)