112 lines
4.1 KiB
C#
112 lines
4.1 KiB
C#
using UnityEditor;
|
|
using UnityEditorInternal;
|
|
using UnityEngine;
|
|
|
|
namespace Game.NavigationTool.Editor
|
|
{
|
|
internal static class FavoritesGUIUtility
|
|
{
|
|
private static readonly int ENTRY_HASH = "DrawEntry".GetHashCode();
|
|
|
|
public static Favorites.Entry manipulatingEntry;
|
|
public static EManipulatingState manipulatingState;
|
|
public static Favorites.Entry hoverEntry;
|
|
|
|
public static void DrawEntry(Rect rect, Favorites.Entry entry, Styles styles, bool ignoreIndentLevel = false)
|
|
{
|
|
int id = GUIUtility.GetControlID(ENTRY_HASH, FocusType.Passive, rect);
|
|
bool on = manipulatingEntry == entry;
|
|
bool intersects = rect.Contains(Event.current.mousePosition);
|
|
|
|
if (intersects)
|
|
hoverEntry = entry;
|
|
else if (hoverEntry == entry)
|
|
hoverEntry = null;
|
|
|
|
switch (Event.current.type)
|
|
{
|
|
case EventType.MouseDown:
|
|
if (intersects)
|
|
{
|
|
SetManipulating(entry, Event.current.button == 0 ? EManipulatingState.BeginClick : EManipulatingState.BeginContextClick);
|
|
Event.current.Use();
|
|
}
|
|
break;
|
|
case EventType.MouseUp:
|
|
if (manipulatingEntry == entry)
|
|
{
|
|
if (manipulatingState == EManipulatingState.BeginClick)
|
|
{
|
|
if (intersects && Event.current.button == 0)
|
|
SetManipulating(entry, EManipulatingState.PerformedClick);
|
|
else
|
|
SetManipulating(entry, EManipulatingState.EndClick);
|
|
}
|
|
else if (manipulatingState == EManipulatingState.BeginContextClick)
|
|
{
|
|
if (intersects && Event.current.button == 1)
|
|
SetManipulating(entry, EManipulatingState.PerformedContextClick);
|
|
else
|
|
SetManipulating(entry, EManipulatingState.EndContextClick);
|
|
}
|
|
|
|
Event.current.Use();
|
|
}
|
|
break;
|
|
case EventType.MouseDrag:
|
|
if (manipulatingEntry == entry)
|
|
Event.current.Use();
|
|
break;
|
|
case EventType.KeyDown:
|
|
break;
|
|
case EventType.KeyUp:
|
|
break;
|
|
case EventType.Repaint:
|
|
if (!ignoreIndentLevel)
|
|
{
|
|
rect.x += entry.indentLevel * 15.0f;
|
|
rect.width -= entry.indentLevel * 15.0f;
|
|
}
|
|
|
|
if (!entry.isAsset)
|
|
entry.content.image = entry.expanded ? styles.foldoutOut : styles.foldoutIn;
|
|
|
|
styles.entry.Draw(rect, entry.content, id, on, intersects);
|
|
break;
|
|
case EventType.DragUpdated:
|
|
break;
|
|
case EventType.DragPerform:
|
|
break;
|
|
case EventType.DragExited:
|
|
break;
|
|
}
|
|
}
|
|
|
|
public static Texture2D GetIcon(string path)
|
|
{
|
|
var texture = AssetDatabase.GetCachedIcon(path) as Texture2D;
|
|
|
|
if (texture == null)
|
|
texture = InternalEditorUtility.GetIconForFile(path);
|
|
|
|
return texture;
|
|
}
|
|
|
|
public static Texture2D GetFolderIcon()
|
|
{
|
|
return AssetDatabase.GetCachedIcon("Assets") as Texture2D;
|
|
}
|
|
|
|
private static void SetManipulating(Favorites.Entry entry, EManipulatingState state)
|
|
{
|
|
manipulatingEntry = entry;
|
|
manipulatingState = state;
|
|
}
|
|
|
|
public static void ClearManipulating()
|
|
{
|
|
SetManipulating(null, EManipulatingState.None);
|
|
hoverEntry = null;
|
|
}
|
|
}
|
|
} |