Files
plugin-library/Assets/02.InformationSave/Editor/CustomEditorBaseEditor.cs
2025-05-08 15:57:40 +08:00

46 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using Object = UnityEngine.Object;
namespace Stary.Evo.InformationSave
{
[CustomEditor(typeof(CustomEditorBase), true)]
public class CustomEditorBaseEditor : UnityEditor.Editor
{
private CustomEditorBase _customEditorBase;
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
serializedObject.Update();
_customEditorBase = target as CustomEditorBase;
if (string.IsNullOrEmpty(_customEditorBase.mationID))
{
_customEditorBase.mationID = _customEditorBase.gameObject.GetInstanceID().ToString();
}
GUILayout.BeginHorizontal();
GUILayout.Box("MationID:", GUILayout.MaxWidth(500));
GUILayout.Box(_customEditorBase.mationID, GUILayout.MaxWidth(500));
GUILayout.EndHorizontal();
_customEditorBase.Draw();
//这个函数告诉引擎相关对象所属于的Prefab已经发生了更改。方便当我们更改了自定义对象的属性的时候自动更新到所属的Prefab中
if (GUI.changed && EditorApplication.isPlaying == false)
{
serializedObject.ApplyModifiedProperties();
var prefabType = PrefabUtility.GetPrefabInstanceStatus(_customEditorBase);
if (prefabType != PrefabInstanceStatus.NotAPrefab)
{
PrefabUtility.RecordPrefabInstancePropertyModifications(_customEditorBase);
}
EditorUtility.SetDirty(_customEditorBase);
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
}
}
}
}