Files

46 lines
1.8 KiB
C#
Raw Permalink Normal View History

2025-05-08 15:57:40 +08:00
using System;
2025-03-26 09:34:52 +08:00
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
2025-05-08 15:57:40 +08:00
using Object = UnityEngine.Object;
2025-03-26 09:34:52 +08:00
namespace Stary.Evo.InformationSave
{
[CustomEditor(typeof(CustomEditorBase), true)]
public class CustomEditorBaseEditor : UnityEditor.Editor
{
private CustomEditorBase _customEditorBase;
2025-05-08 15:57:40 +08:00
2025-03-26 09:34:52 +08:00
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
serializedObject.Update();
_customEditorBase = target as CustomEditorBase;
2025-05-08 15:57:40 +08:00
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();
2025-03-26 09:34:52 +08:00
_customEditorBase.Draw();
//这个函数告诉引擎相关对象所属于的Prefab已经发生了更改。方便当我们更改了自定义对象的属性的时候自动更新到所属的Prefab中
if (GUI.changed && EditorApplication.isPlaying == false)
{
serializedObject.ApplyModifiedProperties();
2025-05-08 15:57:40 +08:00
var prefabType = PrefabUtility.GetPrefabInstanceStatus(_customEditorBase);
if (prefabType != PrefabInstanceStatus.NotAPrefab)
{
PrefabUtility.RecordPrefabInstancePropertyModifications(_customEditorBase);
}
2025-03-26 09:34:52 +08:00
EditorUtility.SetDirty(_customEditorBase);
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
}
}
}
}