75 lines
2.5 KiB
C#
75 lines
2.5 KiB
C#
using UnityEditor;
|
|
using UnityEditorInternal;
|
|
using UnityEngine;
|
|
|
|
namespace Game.NavigationTool.Editor.History
|
|
{
|
|
internal static class HistoryGUIUtility
|
|
{
|
|
private static readonly int ENTRY_HASH = "DrawHistoryEntry".GetHashCode();
|
|
|
|
public static bool isClicked;
|
|
public static HistoryList.Entry currentEntry;
|
|
|
|
public static void DrawEntry(Rect rect, HistoryList.Entry entry, Styles styles, bool ignoreIndentLevel = false)
|
|
{
|
|
int id = GUIUtility.GetControlID(ENTRY_HASH, FocusType.Passive, rect);
|
|
bool on = currentEntry == entry;
|
|
bool intersects = rect.Contains(Event.current.mousePosition);
|
|
|
|
switch (Event.current.type)
|
|
{
|
|
case EventType.MouseDown:
|
|
if (intersects)
|
|
{
|
|
currentEntry = entry;
|
|
Event.current.Use();
|
|
}
|
|
break;
|
|
case EventType.MouseUp:
|
|
if (currentEntry == entry)
|
|
{
|
|
isClicked = intersects;
|
|
|
|
if (!isClicked)
|
|
currentEntry = null;
|
|
|
|
Event.current.Use();
|
|
}
|
|
break;
|
|
case EventType.Repaint:
|
|
Vector2 oldSize = EditorGUIUtility.GetIconSize();
|
|
EditorGUIUtility.SetIconSize(new Vector2(rect.height, rect.height));
|
|
GUIStyle style = entry.valid ? styles.entry : styles.invalidEntry;
|
|
style.Draw(rect, entry.content, id, on, intersects);
|
|
EditorGUIUtility.SetIconSize(oldSize);
|
|
break;
|
|
}
|
|
}
|
|
|
|
public static void Used()
|
|
{
|
|
isClicked = false;
|
|
currentEntry = null;
|
|
}
|
|
|
|
public static Texture2D GetIcon(string path)
|
|
{
|
|
var texture = AssetDatabase.GetCachedIcon(path) as Texture2D;
|
|
|
|
if (texture == null)
|
|
texture = InternalEditorUtility.GetIconForFile(path);
|
|
|
|
return texture;
|
|
}
|
|
|
|
public static void Repaint()
|
|
{
|
|
if (!EditorWindow.HasOpenInstances<EditorHistoryWindow>())
|
|
return;
|
|
|
|
var window = EditorWindow.GetWindow<EditorHistoryWindow>("History", false);
|
|
window.Repaint();
|
|
}
|
|
}
|
|
} |