[MenuItem("Tool/PrefabUtility.GetPropertyModifications")]
static void GetPropertyModifications()
{
GameObject tar = Selection.activeObject as GameObject;
PropertyModification[] pms = PrefabUtility.GetPropertyModifications(tar);
UnityEngine.Debug.Log($"---pms==={pms.Length}");//场景内有效
}
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets,
string[] movedFromAssetPaths)
{//资源刷新后
foreach (string assetPath in importedAssets)
{
if (assetPath.EndsWith(".prefab"))
{
GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
if (prefab != null)
{//预制体变化时生效
var targetObj = GameObject.Find(prefab.name);//寻找场景下的资源
if (targetObj != null)
{
}
}
}
}
}
[InitializeOnLoadMethod]
private static void RegisterPrefabEvents()
{
UnityEngine.Debug.Log("RegisterPrefabEvents");
PrefabStage.prefabSaving += OnSaving;
}