using System; using UnityEditor; using UnityEngine; using Object = UnityEngine.Object; namespace Game.NavigationTool.Editor.History { internal sealed class EditorHistoryWindow : EditorWindow { [NonSerialized] private Styles styles; [SerializeField] public EditorHistoryViewTools viewTools; [SerializeField] private EditorHistoryViewSearchList viewSearchList; [MenuItem("Tools/Windows/History")] public static void Open() { var window = GetWindow(); window.titleContent = new GUIContent("History"); window.Show(); } private void OnEnable() { if (styles == null) styles = new Styles(); if (viewTools == null) viewTools = new EditorHistoryViewTools(); if (viewSearchList == null) viewSearchList = new EditorHistoryViewSearchList(); } private void OnGUI() { if (Event.current.type == EventType.Layout) return; styles.Initialize(GUI.skin); var rectTools = new Rect(0.0f, 0.0f, position.width, EditorGUIUtility.singleLineHeight); var rectList = new Rect(0.0f, rectTools.yMax, position.width, position.height - rectTools.height); viewTools.Initialize(); viewTools.Draw(this, rectTools, styles); viewSearchList.Initialize(); viewSearchList.Draw(this, rectList, styles); HandleClickEvent(); } private void HandleClickEvent() { if (!HistoryGUIUtility.isClicked) return; HistoryList historyList = HistoryUtility.GetHistoryList(); Object obj = historyList.GetObject(HistoryGUIUtility.currentEntry); if (obj != null) { if (HistoryGUIUtility.isDoubleClick) { AssetDatabase.OpenAsset(obj); } else { HistoryListPostProcess.IgnoreNextSelectionChange(); Selection.activeObject = obj; EditorGUIUtility.PingObject(obj); } } HistoryGUIUtility.Used(); } } }