1.加载Prefab
var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(TargetPath);
2.在自定义的窗口绘制组件Inspector
var coms = prefab.GetComponents<Component>();
foreach (var component in coms)
{
if (!_cachedEditors.TryGetValue(component.GetType(), out var e))
{
e = Editor.CreateEditor(component);
_cachedEditors[component.GetType()] = e;
}
Editor.DrawFoldoutInspector(component, ref e);
if (GUI.changed)
{
EditorUtility.SetDirty(prefab);
_controlId = GUIUtility.hotControl;
}
}
GUILayout.EndArea();
if (EditorUtility.IsDirty(_prefabObj))
{
if (_controlId != GUIUtility.hotControl) //这一步是为了降低保存频率
PrefabUtility.SavePrefabAsset(_prefabObj);
}