Commit 1
This commit is contained in:
95
Assets/Editor/ProjectNavigation.cs
Normal file
95
Assets/Editor/ProjectNavigation.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
// ===============================================================================
|
||||
// ProjectNavigation - Navigation History for Unity Project Window
|
||||
//
|
||||
// Creator: Scove
|
||||
// Last Updated: 2026-03-05
|
||||
// Version: 1.1
|
||||
//
|
||||
// Purpose:
|
||||
// This tool provides a navigation history for the Unity Project window, allowing
|
||||
// users to quickly jump back and forward between previously visited folders.
|
||||
//
|
||||
// Key Features:
|
||||
// 1. Tracks folder selection history automatically.
|
||||
// 2. Supports Back and Forward navigation via menu items and shortcuts.
|
||||
// 3. Pings the selected folder for quick visual identification.
|
||||
//
|
||||
// How to Use:
|
||||
// 1. Place this script in an 'Editor' folder in your project.
|
||||
// 2. Use Alt + Left Arrow to navigate Back.
|
||||
// 3. Use Alt + Right Arrow to navigate Forward.
|
||||
// ===============================================================================
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Editor
|
||||
{
|
||||
public class ProjectNavigation : EditorWindow
|
||||
{
|
||||
private static List<string> history = new List<string>();
|
||||
private static int currentIndex = -1;
|
||||
private static string lastPath = "";
|
||||
|
||||
// Store the current position when selecting a folder
|
||||
[InitializeOnLoadMethod]
|
||||
static void Init()
|
||||
{
|
||||
Selection.selectionChanged += OnSelectionChanged;
|
||||
}
|
||||
|
||||
static void OnSelectionChanged()
|
||||
{
|
||||
if (Selection.activeObject != null)
|
||||
{
|
||||
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
|
||||
|
||||
// Only track if it's a valid folder and different from the last recorded path
|
||||
if (AssetDatabase.IsValidFolder(path) && path != lastPath)
|
||||
{
|
||||
// If we are in the middle of history and perform a new "direct jump",
|
||||
// clear the forward history (browser-style navigation)
|
||||
if (currentIndex < history.Count - 1)
|
||||
{
|
||||
history.RemoveRange(currentIndex + 1, history.Count - (currentIndex + 1));
|
||||
}
|
||||
|
||||
history.Add(path);
|
||||
currentIndex++;
|
||||
lastPath = path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Shortcut Alt + Left Arrow (Back)
|
||||
[MenuItem("Tools/Navigation/Back &LEFT")]
|
||||
static void Back()
|
||||
{
|
||||
if (currentIndex > 0)
|
||||
{
|
||||
currentIndex--;
|
||||
NavigateTo(history[currentIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
// Shortcut Alt + Right Arrow (Forward)
|
||||
[MenuItem("Tools/Navigation/Forward &RIGHT")]
|
||||
static void Forward()
|
||||
{
|
||||
if (currentIndex < history.Count - 1)
|
||||
{
|
||||
currentIndex++;
|
||||
NavigateTo(history[currentIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
static void NavigateTo(string path)
|
||||
{
|
||||
lastPath = path;
|
||||
Object obj = AssetDatabase.LoadAssetAtPath<Object>(path);
|
||||
Selection.activeObject = obj;
|
||||
EditorGUIUtility.PingObject(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user