修改
This commit is contained in:
parent
da3a43a2a6
commit
57c49b1e2f
@ -1,10 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using AlicizaX.Localization.Runtime;
|
||||
using AlicizaX;
|
||||
using AlicizaX.Localization.Editor;
|
||||
using Paps.UnityToolbarExtenderUIToolkit;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
@ -56,6 +59,7 @@ public class LocalizationDropdownField : IMGUIContainer
|
||||
void ClickToolsSubmenu(string langaugeName)
|
||||
{
|
||||
EditorPrefs.SetString(LocalizationComponent.PrefsKey, langaugeName);
|
||||
InvokeOnValidateInScene();
|
||||
Debug.Log(langaugeName);
|
||||
}
|
||||
|
||||
@ -63,4 +67,45 @@ public class LocalizationDropdownField : IMGUIContainer
|
||||
{
|
||||
return EditorPrefs.GetString(LocalizationComponent.PrefsKey, "None");
|
||||
}
|
||||
|
||||
|
||||
public static void InvokeOnValidateInScene()
|
||||
{
|
||||
|
||||
System.Type targetType = AlicizaX.Utility.Assembly.GetType("UnityEngine.UI.UXTextMeshPro");
|
||||
MethodInfo onValidateMethod = targetType.GetMethod("OnValidate", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
|
||||
|
||||
if (onValidateMethod == null)
|
||||
{
|
||||
Debug.LogWarning($"类型 {targetType.Name} 没有找到 OnValidate 方法(可能是用其他签名或不存在)");
|
||||
return;
|
||||
}
|
||||
|
||||
List<Component> components = new List<Component>();
|
||||
|
||||
components = GameObject.FindObjectsOfType(targetType).ToList().Select(t => (t as Component)).ToList();
|
||||
|
||||
if (components.Count == 0)
|
||||
{
|
||||
Debug.Log("未在场景中找到任何目标组件。");
|
||||
return;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
|
||||
var scenesToMarkDirty = EditorSceneManager.GetActiveScene();
|
||||
|
||||
foreach (var comp in components)
|
||||
{
|
||||
Undo.RecordObject(comp, "Invoke OnValidate");
|
||||
onValidateMethod.Invoke(comp, null);
|
||||
EditorUtility.SetDirty(comp);
|
||||
count++;
|
||||
}
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
EditorSceneManager.MarkSceneDirty(scenesToMarkDirty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user