补充提交
This commit is contained in:
parent
6fa5a6c175
commit
e93cc36d33
64
Assets/Editor/EnableHideMobileInput.cs
Normal file
64
Assets/Editor/EnableHideMobileInput.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
/// <summary>
|
||||
/// 批量勾选项目中所有 Prefab 里 InputField 的 Hide Mobile Input 选项
|
||||
/// 菜单:Tools/UI/勾选所有输入框的 Hide Mobile Input
|
||||
/// 说明:
|
||||
/// 1. shouldHideMobileInput 属性在编辑器下(非移动平台)getter 恒返回 true,
|
||||
/// 因此直接操作序列化字段 m_HideMobileInput(inspector 勾选框实际写入的字段)
|
||||
/// 2. 使用 LoadPrefabContents/SaveAsPrefabAsset 打开并保存,
|
||||
/// 确保 YAML 真正写盘(LoadAssetAtPath + SaveAssets 不够可靠)
|
||||
/// </summary>
|
||||
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<InputField>(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}");
|
||||
}
|
||||
}
|
||||
11
Assets/Editor/EnableHideMobileInput.cs.meta
Normal file
11
Assets/Editor/EnableHideMobileInput.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aad443f4ae341494abea2d472c16af32
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
x
Reference in New Issue
Block a user