From e93cc36d3301a0da93542be0bc6741ce42790b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9C=E8=99=9E=E6=B8=A0=E6=88=90=E2=80=9D?= <“yuqucheng2006@qq.com”> Date: Fri, 11 Sep 2026 09:48:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Editor/EnableHideMobileInput.cs | 64 +++++++++++++++++++++ Assets/Editor/EnableHideMobileInput.cs.meta | 11 ++++ 2 files changed, 75 insertions(+) create mode 100644 Assets/Editor/EnableHideMobileInput.cs create mode 100644 Assets/Editor/EnableHideMobileInput.cs.meta 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: