mirror of
https://github.com/muskit/H3VR-TNH-Quality-of-Life-Improvements.git
synced 2026-06-03 12:44:26 -07:00
132 lines
4.7 KiB
C#
132 lines
4.7 KiB
C#
using UnityEngine;
|
|
using UnityEditor.IMGUI.Controls;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace AssetBundleBrowser
|
|
{
|
|
internal class InspectTreeItem : TreeViewItem
|
|
{
|
|
internal string bundlePath { get; private set; }
|
|
|
|
internal InspectTreeItem(string path, int depth) : base(path.GetHashCode(), depth, path)
|
|
{
|
|
bundlePath = path;
|
|
}
|
|
|
|
internal InspectTreeItem(string path, int depth, string prettyName) : base(path.GetHashCode(), depth, prettyName)
|
|
{
|
|
bundlePath = path;
|
|
}
|
|
|
|
internal InspectTreeItem(string path, string parentPath, int depth, string prettyName) : base((path + parentPath).GetHashCode(), depth, prettyName)
|
|
{
|
|
bundlePath = path;
|
|
}
|
|
}
|
|
|
|
internal class InspectBundleTree : TreeView
|
|
{
|
|
private AssetBundleInspectTab m_InspectTab;
|
|
|
|
internal InspectBundleTree(TreeViewState s, AssetBundleInspectTab parent) : base(s)
|
|
{
|
|
m_InspectTab = parent;
|
|
showBorder = true;
|
|
}
|
|
|
|
protected override TreeViewItem BuildRoot()
|
|
{
|
|
TreeViewItem root = new TreeViewItem(-1, -1);
|
|
root.children = new List<TreeViewItem>();
|
|
if (m_InspectTab == null)
|
|
Debug.Log("Unknown problem in AssetBundle Browser Inspect tab. Restart Browser and try again, or file ticket on github.");
|
|
else
|
|
foreach (KeyValuePair<string, List<string>> folder in m_InspectTab.BundleList)
|
|
if (string.IsNullOrEmpty(folder.Key))
|
|
{
|
|
foreach (string path in folder.Value)
|
|
root.AddChild(new InspectTreeItem(path, 0));
|
|
}
|
|
else
|
|
{
|
|
TreeViewItem folderItem = new TreeViewItem(folder.Key.GetHashCode(), 0, folder.Key);
|
|
foreach (string path in folder.Value)
|
|
{
|
|
string prettyName = path;
|
|
if (path.StartsWith(folder.Key)) //how could it not?
|
|
prettyName = path.Remove(0, folder.Key.Length + 1);
|
|
|
|
folderItem.AddChild(new InspectTreeItem(path, folder.Key, 1, prettyName));
|
|
}
|
|
|
|
root.AddChild(folderItem);
|
|
}
|
|
|
|
return root;
|
|
}
|
|
|
|
public override void OnGUI(Rect rect)
|
|
{
|
|
base.OnGUI(rect);
|
|
if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && rect.Contains(Event.current.mousePosition)) SetSelection(new int[0], TreeViewSelectionOptions.FireSelectionChanged);
|
|
}
|
|
|
|
protected override void RowGUI(RowGUIArgs args)
|
|
{
|
|
base.RowGUI(args);
|
|
if (args.item.depth == 0)
|
|
{
|
|
int width = 16;
|
|
Rect edgeRect = new Rect(args.rowRect.xMax - width, args.rowRect.y, width, args.rowRect.height);
|
|
if (GUI.Button(edgeRect, "-"))
|
|
{
|
|
if (GetSelection().Contains(args.item.id))
|
|
{
|
|
IList<int> selection = GetSelection();
|
|
foreach (int id in selection)
|
|
{
|
|
TreeViewItem item = FindItem(id, rootItem);
|
|
if (item.depth == 0)
|
|
RemoveItem(item);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
RemoveItem(args.item);
|
|
}
|
|
|
|
m_InspectTab.RefreshBundles();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void RemoveItem(TreeViewItem item)
|
|
{
|
|
InspectTreeItem inspectItem = item as InspectTreeItem;
|
|
if (inspectItem != null)
|
|
m_InspectTab.RemoveBundlePath(inspectItem.bundlePath);
|
|
else
|
|
m_InspectTab.RemoveBundleFolder(item.displayName);
|
|
}
|
|
|
|
protected override void SelectionChanged(IList<int> selectedIds)
|
|
{
|
|
base.SelectionChanged(selectedIds);
|
|
|
|
if (selectedIds == null)
|
|
return;
|
|
|
|
if (selectedIds.Count > 0)
|
|
m_InspectTab.SetBundleItem(FindRows(selectedIds).Select(tvi => tvi as InspectTreeItem).ToList());
|
|
//m_InspectTab.SetBundleItem(FindItem(selectedIds[0], rootItem) as InspectTreeItem);
|
|
else
|
|
m_InspectTab.SetBundleItem(null);
|
|
}
|
|
|
|
protected override bool CanMultiSelect(TreeViewItem item)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
} |