0.3.0: Added history list

This commit is contained in:
Anders Ejlersen 2021-02-14 13:49:25 +01:00
parent 1e1736f94a
commit 9b73200c73
38 changed files with 662 additions and 18 deletions

View file

@ -0,0 +1,71 @@
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<EditorHistoryWindow>();
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)
{
HistoryListPostProcess.IgnoreNextSelectionChange();
Selection.activeObject = obj;
EditorGUIUtility.PingObject(obj);
}
HistoryGUIUtility.Used();
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1e561aeb312d93340b9abb76f0f65f22
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bcfcc9f9ab909284384fa64c41070bba
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,32 @@
using UnityEngine;
namespace Game.NavigationTool.Editor.History
{
internal sealed class Styles
{
public GUIStyle toolbox;
public GUIStyle entry;
public GUIStyle invalidEntry;
private GUISkin skin;
public void Initialize(GUISkin skin)
{
if (this.skin == skin)
return;
this.skin = skin;
toolbox = new GUIStyle(skin.box);
entry = new GUIStyle(skin.label);
entry.hover.textColor = entry.onHover.textColor = Color.white;
entry.active.textColor = entry.onActive.textColor = Color.yellow;
invalidEntry = new GUIStyle(entry);
invalidEntry.normal.textColor = Color.red;
invalidEntry.hover.textColor = invalidEntry.onHover.textColor = new Color(1.0f, 0.3f, 0.3f);
invalidEntry.active.textColor = invalidEntry.onActive.textColor = new Color(1.0f, 0.0f, 0.5f);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 39240bd81396c5d4dabe109523e9f8c6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f8f7454581679aa4fbc63ff14e2aecb3
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,10 @@
using UnityEngine;
namespace Game.NavigationTool.Editor.History
{
internal abstract class AbstractEditorHistoryView
{
public abstract void Initialize();
public abstract void Draw(EditorHistoryWindow window, Rect rect, Styles styles);
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e3d660bb77394c34884adc62cff3ac7c
timeCreated: 1613305008

View file

@ -0,0 +1,53 @@
using System;
using UnityEditor;
using UnityEngine;
namespace Game.NavigationTool.Editor.History
{
[Serializable]
internal sealed class EditorHistoryViewSearchList : AbstractEditorHistoryView
{
[SerializeField]
private Vector2 scrollPosition;
[NonSerialized]
private HistoryList historyList;
public override void Initialize()
{
historyList = HistoryUtility.GetHistoryList();
}
public override void Draw(EditorHistoryWindow window, Rect rect, Styles styles)
{
float entryHeight = EditorGUIUtility.singleLineHeight;
float height = entryHeight * historyList.entries.Count;
bool isSearching = !string.IsNullOrEmpty(window.viewTools.searchStr);
string lowerSearchStr = window.viewTools.searchStr.ToLower();
GUI.BeginGroup(rect);
{
var position = new Rect(0.0f, 0.0f, rect.width, rect.height);
var viewRect = new Rect(0.0f, 0.0f, position.height > height ? position.width : position.width - 14.0f, height);
var entryRect = new Rect(0.0f, 0.0f, viewRect.width, entryHeight);
scrollPosition = GUI.BeginScrollView(position, scrollPosition, viewRect);
{
for (int i = historyList.entries.Count - 1; i >= 0; i--)
{
HistoryList.Entry e = historyList.entries[i];
if (isSearching && !e.lowerName.Contains(lowerSearchStr))
continue;
HistoryGUIUtility.DrawEntry(entryRect, historyList.entries[i], styles, true);
entryRect.y += entryHeight;
}
}
GUI.EndScrollView();
}
GUI.EndGroup();
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7b9e14bc776433a4482034c88a6c9ad5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,41 @@
using System;
using UnityEditor;
using UnityEngine;
namespace Game.NavigationTool.Editor.History
{
[Serializable]
internal sealed class EditorHistoryViewTools : AbstractEditorHistoryView
{
public string searchStr = string.Empty;
[NonSerialized]
private HistoryList historyList;
public override void Initialize()
{
historyList = HistoryUtility.GetHistoryList();
}
public override void Draw(EditorHistoryWindow window, Rect rect, Styles styles)
{
const float BUTTON_SIZE = 50.0f;
GUI.BeginGroup(rect, styles.toolbox);
{
var r0 = new Rect(0.0f, 0.0f, rect.width - BUTTON_SIZE, rect.height);
var r1 = new Rect(r0.xMax, 0.0f, BUTTON_SIZE, rect.height);
searchStr = EditorGUI.TextField(r0, searchStr);
if (GUI.Button(r1, "Clear"))
historyList.Clear();
}
GUI.EndGroup();
}
public bool IsSearching()
{
return !string.IsNullOrEmpty(searchStr);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cc6ff725030026948be65ba87dfb9bd9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: