我很讨厌每次都去找Inspector面板上那个小小的Apply按钮,所以今天自己写了一个工具. 实现了Apply功能,之后鼠标选中场景中对应的物体,按Alt+p就可以了
using UnityEngine;
using System.Collections;
using UnityEditor;
public class CustomHotKey {
[MenuItem("HotKey/Apply Prefab &p")]
public static void PrintName()
{
if (Selection.activeGameObject!=null)
{
var target = Selection.activeGameObject;
UnityEngine.Object prefabParent = PrefabUtility.GetPrefabParent(target);
GameObject gameObject = PrefabUtility.FindValidUploadPrefabInstanceRoot(target);
if (gameObject == null ||prefabParent == null)
{
return;
}
PrefabUtility.ReplacePrefab(gameObject, prefabParent, ReplacePrefabOptions.ConnectToPrefab);
}
}
}
网友评论