Skip to content

Commit

Permalink
v1.0.118 LocaleKit: LocaleText 预览位置调整
Browse files Browse the repository at this point in the history
  • Loading branch information
liangxiegame@163.com committed Dec 17, 2023
1 parent 68d8d4b commit a104838
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Id": "",
"Version": "v1.0.117",
"Version": "v1.0.118",
"Type": 0,
"AccessRight": 0,
"DownloadUrl": "",
Expand All @@ -11,10 +11,10 @@
],
"DocUrl": "https://liangxiegame.com",
"Readme": {
"version": "v1.0.117",
"content": "LocaleText 避免批量编辑造成的文本覆盖问题",
"version": "v1.0.118",
"content": "LocaleKit: LocaleText 预览位置调整",
"author": "liangxie",
"date": "2023 年 12 月 17 日 00:38",
"date": "2023 年 12 月 17 日 14:54",
"PackageId": ""
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
/****************************************************************************
* Copyright (c) 2015 - 2022 liangxiegame UNDER MIT License
*
*
* http://qframework.cn
* https://github.com/liangxiegame/QFramework
* https://gitee.com/liangxiegame/QFramework
****************************************************************************/

using System.Collections.Generic;
using System.Linq;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
using UnityEngine.UI;

Expand All @@ -19,19 +16,17 @@ namespace QFramework
public class LocaleText : MonoBehaviour
{
public bool SetTextOnInit = true;

public List<LanguageText> LanguageTexts;

private Text mText;
private TextMesh mTextMesh;



private void Start()
{
mText = GetComponent<Text>();
mTextMesh = GetComponent<TextMesh>();



LocaleKit.OnLanguageChanged.Register(() => { UpdateText(LocaleKit.CurrentLanguage); })
.UnRegisterWhenGameObjectDestroyed(gameObject);

Expand All @@ -41,7 +36,7 @@ private void Start()
}
}

void UpdateText(Language language)
public void UpdateText(Language language)
{
if (mText)
{
Expand All @@ -54,35 +49,4 @@ void UpdateText(Language language)
}
}
}


#if UNITY_EDITOR
[CustomEditor(typeof(LocaleText))]
internal class LocaleTextInspector : Editor
{
LocaleText mScript => target as LocaleText;

public override void OnInspectorGUI()
{
base.OnInspectorGUI();

serializedObject.Update();

if (mScript.LanguageTexts != null)
{
foreach (var scriptLanguageText in mScript.LanguageTexts)
{
if (GUILayout.Button("Preview " + scriptLanguageText.Language))
{
Debug.Log(scriptLanguageText.Language);
Debug.Log((int)scriptLanguageText.Language);
mScript.GetComponent<Text>().text = scriptLanguageText.Text;
}
}
}

serializedObject.ApplyModifiedProperties();
}
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public override float GetPropertyHeight(SerializedProperty property, GUIContent

var textProperty = property.FindPropertyRelative("Text");
var height = EditorGUI.GetPropertyHeight(textProperty);
return height;
return height + EditorGUIUtility.singleLineHeight;
}


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



var previewButtonRect = new Rect(position.x, position.y + 10
+ textHeight - 12,
position.width, EditorGUIUtility.singleLineHeight);
if (GUI.Button(previewButtonRect, Locale.Preview))
{
var localeText = property.serializedObject.targetObject as LocaleText;
if (localeText != null) localeText.UpdateText((Language)language.intValue);
}
EditorGUI.indentLevel = indent;
EditorGUI.EndProperty();
}

public class Locale
{
public static string Preview => LocaleKitEditor.IsCN.Value ? "预览 " : "Preview ";
}
}
#endif
}

0 comments on commit a104838

Please sign in to comment.