diff --git a/Assets/Editor/EnableHideMobileInput.cs b/Assets/Editor/EnableHideMobileInput.cs new file mode 100644 index 0000000..08e343a --- /dev/null +++ b/Assets/Editor/EnableHideMobileInput.cs @@ -0,0 +1,64 @@ +using System.Text; +using UnityEditor; +using UnityEngine; +using UnityEngine.UI; + +/// +/// 批量勾选项目中所有 Prefab 里 InputField 的 Hide Mobile Input 选项 +/// 菜单:Tools/UI/勾选所有输入框的 Hide Mobile Input +/// 说明: +/// 1. shouldHideMobileInput 属性在编辑器下(非移动平台)getter 恒返回 true, +/// 因此直接操作序列化字段 m_HideMobileInput(inspector 勾选框实际写入的字段) +/// 2. 使用 LoadPrefabContents/SaveAsPrefabAsset 打开并保存, +/// 确保 YAML 真正写盘(LoadAssetAtPath + SaveAssets 不够可靠) +/// +public static class EnableHideMobileInput +{ + [MenuItem("Tools/UI/勾选所有输入框的 Hide Mobile Input")] + public static void EnableAll() + { + var log = new StringBuilder(); + int files = 0, fields = 0; + + foreach (var guid in AssetDatabase.FindAssets("t:Prefab", new[] { "Assets" })) + { + string path = AssetDatabase.GUIDToAssetPath(guid); + var contents = PrefabUtility.LoadPrefabContents(path); + try + { + int changed = 0; + foreach (var field in contents.GetComponentsInChildren(true)) + { + var so = new SerializedObject(field); + var prop = so.FindProperty("m_HideMobileInput"); + if (prop != null && !prop.boolValue) + { + prop.boolValue = true; + so.ApplyModifiedProperties(); + changed++; + } + } + + if (changed > 0) + { + PrefabUtility.SaveAsPrefabAsset(contents, path); + files++; + fields += changed; + log.AppendLine($"{path}:{changed} 个"); + } + } + finally + { + PrefabUtility.UnloadPrefabContents(contents); + } + } + + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + + if (files == 0) + Debug.Log("所有输入框的 Hide Mobile Input 均已勾选,无需修改。"); + else + Debug.Log($"处理完成:{files} 个 Prefab 共 {fields} 个输入框已勾选。\n{log}"); + } +} diff --git a/Assets/Editor/EnableHideMobileInput.cs.meta b/Assets/Editor/EnableHideMobileInput.cs.meta new file mode 100644 index 0000000..165a600 --- /dev/null +++ b/Assets/Editor/EnableHideMobileInput.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: aad443f4ae341494abea2d472c16af32 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: