Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if UNITY_EDITOR
- using System;
- using UnityEditor;
- using UnityEngine;
- #if ENABLE_INPUT_SYSTEM
- using UnityEngine.InputSystem;
- #endif
- namespace Utility.EditorUtilities
- {
- public static class ProjectWindowHoverUtility
- {
- private static Type ProjectWindowType = null;
- private static Vector2 CachedMousePosition = default;
- private static double LastUpdateTime = -3d;
- private static Color RectOutlineColour = new Color(1, 1, 1, 0.06f);
- private const string Project_Window_Type_String = "ProjectBrowser";
- private const double Update_Frequency_Time = 2d;
- [InitializeOnLoadMethod]
- private static void DisplayRectOverProjectWindowHoveredItem()
- {
- EditorApplication.update += HandleEditorUpdate;
- EditorApplication.projectWindowItemOnGUI += DrawRectOverFileInProjectWindow;
- }
- private static void HandleEditorUpdate()
- {
- if (ProjectWindowType != null)
- {
- #if ENABLE_INPUT_SYSTEM
- Mouse mouse = Mouse.current;
- if (mouse == null) return;
- Vector2 mousePosition = mouse.position.value;
- #else
- Vector2 mousePosition = Input.mousePosition;
- #endif
- if (Mathf.Approximately(mousePosition.x, CachedMousePosition.x)
- && Mathf.Approximately(mousePosition.y, CachedMousePosition.y)) return;
- CachedMousePosition = mousePosition;
- EditorWindow mouseOverWindow = EditorWindow.mouseOverWindow;
- if (mouseOverWindow == null) return;
- if (mouseOverWindow.GetType() != ProjectWindowType) return;
- mouseOverWindow.Repaint();
- }
- else if (EditorApplication.timeSinceStartup > LastUpdateTime + Update_Frequency_Time)
- {
- LastUpdateTime = EditorApplication.timeSinceStartup;
- foreach (EditorWindow window in Resources.FindObjectsOfTypeAll<EditorWindow>())
- {
- if (!window.GetType().Name.EndsWith(Project_Window_Type_String)) continue;
- ProjectWindowType = window.GetType();
- break;
- }
- }
- }
- private static void DrawRectOverFileInProjectWindow(string guid, Rect selectionRect)
- {
- selectionRect.width += selectionRect.x;
- selectionRect.x = 0;
- Vector2 mousePosition = Event.current.mousePosition;
- if (!selectionRect.Contains(mousePosition)) return;
- EditorGUI.DrawRect(selectionRect, RectOutlineColour);
- }
- }
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement