Skip to content

Commit 1a5ae86

Browse files
committed
强制刷新
1 parent ec0aae1 commit 1a5ae86

File tree

11 files changed

+43
-24
lines changed

11 files changed

+43
-24
lines changed

Assets/Editor/LocalizationSetting.asset

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ MonoBehaviour:
1313
m_Name: LocalizationSetting
1414
m_EditorClassIdentifier:
1515
_localizationType: zh-TW
16-
_defaultData: Assets/Example/New Localization Data_zh-TW.asset
16+
_defaultData: Assets/Example/New Localization Data.asset
1717
_lineReg: '"'
1818
_fieldReg: \G(?:^|,)(?:"((?>[^"]*)(?>""[^"]*)*)"|([^",]*))
1919
_quotesReg: '""'
@@ -22,4 +22,3 @@ MonoBehaviour:
2222
list:
2323
- Key: WooLocalization.YouDao
2424
Value: '{"AppId":"1db431ae6d39bdbd","AppSecret":"v4hGoQMakxaBuZJEGzksA3Uf4adhHfoW"}'
25-
_lastCSVPath: Assets

Assets/Example/New Localization Data.asset

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ MonoBehaviour:
3838
Value:
3939
list:
4040
- Key: Load_GameTip
41-
Value: "\u300A\u5065\u5EB7\u6E38\u620F\u5FE0\u544A\u300B\r\n\u62B5\u5236\u4E0D\u826F\u6E38\u620F\uFF0C\u62D2\u7EDD\u76D7\u7248\u6E38\u620F\u3002\r\n\u6CE8\u610F\u81EA\u6211\u4FDD\u62A4\uFF0C\u8C28\u9632\u53D7\u9A97\u4E0A\u5F53\u3002\r\n\u9002\u5EA6\u6E38\u620F\u76CA\u8111\uFF0C\u6C89\u8FF7\u6E38\u620F\u4F24\u8EAB\u3002\r\n\u5408\u7406\u5B89\u6392\u65F6\u95F4\uFF0C\u4EAB\u53D7\u5065\u5EB7\u751F\u6D3B\u3002"
41+
Value: "\u5527\u5527\u6B6A\u6B6A"
4242
- Key: Load_UpdateText
4343
Value: "\u6B63\u5728\u68C0\u67E5\u66F4\u65B0\u4E2D"
4444
- Key: Load_Tip_Title
@@ -79,7 +79,7 @@ MonoBehaviour:
7979
Value:
8080
list:
8181
- Key: Load_GameTip
82-
Value:
82+
Value: "\u5527\u5527\u6B6A\u6B6A"
8383
- Key: Load_UpdateText
8484
Value:
8585
- Key: Load_Tip_Title

Assets/Example/New Scene.unity

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ MonoBehaviour:
687687
m_OnCullStateChanged:
688688
m_PersistentCalls:
689689
m_Calls: []
690-
m_Sprite: {fileID: 0}
690+
m_Sprite: {fileID: 21300000, guid: 1f49c06b3dfcb8747a2025c8cbb44f67, type: 3}
691691
m_Type: 1
692692
m_PreserveAspect: 0
693693
m_FillCenter: 1
@@ -749,9 +749,9 @@ MonoBehaviour:
749749
Value: {fileID: 0}
750750
- Key: CN
751751
Value: {fileID: 0}
752-
_mode: 0
753-
_key:
754-
asset: {fileID: 0}
752+
_mode: 2
753+
_key: text
754+
asset: {fileID: 11400000, guid: 89a2e053f7951de4bbb89bda646bc86a, type: 2}
755755
--- !u!1 &721698454
756756
GameObject:
757757
m_ObjectHideFlags: 0

Assets/WooLocalization/Editor/LocalizationEditorHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ internal static void SaveContext(ScriptableObject context)
553553
{
554554
EditorUtility.SetDirty(context);
555555
AssetDatabase.SaveAssetIfDirty(context);
556+
Localization.ForceRefreshBehaviors();
556557
}
557558

558559
public static void ReadCSV(string path, LocalizationData context)
@@ -636,7 +637,6 @@ public static void ReadExcel(string path, LocalizationData context)
636637
}
637638
}
638639
EditorUtility.ClearProgressBar();
639-
640640
SaveContext(context);
641641
}
642642

Assets/WooLocalization/Runtime/Actor/ILocalizationActor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ public interface ILocalizationActor
1616
void SetBehavior(LocalizationBehavior behavior);
1717
void SetName(string name);
1818
void OnEditorLoad();
19+
void SetDirty();
1920
}
2021
}

Assets/WooLocalization/Runtime/Actor/LocalizationActor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public abstract class LocalizationActor<T> : ILocalizationActor where T : Locali
1414
[System.NonSerialized] private string _localizationType;
1515
[System.NonSerialized] private bool dirty = true;
1616

17-
protected void SetDirty()
17+
public void SetDirty()
1818
{
1919
dirty = true;
2020
}

Assets/WooLocalization/Runtime/Component/LocalizationBehavior.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public T target
2626
}
2727
}
2828
[ExecuteAlways]
29-
public abstract class LocalizationBehavior : MonoBehaviour, ILocalizationEventActor
29+
public abstract class LocalizationBehavior : MonoBehaviour, ILocalizationEventBehavior
3030
{
3131
[SerializeField]
3232
private LocalizationData _context;
@@ -114,11 +114,11 @@ protected virtual void Awake()
114114

115115
protected void OnDisable()
116116
{
117-
Localization.RemoveHandler(this);
117+
Localization.RemoveBehavior(this);
118118
}
119119
protected void OnEnable()
120120
{
121-
Localization.AddHandler(this);
121+
Localization.AddBehavior(this);
122122
# if UNITY_EDITOR
123123
UnityEditor.EditorApplication.delayCall += Execute;
124124
#else
@@ -128,7 +128,8 @@ protected void OnEnable()
128128

129129
protected abstract List<ILocalizationActor> GetActors();
130130

131-
void ILocalizationEventActor.OnLanguageChange() => Execute();
131+
void ILocalizationEventBehavior.OnLanguageChange() => Execute();
132+
132133
private void Execute()
133134
{
134135
LoadActors();
@@ -138,6 +139,11 @@ private void Execute()
138139
actors[i].Execute(_type, this);
139140
}
140141

141-
142+
void ILocalizationEventBehavior.SetActorsDirty()
143+
{
144+
var actors = LoadActors();
145+
for (int i = 0; i < actors.Count; i++)
146+
actors[i].SetDirty();
147+
}
142148
}
143149
}

Assets/WooLocalization/Runtime/ILocalizationEventActor.cs renamed to Assets/WooLocalization/Runtime/ILocalizationEventBehavior.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
*********************************************************************************/
77
namespace WooLocalization
88
{
9-
public interface ILocalizationEventActor
9+
public interface ILocalizationEventBehavior
1010
{
1111
void OnLanguageChange();
12+
13+
void SetActorsDirty();
1214
}
1315
}

Assets/WooLocalization/Runtime/ILocalizationEventActor.cs.meta renamed to Assets/WooLocalization/Runtime/ILocalizationEventBehavior.cs.meta

File renamed without changes.

Assets/WooLocalization/Runtime/Localization.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*Date: 2024-04-25
66
*********************************************************************************/
77
using System.Collections.Generic;
8-
using System.Text.RegularExpressions;
98
namespace WooLocalization
109
{
1110
public static class Localization
@@ -14,10 +13,22 @@ public static class Localization
1413
public static LocalizationData context;
1514
private static LocalizationPref pref;
1615
private static ILocalizationPrefRecorder recorder = new MixedRecorder();
17-
private static List<ILocalizationEventActor> handlers = new List<ILocalizationEventActor>();
16+
private static List<ILocalizationEventBehavior> behaviors = new List<ILocalizationEventBehavior>();
17+
18+
public static void AddBehavior(ILocalizationEventBehavior behavior) => behaviors.Add(behavior);
19+
public static void RemoveBehavior(ILocalizationEventBehavior behavior) => behaviors.Remove(behavior);
20+
21+
public static void ForceRefreshBehaviors()
22+
{
23+
for (int i = 0; i < behaviors.Count; i++)
24+
{
25+
var behavior = behaviors[i];
26+
behavior.SetActorsDirty();
27+
behavior.OnLanguageChange();
28+
}
29+
}
30+
1831

19-
public static void AddHandler(ILocalizationEventActor handler) => handlers.Add(handler);
20-
public static void RemoveHandler(ILocalizationEventActor handler) => handlers.Remove(handler);
2132
public static void SetRecorder(ILocalizationPrefRecorder recorder)
2233
{
2334
(Localization.recorder as MixedRecorder).Add(recorder);
@@ -42,9 +53,9 @@ public static void SetLocalizationType(string language)
4253
if (Localization.language == language) return;
4354
pref.language = language;
4455
recorder.Write(pref);
45-
for (int i = 0; i < handlers.Count; i++)
56+
for (int i = 0; i < behaviors.Count; i++)
4657
{
47-
var handler = handlers[i];
58+
var handler = behaviors[i];
4859
if (handler == null) continue;
4960
handler.OnLanguageChange();
5061
}
@@ -74,7 +85,7 @@ public static string GetLocalization(LocalizationData context, string language,
7485
if (string.IsNullOrEmpty(restult)) return key;
7586

7687
#if UNITY_EDITOR
77-
var match = Regex.Matches(restult, "{[0-9]*}");
88+
var match = System.Text.RegularExpressions.Regex.Matches(restult, "{[0-9]*}");
7889
if (match.Count != 0 && (args == null || args.Length != match.Count))
7990
throw new System.Exception($"Args Err \t\t{nameof(language)}:{language}\t{nameof(key)}:{key}\n{restult}");
8091
#endif

0 commit comments

Comments
 (0)