[MenuItem("所有Prefab添加PrefabInfoHerlper组件")]
static void AddPrefabInfoHelper()
{
UnityEngine.Object[] selObjs = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets);
for (int i = 0; i < selObjs.Length; i++)
{
Object selObj = selObjs[i];
string selfPath = AssetDatabase.GetAssetPath(selObj);
if (selfPath.EndsWith(".prefab"))
{
string[] dependPaths = AssetDatabase.GetDependencies(selfPath);
GameObject go = GameObject.Instantiate(selObj) as GameObject;
PrefabInfoHelper pih = go.GetComponent<PrefabInfoHelper>();
if (pih == null)
{
pih = go.AddComponent<PrefabInfoHelper>();
}
pih.isInstanced = false;
pih.selfPath
Unity Editor下 修改 Prefab
最新推荐文章于 2022-11-11 15:12:04 发布
本文介绍如何在Unity编辑器中批量为所有Prefab添加PrefabInfoHelper组件。通过MenuItem函数`AddPrefabInfoHelper`,遍历选择的深资产对象,检查是否为Prefab,然后实例化Prefab,添加PrefabInfoHelper组件,设置相关信息,并使用PrefabUtility替换Prefab,最后销毁临时实例。
摘要由CSDN通过智能技术生成