NBC修改
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 85de779f0e1c49718afffe35427bca16
|
||||
timeCreated: 1679472125
|
||||
@@ -1,106 +0,0 @@
|
||||
using UnityEditor;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC.Asset.Editor
|
||||
{
|
||||
public class BuilderWindow : EditorWindow
|
||||
{
|
||||
[MenuItem(Language.BuilderWindowNameMenuPath, false, 2)]
|
||||
public static void ShowWindow()
|
||||
{
|
||||
BuilderWindow wnd = GetWindow<BuilderWindow>(Language.BuilderWindowName, true, Defs.DockedWindowTypes);
|
||||
wnd.minSize = new Vector2(Defs.DefWindowWidth, Defs.DefWindowHeight);
|
||||
}
|
||||
|
||||
const int _splitterThickness = 2;
|
||||
|
||||
public BuildBundle SelectBundleConfig;
|
||||
|
||||
readonly VerticalSplitter _verticalSplitter = new VerticalSplitter(0.8f, 0.7f, 0.8f);
|
||||
readonly HorizontalSplitter _horizontalSplitter = new HorizontalSplitter(0.4f, 0.3f, 0.6f);
|
||||
|
||||
private BuildBundleTreeEditor _buildBundleList;
|
||||
private BuildBundleAssetsTreeEditor _buildBundleAssetsTreeEditor;
|
||||
|
||||
public void UpdateSelectedBundle(string name)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
{
|
||||
var cache = Caches.Get();
|
||||
if (cache.Bundles == null) return;
|
||||
foreach (var bundle in cache.Bundles)
|
||||
{
|
||||
if (bundle.Name != name) continue;
|
||||
SelectBundleConfig = bundle;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectBundleConfig = null;
|
||||
}
|
||||
|
||||
_buildBundleAssetsTreeEditor?.Reload();
|
||||
}
|
||||
|
||||
protected void OnEnable()
|
||||
{
|
||||
Builder.Gather();
|
||||
Styles.Initialize();
|
||||
}
|
||||
|
||||
protected void OnGUI()
|
||||
{
|
||||
var barHeight = _splitterThickness;
|
||||
Rect contentRect = new Rect(_splitterThickness, barHeight, position.width - _splitterThickness * 4,
|
||||
position.height - barHeight - _splitterThickness);
|
||||
|
||||
var resizingPackage = _horizontalSplitter.OnGUI(contentRect, out var bundleRect, out var infoRect);
|
||||
|
||||
DrawBuildBundleList(bundleRect);
|
||||
bool resizingVer = _verticalSplitter.OnGUI(infoRect, out var top, out var bot);
|
||||
DrawAssetList(top);
|
||||
DrawBuildOperation(bot);
|
||||
if (resizingPackage || resizingVer)
|
||||
Repaint();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DrawBuildBundleList(Rect rect)
|
||||
{
|
||||
if (_buildBundleList == null)
|
||||
{
|
||||
_buildBundleList = new BuildBundleTreeEditor(new TreeViewState(), this,
|
||||
BuildBundleTreeEditor.CreateDefaultMultiColumnHeaderState());
|
||||
}
|
||||
|
||||
_buildBundleList.OnGUI(rect);
|
||||
}
|
||||
|
||||
void DrawAssetList(Rect rect)
|
||||
{
|
||||
if (_buildBundleAssetsTreeEditor == null)
|
||||
{
|
||||
_buildBundleAssetsTreeEditor = new BuildBundleAssetsTreeEditor(new TreeViewState(), this,
|
||||
BuildBundleAssetsTreeEditor.CreateDefaultMultiColumnHeaderState());
|
||||
}
|
||||
|
||||
_buildBundleAssetsTreeEditor.OnGUI(rect);
|
||||
}
|
||||
|
||||
void DrawBuildOperation(Rect rect)
|
||||
{
|
||||
GUILayout.BeginArea(rect);
|
||||
GUILayout.Space(20);
|
||||
var height = rect.height * 0.4f;
|
||||
if (GUILayout.Button(Language.BuildStart, GUILayout.Height((int)height)))
|
||||
{
|
||||
Builder.Build();
|
||||
HistoryUtil.ShowLastBuildInfo();
|
||||
}
|
||||
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 304020e2c4ff4a4d82c363ebc7da11f1
|
||||
timeCreated: 1679472136
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 60848865285f41c0b85a659486785caf
|
||||
timeCreated: 1679977546
|
||||
@@ -1,234 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC.Asset.Editor
|
||||
{
|
||||
public class BuildBundleAssetsTreeEditor : TreeView
|
||||
{
|
||||
public static MultiColumnHeaderState CreateDefaultMultiColumnHeaderState()
|
||||
{
|
||||
return new MultiColumnHeaderState(GetColumns());
|
||||
}
|
||||
|
||||
private static MultiColumnHeaderState.Column[] GetColumns()
|
||||
{
|
||||
List<MultiColumnHeaderState.Column> retVal = new List<MultiColumnHeaderState.Column>();
|
||||
retVal.Add(EditUtil.GetMultiColumnHeaderColumn(Language.Path, 200));
|
||||
retVal.Add(EditUtil.GetMultiColumnHeaderColumn(Language.FileSize));
|
||||
retVal.Add(EditUtil.GetMultiColumnHeaderColumn(Language.AddressPath));
|
||||
|
||||
return retVal.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当前选中了
|
||||
/// </summary>
|
||||
private bool _contextOnItem = false;
|
||||
|
||||
BuilderWindow _window;
|
||||
public MultiColumnHeaderState HeaderState;
|
||||
|
||||
public BuildBundleAssetsTreeEditor(TreeViewState state, BuilderWindow window, MultiColumnHeaderState header) :
|
||||
base(state,
|
||||
new MultiColumnHeader(header))
|
||||
{
|
||||
_window = window;
|
||||
HeaderState = header;
|
||||
showBorder = true;
|
||||
showAlternatingRowBackgrounds = true;
|
||||
|
||||
Reload();
|
||||
}
|
||||
|
||||
private TreeViewItem _root = null;
|
||||
|
||||
protected override TreeViewItem BuildRoot()
|
||||
{
|
||||
_root = new TreeViewItem
|
||||
{
|
||||
id = -1,
|
||||
depth = -1,
|
||||
children = new List<TreeViewItem>()
|
||||
};
|
||||
int id = 0;
|
||||
|
||||
if (_window.SelectBundleConfig != null && _window.SelectBundleConfig != null)
|
||||
{
|
||||
var bundle = _window.SelectBundleConfig;
|
||||
foreach (var asset in bundle.Assets)
|
||||
{
|
||||
id++;
|
||||
var t = new AssetTreeViewItem(id, asset);
|
||||
_root.AddChild(t);
|
||||
}
|
||||
}
|
||||
|
||||
return _root;
|
||||
}
|
||||
|
||||
|
||||
#region 绘制
|
||||
|
||||
enum MyColumns
|
||||
{
|
||||
Asset,
|
||||
Size,
|
||||
Path
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect rect)
|
||||
{
|
||||
base.OnGUI(rect);
|
||||
HeaderState.AutoWidth(rect.width, 2);
|
||||
if (UnityEngine.Event.current.type == EventType.MouseDown && UnityEngine.Event.current.button == 0 &&
|
||||
rect.Contains(UnityEngine.Event.current.mousePosition))
|
||||
{
|
||||
SetSelection(Array.Empty<int>(), TreeViewSelectionOptions.FireSelectionChanged);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected override void RowGUI(RowGUIArgs args)
|
||||
{
|
||||
for (int i = 0; i < args.GetNumVisibleColumns(); ++i)
|
||||
{
|
||||
CellGUI(args.GetCellRect(i), args.item, args.GetColumn(i), ref args);
|
||||
}
|
||||
}
|
||||
|
||||
private void CellGUI(Rect cellRect, TreeViewItem item, int column, ref RowGUIArgs args)
|
||||
{
|
||||
AssetTreeViewItem assetTreeViewItem = item as AssetTreeViewItem;
|
||||
if (assetTreeViewItem == null) return;
|
||||
var assetData = assetTreeViewItem.Asset;
|
||||
Color oldColor = GUI.color;
|
||||
CenterRectUsingSingleLineHeight(ref cellRect);
|
||||
if (!File.Exists(assetData.Path))
|
||||
{
|
||||
GUI.color = Color.red;
|
||||
}
|
||||
|
||||
switch ((MyColumns)column)
|
||||
{
|
||||
case MyColumns.Asset:
|
||||
{
|
||||
var iconRect = new Rect(cellRect.x + 1, cellRect.y + 1, cellRect.height - 2, cellRect.height - 2);
|
||||
if (item.icon != null)
|
||||
{
|
||||
GUI.DrawTexture(iconRect, item.icon, ScaleMode.ScaleToFit);
|
||||
}
|
||||
|
||||
var nameRect = new Rect(cellRect.x + iconRect.xMax + 1
|
||||
, cellRect.y, cellRect.width - iconRect.width, cellRect.height);
|
||||
|
||||
DefaultGUI.Label(nameRect,
|
||||
item.displayName,
|
||||
args.selected,
|
||||
args.focused);
|
||||
}
|
||||
break;
|
||||
case MyColumns.Size:
|
||||
EditorGUI.LabelField(cellRect, GetSizeString(assetData), GUITools.DefLabelStyle);
|
||||
break;
|
||||
case MyColumns.Path:
|
||||
DefaultGUI.Label(cellRect, assetData.Address, args.selected, args.focused);
|
||||
break;
|
||||
}
|
||||
|
||||
GUI.color = oldColor;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 事件
|
||||
|
||||
/// <summary>
|
||||
/// 点击的时候
|
||||
/// </summary>
|
||||
protected override void ContextClicked()
|
||||
{
|
||||
if (HasSelection())
|
||||
{
|
||||
_contextOnItem = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void DoubleClickedItem(int id)
|
||||
{
|
||||
if (FindItem(id, rootItem) is AssetTreeViewItem assetItem)
|
||||
{
|
||||
UnityEngine.Object o = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(assetItem.Asset.Path);
|
||||
EditorGUIUtility.PingObject(o);
|
||||
Selection.activeObject = o;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ContextClickedItem(int id)
|
||||
{
|
||||
if (_contextOnItem)
|
||||
{
|
||||
_contextOnItem = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_contextOnItem = true;
|
||||
List<int> selectedNodes = new List<int>();
|
||||
foreach (var nodeID in GetSelection())
|
||||
{
|
||||
selectedNodes.Add(nodeID);
|
||||
}
|
||||
|
||||
GenericMenu menu = new GenericMenu();
|
||||
if (selectedNodes.Count == 1)
|
||||
{
|
||||
menu.AddItem(new GUIContent(Language.CopyPath), false, CopyPath, selectedNodes);
|
||||
menu.AddItem(new GUIContent(Language.CopyAddressPath), false, CopyAddressPath, selectedNodes);
|
||||
}
|
||||
|
||||
menu.ShowAsContext();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 私有方法
|
||||
|
||||
private string GetSizeString(BuildAsset asset)
|
||||
{
|
||||
if (asset.Size == 0)
|
||||
return "--";
|
||||
return EditorUtility.FormatBytes(asset.Size);
|
||||
}
|
||||
|
||||
private void CopyAddressPath(object context)
|
||||
{
|
||||
if (context is List<int> selectedNodes && selectedNodes.Count > 0)
|
||||
{
|
||||
TreeViewItem item = FindItem(selectedNodes[0], rootItem);
|
||||
if (item is AssetTreeViewItem assetTreeViewItem)
|
||||
{
|
||||
EditUtil.CopyToClipBoard(assetTreeViewItem.Asset.Address);
|
||||
Debug.Log($"copy success:{assetTreeViewItem.Asset.Address}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CopyPath(object context)
|
||||
{
|
||||
if (context is List<int> selectedNodes && selectedNodes.Count > 0)
|
||||
{
|
||||
TreeViewItem item = FindItem(selectedNodes[0], rootItem);
|
||||
if (item is AssetTreeViewItem assetTreeViewItem)
|
||||
{
|
||||
EditUtil.CopyToClipBoard(assetTreeViewItem.Asset.Path);
|
||||
Debug.Log($"copy success:{assetTreeViewItem.Asset.Path}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa3fa99bb63d4717b8c7aab8930a3953
|
||||
timeCreated: 1679978995
|
||||
@@ -1,167 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC.Asset.Editor
|
||||
{
|
||||
public class BuildBundleTreeViewItem : TreeViewItem
|
||||
{
|
||||
private BuildBundle _bundle;
|
||||
|
||||
public BuildBundle Bundle => _bundle;
|
||||
|
||||
public BuildBundleTreeViewItem(int id, BuildBundle bundle) : base(id, id, bundle.Name)
|
||||
{
|
||||
_bundle = bundle;
|
||||
}
|
||||
}
|
||||
|
||||
public class BuildBundleTreeEditor : TreeView
|
||||
{
|
||||
public static MultiColumnHeaderState CreateDefaultMultiColumnHeaderState()
|
||||
{
|
||||
return new MultiColumnHeaderState(GetColumns());
|
||||
}
|
||||
|
||||
private static MultiColumnHeaderState.Column[] GetColumns()
|
||||
{
|
||||
List<MultiColumnHeaderState.Column> retVal = new List<MultiColumnHeaderState.Column>();
|
||||
var fist = EditUtil.GetMultiColumnHeaderColumn(Language.BuildBundleName, 200, 200, 1000);
|
||||
retVal.Add(fist);
|
||||
return retVal.ToArray();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 当前选中了
|
||||
/// </summary>
|
||||
private bool mContextOnItem = false;
|
||||
|
||||
BuilderWindow _window;
|
||||
|
||||
public MultiColumnHeaderState HeaderState;
|
||||
|
||||
public BuildBundleTreeEditor(TreeViewState state, BuilderWindow window, MultiColumnHeaderState header)
|
||||
: base(state, new MultiColumnHeader(header))
|
||||
{
|
||||
HeaderState = header;
|
||||
showBorder = true;
|
||||
|
||||
showAlternatingRowBackgrounds = false;
|
||||
_window = window;
|
||||
Refresh();
|
||||
Reload();
|
||||
}
|
||||
|
||||
|
||||
private TreeViewItem _root;
|
||||
|
||||
protected override TreeViewItem BuildRoot()
|
||||
{
|
||||
_root = new TreeViewItem
|
||||
{
|
||||
id = -1,
|
||||
depth = -1,
|
||||
children = new List<TreeViewItem>()
|
||||
};
|
||||
int id = 0;
|
||||
var caches = Caches.Get();
|
||||
foreach (var bundle in caches.Bundles)
|
||||
{
|
||||
id++;
|
||||
var t = new BuildBundleTreeViewItem(id, bundle);
|
||||
_root.AddChild(t);
|
||||
}
|
||||
|
||||
return _root;
|
||||
}
|
||||
|
||||
internal void Refresh()
|
||||
{
|
||||
var selection = GetSelection();
|
||||
|
||||
SelectionChanged(selection);
|
||||
}
|
||||
|
||||
#region 绘制
|
||||
|
||||
public override void OnGUI(Rect rect)
|
||||
{
|
||||
base.OnGUI(rect);
|
||||
HeaderState.AutoWidth(rect.width);
|
||||
if (Event.current.type == EventType.MouseDown && Event.current.button == 0 &&
|
||||
rect.Contains(Event.current.mousePosition))
|
||||
{
|
||||
SetSelection(Array.Empty<int>(), TreeViewSelectionOptions.FireSelectionChanged);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制行
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
protected override void RowGUI(RowGUIArgs args)
|
||||
{
|
||||
for (int i = 0; i < args.GetNumVisibleColumns(); ++i)
|
||||
{
|
||||
CellGUI(args.GetCellRect(i), args.item, args.GetColumn(i), ref args);
|
||||
}
|
||||
}
|
||||
|
||||
private void CellGUI(Rect cellRect, TreeViewItem item, int column, ref RowGUIArgs args)
|
||||
{
|
||||
if (item is BuildBundleTreeViewItem bundleTreeViewItem)
|
||||
{
|
||||
CenterRectUsingSingleLineHeight(ref cellRect);
|
||||
if (column == 0)
|
||||
{
|
||||
var iconRect = new Rect(cellRect.x + 4, cellRect.y + 1, cellRect.height - 2, cellRect.height - 2);
|
||||
GUI.DrawTexture(iconRect, Styles.Package, ScaleMode.ScaleToFit);
|
||||
|
||||
var nameRect = new Rect(cellRect.x + iconRect.xMax + 1, cellRect.y, cellRect.width - iconRect.width,
|
||||
cellRect.height);
|
||||
DefaultGUI.Label(nameRect, item.displayName, args.selected, args.focused);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 接口实现
|
||||
|
||||
/// <summary>
|
||||
/// 是否能多选
|
||||
/// </summary>
|
||||
/// <param name="item">选中的文件</param>
|
||||
/// <returns></returns>
|
||||
protected override bool CanMultiSelect(TreeViewItem item)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override float GetCustomRowHeight(int row, TreeViewItem item)
|
||||
{
|
||||
return 30;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 事件回调
|
||||
|
||||
protected override void SelectionChanged(IList<int> selectedIds)
|
||||
{
|
||||
var selectedBundles = new List<string>();
|
||||
foreach (var id in selectedIds)
|
||||
{
|
||||
var item = FindItem(id, rootItem);
|
||||
if (item != null)
|
||||
selectedBundles.Add(item.displayName);
|
||||
}
|
||||
|
||||
_window.UpdateSelectedBundle(selectedBundles.Count > 0 ? selectedBundles[0] : string.Empty);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a3010c810f5344608b1612bd177dbd17
|
||||
timeCreated: 1679977834
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5ebef90b58f1fe744958dee119ebc373
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,192 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace NBC.Asset.Editor
|
||||
{
|
||||
public class CollectorWindow : EditorWindow
|
||||
{
|
||||
[MenuItem(Language.CollectorWindowMenuPath, false, 1)]
|
||||
public static void ShowWindow()
|
||||
{
|
||||
CollectorWindow wnd =
|
||||
GetWindow<CollectorWindow>(Language.CollectorWindowName, true, Defs.DockedWindowTypes);
|
||||
wnd.minSize = new Vector2(Defs.DefWindowWidth, Defs.DefWindowHeight);
|
||||
}
|
||||
|
||||
public PackageConfig SelectPackageConfig;
|
||||
public GroupConfig SelectGroupConfig;
|
||||
|
||||
readonly VerticalSplitter _verticalSplitter = new VerticalSplitter();
|
||||
readonly HorizontalSplitter _horizontalSplitter1 = new HorizontalSplitter(0.2f, 0.1f, 0.3f);
|
||||
readonly HorizontalSplitter _horizontalSplitter2 = new HorizontalSplitter(0.2f, 0.1f, 0.3f);
|
||||
|
||||
const int _splitterThickness = 2;
|
||||
|
||||
PackageTreeEditor _packagesList;
|
||||
GroupTreeEditor _groupsList;
|
||||
private AssetsTreeEditor _assetsList;
|
||||
private GroupInfoGUI _groupInfoGUI;
|
||||
|
||||
public void UpdateSelectedPackage(string packageName)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(packageName))
|
||||
{
|
||||
var packages = CollectorSetting.Instance.Packages;
|
||||
if (packages == null) return;
|
||||
foreach (var package in packages)
|
||||
{
|
||||
if (package.Name != packageName) continue;
|
||||
SelectPackageConfig = package;
|
||||
SelectGroupConfig = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectPackageConfig = null;
|
||||
SelectGroupConfig = null;
|
||||
}
|
||||
|
||||
_groupsList?.Reload();
|
||||
_groupsList?.SetSelection(new List<int>());
|
||||
_assetsList?.Reload();
|
||||
}
|
||||
|
||||
public void UpdateSelectedGroup(string groupName)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(groupName))
|
||||
{
|
||||
if (SelectPackageConfig == null) return;
|
||||
foreach (var group in SelectPackageConfig.Groups)
|
||||
{
|
||||
if (group.Name != groupName) continue;
|
||||
SelectGroupConfig = group;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectGroupConfig = null;
|
||||
}
|
||||
|
||||
_assetsList?.Reload();
|
||||
}
|
||||
|
||||
public void UpdateAssets()
|
||||
{
|
||||
Builder.Gather();
|
||||
_assetsList?.Reload();
|
||||
}
|
||||
|
||||
protected void OnEnable()
|
||||
{
|
||||
Builder.Gather();
|
||||
Styles.Initialize();
|
||||
}
|
||||
|
||||
protected void OnGUI()
|
||||
{
|
||||
GUI.skin.label.richText = true;
|
||||
GUI.skin.label.alignment = TextAnchor.UpperLeft;
|
||||
EditorStyles.label.richText = true;
|
||||
EditorStyles.textField.wordWrap = true;
|
||||
EditorStyles.foldout.richText = true;
|
||||
|
||||
DrawToolBar();
|
||||
var barHeight = EditorStyles.toolbar.fixedHeight + _splitterThickness;
|
||||
Rect contentRect = new Rect(_splitterThickness, barHeight, position.width - _splitterThickness * 4,
|
||||
position.height - barHeight - _splitterThickness);
|
||||
|
||||
var resizingPackage = _horizontalSplitter1.OnGUI(contentRect, out var packageRect, out var groupRect);
|
||||
|
||||
DrawPackagesList(packageRect);
|
||||
|
||||
var resizingGroup = _horizontalSplitter2.OnGUI(groupRect, out var groupListRect, out var groupInfoRect);
|
||||
|
||||
DrawGroupList(groupListRect);
|
||||
|
||||
bool resizingVer = _verticalSplitter.OnGUI(groupInfoRect, out var groupBaseInfo, out var groupAssetList);
|
||||
|
||||
DrawGroupInfo(groupBaseInfo);
|
||||
DrawAssetList(groupAssetList);
|
||||
|
||||
if (resizingPackage || resizingGroup || resizingVer)
|
||||
Repaint();
|
||||
}
|
||||
|
||||
void DrawToolBar()
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
|
||||
|
||||
var guiMode = new GUIContent(Language.Tools);
|
||||
Rect rMode = GUILayoutUtility.GetRect(guiMode, EditorStyles.toolbarDropDown);
|
||||
if (EditorGUI.DropdownButton(rMode, guiMode, FocusType.Passive, EditorStyles.toolbarDropDown))
|
||||
{
|
||||
var menu = new GenericMenu();
|
||||
menu.AddItem(new GUIContent(Language.Profiler), false, () => { });
|
||||
menu.AddItem(new GUIContent(Language.Analyse), false, () => { });
|
||||
menu.DropDown(rMode);
|
||||
}
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
if (GUILayout.Button(Language.Build, EditorStyles.toolbarButton))
|
||||
{
|
||||
Builder.Build();
|
||||
}
|
||||
|
||||
if (GUILayout.Button(Language.Save, EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
|
||||
{
|
||||
CollectorSetting.Instance.Save();
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
void DrawPackagesList(Rect rect)
|
||||
{
|
||||
if (_packagesList == null)
|
||||
{
|
||||
_packagesList = new PackageTreeEditor(new TreeViewState(), this,
|
||||
PackageTreeEditor.CreateDefaultMultiColumnHeaderState());
|
||||
}
|
||||
|
||||
_packagesList.OnGUI(rect);
|
||||
}
|
||||
|
||||
void DrawGroupList(Rect rect)
|
||||
{
|
||||
if (_groupsList == null)
|
||||
{
|
||||
_groupsList = new GroupTreeEditor(new TreeViewState(), this,
|
||||
GroupTreeEditor.CreateDefaultMultiColumnHeaderState());
|
||||
}
|
||||
|
||||
_groupsList.OnGUI(rect);
|
||||
}
|
||||
|
||||
|
||||
void DrawGroupInfo(Rect rect)
|
||||
{
|
||||
if (_groupInfoGUI == null)
|
||||
{
|
||||
_groupInfoGUI = new GroupInfoGUI(this);
|
||||
}
|
||||
|
||||
_groupInfoGUI.OnGUI(rect);
|
||||
}
|
||||
|
||||
void DrawAssetList(Rect rect)
|
||||
{
|
||||
if (_assetsList == null)
|
||||
{
|
||||
_assetsList = new AssetsTreeEditor(new TreeViewState(), this,
|
||||
AssetsTreeEditor.CreateDefaultMultiColumnHeaderState());
|
||||
}
|
||||
|
||||
_assetsList.OnGUI(rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64eabfbca2143c940a620e3fe03f8e2c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,49 +0,0 @@
|
||||
// using System.Collections.Generic;
|
||||
// using UnityEditor.IMGUI.Controls;
|
||||
//
|
||||
// namespace NBC.Asset.Editor
|
||||
// {
|
||||
// public class PackagesListTreeView : TreeView
|
||||
// {
|
||||
// private TreeViewItem mRoot = null;
|
||||
//
|
||||
// public PackagesListTreeView(TreeViewState state, AssetGroupMgr ctrl, MultiColumnHeaderState mchs) : base(state,
|
||||
// new MultiColumnHeader(mchs))
|
||||
// {
|
||||
// showBorder = true;
|
||||
//
|
||||
// showAlternatingRowBackgrounds = false;
|
||||
// mController = ctrl;
|
||||
// Refresh();
|
||||
// Reload();
|
||||
// }
|
||||
//
|
||||
// protected override TreeViewItem BuildRoot()
|
||||
// {
|
||||
// mRoot = new TreeViewItem
|
||||
// {
|
||||
// id = -1,
|
||||
// depth = -1,
|
||||
// children = new List<TreeViewItem>()
|
||||
// };
|
||||
// int id = 0;
|
||||
// var packages = CollectorSetting.Instance.Packages;
|
||||
// foreach (var package in packages)
|
||||
// {
|
||||
// id++;
|
||||
// var t = new PackageTreeViewItem(id, package);
|
||||
// mRoot.AddChild(t);
|
||||
// }
|
||||
//
|
||||
// return mRoot;
|
||||
// }
|
||||
//
|
||||
// public PackagesListTreeView(TreeViewState state) : base(state)
|
||||
// {
|
||||
// }
|
||||
//
|
||||
// public PackagesListTreeView(TreeViewState state, MultiColumnHeader multiColumnHeader) : base(state, multiColumnHeader)
|
||||
// {
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a53cbb0029c40c6a39fa066cbae38d5
|
||||
timeCreated: 1679405350
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ef2c25ab0b24e8c90faeec8bbad5cf8
|
||||
timeCreated: 1679386737
|
||||
@@ -1,239 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC.Asset.Editor
|
||||
{
|
||||
public sealed class AssetTreeViewItem : TreeViewItem
|
||||
{
|
||||
private BuildAsset _asset;
|
||||
|
||||
public BuildAsset Asset => _asset;
|
||||
|
||||
public AssetTreeViewItem(int id, BuildAsset asset) : base(id, id, asset.Path)
|
||||
{
|
||||
_asset = asset;
|
||||
icon = AssetDatabase.GetCachedIcon(asset.Path) as Texture2D;
|
||||
}
|
||||
}
|
||||
|
||||
public class AssetsTreeEditor : TreeView
|
||||
{
|
||||
public static MultiColumnHeaderState CreateDefaultMultiColumnHeaderState()
|
||||
{
|
||||
return new MultiColumnHeaderState(GetColumns());
|
||||
}
|
||||
|
||||
private static MultiColumnHeaderState.Column[] GetColumns()
|
||||
{
|
||||
List<MultiColumnHeaderState.Column> retVal = new List<MultiColumnHeaderState.Column>();
|
||||
retVal.Add(EditUtil.GetMultiColumnHeaderColumn(Language.Path,200));
|
||||
retVal.Add(EditUtil.GetMultiColumnHeaderColumn(Language.FileSize));
|
||||
retVal.Add(EditUtil.GetMultiColumnHeaderColumn(Language.AddressPath));
|
||||
return retVal.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当前选中了
|
||||
/// </summary>
|
||||
private bool mContextOnItem;
|
||||
|
||||
CollectorWindow _window;
|
||||
public MultiColumnHeaderState HeaderState;
|
||||
|
||||
public AssetsTreeEditor(TreeViewState state, CollectorWindow window, MultiColumnHeaderState header) : base(state,
|
||||
new MultiColumnHeader(header))
|
||||
{
|
||||
_window = window;
|
||||
HeaderState = header;
|
||||
showBorder = true;
|
||||
showAlternatingRowBackgrounds = true;
|
||||
|
||||
Reload();
|
||||
}
|
||||
|
||||
private TreeViewItem _root = null;
|
||||
|
||||
protected override TreeViewItem BuildRoot()
|
||||
{
|
||||
_root = new TreeViewItem
|
||||
{
|
||||
id = -1,
|
||||
depth = -1,
|
||||
children = new List<TreeViewItem>()
|
||||
};
|
||||
int id = 0;
|
||||
var cache = Caches.Get();
|
||||
if (cache.Assets.Count > 0)
|
||||
{
|
||||
if (_window.SelectPackageConfig != null && _window.SelectGroupConfig != null)
|
||||
{
|
||||
foreach (var asset in cache.Assets)
|
||||
{
|
||||
if (asset.Group == null) continue;
|
||||
if (asset.Group != _window.SelectGroupConfig)
|
||||
continue;
|
||||
id++;
|
||||
var t = new AssetTreeViewItem(id, asset);
|
||||
_root.AddChild(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _root;
|
||||
}
|
||||
|
||||
enum MyColumns
|
||||
{
|
||||
Asset,
|
||||
Size,
|
||||
Path
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect rect)
|
||||
{
|
||||
base.OnGUI(rect);
|
||||
HeaderState.AutoWidth(rect.width,2);
|
||||
if (UnityEngine.Event.current.type == EventType.MouseDown && UnityEngine.Event.current.button == 0 &&
|
||||
rect.Contains(UnityEngine.Event.current.mousePosition))
|
||||
{
|
||||
SetSelection(Array.Empty<int>(), TreeViewSelectionOptions.FireSelectionChanged);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected override void RowGUI(RowGUIArgs args)
|
||||
{
|
||||
for (int i = 0; i < args.GetNumVisibleColumns(); ++i)
|
||||
{
|
||||
CellGUI(args.GetCellRect(i), args.item, args.GetColumn(i), ref args);
|
||||
}
|
||||
}
|
||||
|
||||
private void CellGUI(Rect cellRect, TreeViewItem item, int column, ref RowGUIArgs args)
|
||||
{
|
||||
AssetTreeViewItem assetTreeViewItem = item as AssetTreeViewItem;
|
||||
if (assetTreeViewItem == null) return;
|
||||
var assetData = assetTreeViewItem.Asset;
|
||||
Color oldColor = GUI.color;
|
||||
CenterRectUsingSingleLineHeight(ref cellRect);
|
||||
if (!File.Exists(assetData.Path))
|
||||
{
|
||||
GUI.color = Color.red;
|
||||
}
|
||||
|
||||
switch ((MyColumns)column)
|
||||
{
|
||||
case MyColumns.Asset:
|
||||
{
|
||||
var iconRect = new Rect(cellRect.x + 1, cellRect.y + 1, cellRect.height - 2, cellRect.height - 2);
|
||||
if (item.icon != null)
|
||||
{
|
||||
GUI.DrawTexture(iconRect, item.icon, ScaleMode.ScaleToFit);
|
||||
}
|
||||
|
||||
var nameRect = new Rect(cellRect.x + iconRect.xMax + 1
|
||||
, cellRect.y, cellRect.width - iconRect.width, cellRect.height);
|
||||
|
||||
DefaultGUI.Label(nameRect,
|
||||
item.displayName,
|
||||
args.selected,
|
||||
args.focused);
|
||||
}
|
||||
break;
|
||||
case MyColumns.Size:
|
||||
EditorGUI.LabelField(cellRect, GetSizeString(assetData), GUITools.DefLabelStyle);
|
||||
break;
|
||||
case MyColumns.Path:
|
||||
DefaultGUI.Label(cellRect, assetData.Address, args.selected, args.focused);
|
||||
break;
|
||||
}
|
||||
|
||||
GUI.color = oldColor;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 点击的时候
|
||||
/// </summary>
|
||||
protected override void ContextClicked()
|
||||
{
|
||||
if (HasSelection())
|
||||
{
|
||||
mContextOnItem = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void DoubleClickedItem(int id)
|
||||
{
|
||||
if (FindItem(id, rootItem) is AssetTreeViewItem assetItem)
|
||||
{
|
||||
UnityEngine.Object o = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(assetItem.Asset.Path);
|
||||
EditorGUIUtility.PingObject(o);
|
||||
Selection.activeObject = o;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ContextClickedItem(int id)
|
||||
{
|
||||
if (mContextOnItem)
|
||||
{
|
||||
mContextOnItem = false;
|
||||
return;
|
||||
}
|
||||
|
||||
mContextOnItem = true;
|
||||
List<int> selectedNodes = new List<int>();
|
||||
foreach (var nodeID in GetSelection())
|
||||
{
|
||||
selectedNodes.Add(nodeID);
|
||||
}
|
||||
|
||||
GenericMenu menu = new GenericMenu();
|
||||
if (selectedNodes.Count == 1)
|
||||
{
|
||||
menu.AddItem(new GUIContent(Language.CopyPath), false, CopyPath, selectedNodes);
|
||||
menu.AddItem(new GUIContent(Language.CopyAddressPath), false, CopyAddressPath, selectedNodes);
|
||||
}
|
||||
|
||||
menu.ShowAsContext();
|
||||
}
|
||||
|
||||
|
||||
public string GetSizeString(BuildAsset asset)
|
||||
{
|
||||
if (asset.Size == 0)
|
||||
return "--";
|
||||
return EditorUtility.FormatBytes(asset.Size);
|
||||
}
|
||||
|
||||
private void CopyAddressPath(object context)
|
||||
{
|
||||
if (context is List<int> selectedNodes && selectedNodes.Count > 0)
|
||||
{
|
||||
TreeViewItem item = FindItem(selectedNodes[0], rootItem);
|
||||
if (item is AssetTreeViewItem assetTreeViewItem)
|
||||
{
|
||||
EditUtil.CopyToClipBoard(assetTreeViewItem.Asset.Address);
|
||||
Debug.Log($"copy success:{assetTreeViewItem.Asset.Address}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CopyPath(object context)
|
||||
{
|
||||
if (context is List<int> selectedNodes && selectedNodes.Count > 0)
|
||||
{
|
||||
TreeViewItem item = FindItem(selectedNodes[0], rootItem);
|
||||
if (item is AssetTreeViewItem assetTreeViewItem)
|
||||
{
|
||||
EditUtil.CopyToClipBoard(assetTreeViewItem.Asset.Path);
|
||||
Debug.Log($"copy success:{assetTreeViewItem.Asset.Path}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b65c85668d04d64aca7657c2305fd32
|
||||
timeCreated: 1679386505
|
||||
@@ -1,168 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC.Asset.Editor
|
||||
{
|
||||
public class GroupInfoGUI
|
||||
{
|
||||
private bool _groupBaseInfoFold = true;
|
||||
|
||||
private bool _groupCollectorsInfoFold = true;
|
||||
Vector2 _collectorsScrollPos;
|
||||
private CollectorWindow _window;
|
||||
private LabelGUI _labelGUI;
|
||||
|
||||
public GroupInfoGUI(CollectorWindow window)
|
||||
{
|
||||
_window = window;
|
||||
}
|
||||
|
||||
public void OnGUI(Rect rect)
|
||||
{
|
||||
if (_window == null) return;
|
||||
GUILayout.BeginArea(rect);
|
||||
if (_window.SelectGroupConfig == null)
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField(Language.NoSelectGroup);
|
||||
GUILayout.EndArea();
|
||||
return;
|
||||
}
|
||||
|
||||
DrawInfo();
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.Space();
|
||||
|
||||
DrawCollectors();
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
|
||||
void DrawInfo()
|
||||
{
|
||||
GUI.color = new Color(0, 0, 0, 0.2f);
|
||||
GUILayout.BeginHorizontal(Styles.headerBoxStyle);
|
||||
GUI.color = Color.white;
|
||||
GUILayout.Label(
|
||||
$"<b><size=18>{(_groupBaseInfoFold ? "▼" : "▶")} 【{_window.SelectGroupConfig.Name}】 基础信息</size></b>");
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var lastRect = GUILayoutUtility.GetLastRect();
|
||||
if (Event.current.type == EventType.MouseDown && lastRect.Contains(Event.current.mousePosition))
|
||||
{
|
||||
_groupBaseInfoFold = !_groupBaseInfoFold;
|
||||
Event.current.Use();
|
||||
}
|
||||
|
||||
if (!_groupBaseInfoFold) return;
|
||||
EditorGUILayout.Space();
|
||||
|
||||
if (GUITools.EnumGUILayout(Language.GroupBundleMode, _window.SelectGroupConfig, "BundleMode"))
|
||||
{
|
||||
_window.UpdateAssets();
|
||||
}
|
||||
|
||||
if (GUITools.EnumGUILayout(Language.GroupAddressMode, _window.SelectGroupConfig, "AddressMode"))
|
||||
{
|
||||
_window.UpdateAssets();
|
||||
}
|
||||
|
||||
|
||||
var newFilter =
|
||||
(FilterEnum)EditorGUILayout.EnumPopup(Language.Filter, _window.SelectGroupConfig.FilterEnum);
|
||||
|
||||
if (newFilter != _window.SelectGroupConfig.FilterEnum)
|
||||
{
|
||||
_window.SelectGroupConfig.FilterEnum = newFilter;
|
||||
|
||||
_window.UpdateAssets();
|
||||
}
|
||||
|
||||
if (_window.SelectGroupConfig.FilterEnum == FilterEnum.Custom)
|
||||
{
|
||||
var newField =
|
||||
EditorGUILayout.TextField(Language.FilterCustom, _window.SelectGroupConfig.Filter);
|
||||
if (newField != _window.SelectGroupConfig.Filter)
|
||||
{
|
||||
_window.SelectGroupConfig.Filter = newField;
|
||||
_window.UpdateAssets();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DrawLabels();
|
||||
}
|
||||
|
||||
void DrawLabels()
|
||||
{
|
||||
if (_labelGUI == null)
|
||||
{
|
||||
_labelGUI = new LabelGUI();
|
||||
}
|
||||
|
||||
_labelGUI?.OnGUI(_window.SelectGroupConfig);
|
||||
// if (_labelGUI != null && _labelGUI.Lable != _window.SelectGroupConfig.Tags)
|
||||
// {
|
||||
// _window.SelectGroupConfig.Tags = _labelGUI.Lable;
|
||||
// }
|
||||
}
|
||||
|
||||
void DrawCollectors()
|
||||
{
|
||||
GUI.color = new Color(0, 0, 0, 0.2f);
|
||||
GUILayout.BeginHorizontal(Styles.headerBoxStyle);
|
||||
GUI.color = Color.white;
|
||||
GUILayout.Label(
|
||||
$"<b><size=18>{(_groupCollectorsInfoFold ? "▼" : "▶")} 【{_window.SelectGroupConfig.Name}】 收集源 ({_window.SelectGroupConfig.Collectors.Count})</size></b>");
|
||||
GUI.backgroundColor = default(Color);
|
||||
if (GUILayout.Button(Styles.Add, GUILayout.Width(40)))
|
||||
{
|
||||
_window.SelectGroupConfig.Collectors.Add(null);
|
||||
}
|
||||
|
||||
GUI.backgroundColor = Color.white;
|
||||
GUILayout.EndHorizontal();
|
||||
var lastRect = GUILayoutUtility.GetLastRect();
|
||||
if (Event.current.type == EventType.MouseDown && lastRect.Contains(Event.current.mousePosition))
|
||||
{
|
||||
_groupCollectorsInfoFold = !_groupCollectorsInfoFold;
|
||||
Event.current.Use();
|
||||
}
|
||||
|
||||
if (!_groupCollectorsInfoFold) return;
|
||||
EditorGUILayout.Space();
|
||||
|
||||
_collectorsScrollPos = EditorGUILayout.BeginScrollView(_collectorsScrollPos);
|
||||
|
||||
if (_window.SelectGroupConfig.Collectors == null)
|
||||
{
|
||||
_window.SelectGroupConfig.Collectors = new List<Object>();
|
||||
}
|
||||
|
||||
for (int i = 0; i < _window.SelectGroupConfig.Collectors.Count; i++)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label(string.Format(Language.CollectorTitle, i), GUILayout.Width(60));
|
||||
var collector = _window.SelectGroupConfig.Collectors[i];
|
||||
var newObj = EditorGUILayout.ObjectField("", collector, typeof(Object), false);
|
||||
if (newObj != collector)
|
||||
{
|
||||
_window.SelectGroupConfig.Collectors[i] = newObj;
|
||||
_window.UpdateAssets();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("-", GUILayout.Width(20)))
|
||||
{
|
||||
_window.SelectGroupConfig.Collectors.RemoveAt(i);
|
||||
_window.UpdateAssets();
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
GUILayout.EndScrollView();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bafa30ca55c64371b097be0fc2dbfaf8
|
||||
timeCreated: 1679468108
|
||||
@@ -1,375 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC.Asset.Editor
|
||||
{
|
||||
public class GroupTreeViewItem : TreeViewItem
|
||||
{
|
||||
private GroupConfig _group;
|
||||
|
||||
public GroupConfig GroupConfig => _group;
|
||||
|
||||
public GroupTreeViewItem(int id, GroupConfig group) : base(id, id, group.Name)
|
||||
{
|
||||
_group = group;
|
||||
}
|
||||
}
|
||||
|
||||
public class GroupTreeEditor : TreeView
|
||||
{
|
||||
public static MultiColumnHeaderState CreateDefaultMultiColumnHeaderState()
|
||||
{
|
||||
return new MultiColumnHeaderState(GetColumns());
|
||||
}
|
||||
|
||||
private static MultiColumnHeaderState.Column[] GetColumns()
|
||||
{
|
||||
List<MultiColumnHeaderState.Column> retVal = new List<MultiColumnHeaderState.Column>();
|
||||
var fist = EditUtil.GetMultiColumnHeaderColumn(Language.AssetGroupName);
|
||||
retVal.Add(fist);
|
||||
return retVal.ToArray();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 当前选中了
|
||||
/// </summary>
|
||||
private bool mContextOnItem = false;
|
||||
|
||||
CollectorWindow m_Window;
|
||||
public MultiColumnHeaderState HeaderState;
|
||||
|
||||
public GroupTreeEditor(TreeViewState state, CollectorWindow window, MultiColumnHeaderState header)
|
||||
: base(state, new MultiColumnHeader(header))
|
||||
{
|
||||
showBorder = true;
|
||||
HeaderState = header;
|
||||
showAlternatingRowBackgrounds = false;
|
||||
m_Window = window;
|
||||
Refresh();
|
||||
Reload();
|
||||
}
|
||||
|
||||
|
||||
private TreeViewItem mRoot = null;
|
||||
|
||||
protected override TreeViewItem BuildRoot()
|
||||
{
|
||||
mRoot = new TreeViewItem
|
||||
{
|
||||
id = -1,
|
||||
depth = -1,
|
||||
children = new List<TreeViewItem>()
|
||||
};
|
||||
int id = 0;
|
||||
var package = m_Window.SelectPackageConfig;
|
||||
if (package != null && package.Groups.Count > 0)
|
||||
{
|
||||
foreach (var group in package.Groups)
|
||||
{
|
||||
id++;
|
||||
var t = new GroupTreeViewItem(id, group);
|
||||
mRoot.AddChild(t);
|
||||
}
|
||||
}
|
||||
|
||||
return mRoot;
|
||||
}
|
||||
|
||||
internal void Refresh()
|
||||
{
|
||||
var selection = GetSelection();
|
||||
|
||||
SelectionChanged(selection);
|
||||
}
|
||||
|
||||
private void ReloadAndSelect(IList<int> hashCodes)
|
||||
{
|
||||
Reload();
|
||||
SetSelection(hashCodes, TreeViewSelectionOptions.RevealAndFrame);
|
||||
SelectionChanged(hashCodes);
|
||||
}
|
||||
|
||||
#region 绘制
|
||||
|
||||
public override void OnGUI(Rect rect)
|
||||
{
|
||||
base.OnGUI(rect);
|
||||
HeaderState.AutoWidth(rect.width);
|
||||
if (Event.current.type == EventType.MouseDown && Event.current.button == 0 &&
|
||||
rect.Contains(Event.current.mousePosition))
|
||||
{
|
||||
SetSelection(Array.Empty<int>(), TreeViewSelectionOptions.FireSelectionChanged);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制行
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
protected override void RowGUI(RowGUIArgs args)
|
||||
{
|
||||
for (int i = 0; i < args.GetNumVisibleColumns(); ++i)
|
||||
{
|
||||
CellGUI(args.GetCellRect(i), args.item, args.GetColumn(i), ref args);
|
||||
}
|
||||
}
|
||||
|
||||
private void CellGUI(Rect cellRect, TreeViewItem item, int column, ref RowGUIArgs args)
|
||||
{
|
||||
if (item is GroupTreeViewItem groupTreeViewItem)
|
||||
{
|
||||
Color oldColor = GUI.color;
|
||||
if (!groupTreeViewItem.GroupConfig.Enable)
|
||||
{
|
||||
GUI.color = Color.gray;
|
||||
}
|
||||
|
||||
CenterRectUsingSingleLineHeight(ref cellRect);
|
||||
if (column == 0)
|
||||
{
|
||||
var iconRect = new Rect(cellRect.x + 4, cellRect.y + 1, cellRect.height - 2, cellRect.height - 2);
|
||||
GUI.DrawTexture(iconRect, Styles.Group, ScaleMode.ScaleToFit);
|
||||
|
||||
var nameRect = new Rect(cellRect.x + iconRect.xMax + 1, cellRect.y, cellRect.width - iconRect.width,
|
||||
cellRect.height);
|
||||
DefaultGUI.Label(nameRect, item.displayName, args.selected, args.focused);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 接口实现
|
||||
|
||||
/// <summary>
|
||||
/// 是否能多选
|
||||
/// </summary>
|
||||
/// <param name="item">选中的文件</param>
|
||||
/// <returns></returns>
|
||||
protected override bool CanMultiSelect(TreeViewItem item)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 能否重新命名
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
protected override bool CanRename(TreeViewItem item)
|
||||
{
|
||||
return item.displayName.Length > 0;
|
||||
}
|
||||
|
||||
protected override Rect GetRenameRect(Rect rowRect, int row, TreeViewItem item)
|
||||
{
|
||||
return rowRect;
|
||||
}
|
||||
|
||||
protected override float GetCustomRowHeight(int row, TreeViewItem item)
|
||||
{
|
||||
return 30;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 事件回调
|
||||
|
||||
/// <summary>
|
||||
/// 更改名称完成
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
protected override void RenameEnded(RenameEndedArgs args)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(args.newName) && args.newName != args.originalName)
|
||||
{
|
||||
if (NameIsOnly(args.newName))
|
||||
{
|
||||
var group = m_Window.SelectPackageConfig.Groups[args.itemID - 1];
|
||||
if (group.Name == args.originalName)
|
||||
{
|
||||
group.Name = args.newName;
|
||||
}
|
||||
|
||||
Reload();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError(Language.RepetitiveName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
args.acceptedRename = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SelectionChanged(IList<int> selectedIds)
|
||||
{
|
||||
var selectedBundles = new List<string>();
|
||||
foreach (var id in selectedIds)
|
||||
{
|
||||
var item = FindItem(id, rootItem);
|
||||
if (item != null)
|
||||
selectedBundles.Add(item.displayName);
|
||||
}
|
||||
|
||||
m_Window.UpdateSelectedGroup(selectedBundles.Count > 0 ? selectedBundles[0] : string.Empty);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 菜单事件
|
||||
|
||||
/// <summary>
|
||||
/// 点击的时候
|
||||
/// </summary>
|
||||
protected override void ContextClicked()
|
||||
{
|
||||
if (HasSelection())
|
||||
{
|
||||
mContextOnItem = false;
|
||||
return;
|
||||
}
|
||||
|
||||
GenericMenu menu = new GenericMenu();
|
||||
menu.AddItem(new GUIContent(Language.AddGroup), false, CreateResGroup, null);
|
||||
menu.ShowAsContext();
|
||||
}
|
||||
|
||||
protected override void ContextClickedItem(int id)
|
||||
{
|
||||
if (mContextOnItem)
|
||||
{
|
||||
mContextOnItem = false;
|
||||
return;
|
||||
}
|
||||
|
||||
mContextOnItem = true;
|
||||
List<int> selectedNodes = new List<int>();
|
||||
foreach (var nodeID in GetSelection())
|
||||
{
|
||||
selectedNodes.Add(nodeID);
|
||||
}
|
||||
|
||||
GenericMenu menu = new GenericMenu();
|
||||
if (selectedNodes.Count == 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
var index = selectedNodes[0] - 1;
|
||||
var package = m_Window.SelectPackageConfig.Groups[index];
|
||||
menu.AddItem(new GUIContent(package.Enable ? Language.Disable : Language.Enable), false,
|
||||
ChangeEnable,
|
||||
selectedNodes);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e);
|
||||
}
|
||||
|
||||
menu.AddItem(new GUIContent(Language.ReName), false, RenameGroupName, selectedNodes);
|
||||
menu.AddItem(new GUIContent(Language.Del), false, DeleteGroups, selectedNodes);
|
||||
}
|
||||
|
||||
menu.ShowAsContext();
|
||||
}
|
||||
|
||||
protected override void KeyEvent()
|
||||
{
|
||||
if (Event.current.keyCode == KeyCode.Delete && GetSelection().Count > 0)
|
||||
{
|
||||
var list = GetSelection();
|
||||
DeleteGroups(list.ToList());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ChangeEnable(object b)
|
||||
{
|
||||
if (b is List<int> selectedNodes)
|
||||
{
|
||||
var groups = m_Window.SelectPackageConfig.Groups;
|
||||
foreach (var id in selectedNodes)
|
||||
{
|
||||
var pack = groups[id - 1];
|
||||
pack.Enable = !pack.Enable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CreateResGroup(object context)
|
||||
{
|
||||
var group = new GroupConfig
|
||||
{
|
||||
Name = GetOnlyName()
|
||||
};
|
||||
m_Window.SelectPackageConfig.Groups.Add(group);
|
||||
var id = m_Window.SelectPackageConfig.Groups.Count;
|
||||
ReloadAndSelect(new List<int>() { id });
|
||||
}
|
||||
|
||||
void DeleteGroups(object b)
|
||||
{
|
||||
if (b is List<int> selectedNodes)
|
||||
{
|
||||
foreach (var i in selectedNodes)
|
||||
{
|
||||
var index = i - 1;
|
||||
m_Window.SelectPackageConfig.Groups.RemoveAt(index);
|
||||
}
|
||||
|
||||
Reload();
|
||||
m_Window.UpdateSelectedGroup(string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
void RenameGroupName(object context)
|
||||
{
|
||||
if (context is List<int> selectedNodes && selectedNodes.Count > 0)
|
||||
{
|
||||
TreeViewItem item = FindItem(selectedNodes[0], rootItem);
|
||||
BeginRename(item, 0.25f);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 工具方法
|
||||
|
||||
bool NameIsOnly(string name)
|
||||
{
|
||||
foreach (var group in m_Window.SelectPackageConfig.Groups)
|
||||
{
|
||||
if (group.Name == name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
string GetOnlyName()
|
||||
{
|
||||
var index = m_Window.SelectPackageConfig.Groups.Count;
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
var name = $"group{index + i}";
|
||||
if (NameIsOnly(name))
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
return $"group{DateTimeOffset.Now.ToUnixTimeSeconds()}";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ac8a0e5654140f2a53b3c6ad600f51e
|
||||
timeCreated: 1679368950
|
||||
@@ -1,399 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC.Asset.Editor
|
||||
{
|
||||
public class PackageTreeViewItem : TreeViewItem
|
||||
{
|
||||
private PackageConfig _package;
|
||||
|
||||
public PackageConfig Package => _package;
|
||||
|
||||
public PackageTreeViewItem(int id, PackageConfig package) : base(id, id, package.Name)
|
||||
{
|
||||
_package = package;
|
||||
}
|
||||
}
|
||||
|
||||
public class PackageTreeEditor : TreeView
|
||||
{
|
||||
public static MultiColumnHeaderState CreateDefaultMultiColumnHeaderState()
|
||||
{
|
||||
return new MultiColumnHeaderState(GetColumns());
|
||||
}
|
||||
|
||||
private static MultiColumnHeaderState.Column[] GetColumns()
|
||||
{
|
||||
List<MultiColumnHeaderState.Column> retVal = new List<MultiColumnHeaderState.Column>();
|
||||
var fist = EditUtil.GetMultiColumnHeaderColumn(Language.AssetPackageName);
|
||||
retVal.Add(fist);
|
||||
return retVal.ToArray();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 当前选中了
|
||||
/// </summary>
|
||||
private bool mContextOnItem = false;
|
||||
|
||||
CollectorWindow m_Window;
|
||||
public MultiColumnHeaderState HeaderState;
|
||||
public PackageTreeEditor(TreeViewState state, CollectorWindow window, MultiColumnHeaderState header)
|
||||
: base(state, new MultiColumnHeader(header))
|
||||
{
|
||||
showBorder = true;
|
||||
HeaderState = header;
|
||||
showAlternatingRowBackgrounds = false;
|
||||
m_Window = window;
|
||||
Refresh();
|
||||
Reload();
|
||||
}
|
||||
|
||||
|
||||
private TreeViewItem mRoot = null;
|
||||
|
||||
protected override TreeViewItem BuildRoot()
|
||||
{
|
||||
mRoot = new TreeViewItem
|
||||
{
|
||||
id = -1,
|
||||
depth = -1,
|
||||
children = new List<TreeViewItem>()
|
||||
};
|
||||
int id = 0;
|
||||
var packages = CollectorSetting.Instance.Packages;
|
||||
foreach (var package in packages)
|
||||
{
|
||||
id++;
|
||||
var t = new PackageTreeViewItem(id, package);
|
||||
mRoot.AddChild(t);
|
||||
}
|
||||
|
||||
return mRoot;
|
||||
}
|
||||
|
||||
internal void Refresh()
|
||||
{
|
||||
var selection = GetSelection();
|
||||
|
||||
SelectionChanged(selection);
|
||||
}
|
||||
|
||||
private void ReloadAndSelect(IList<int> hashCodes)
|
||||
{
|
||||
Reload();
|
||||
SetSelection(hashCodes, TreeViewSelectionOptions.RevealAndFrame);
|
||||
SelectionChanged(hashCodes);
|
||||
}
|
||||
|
||||
#region 绘制
|
||||
|
||||
public override void OnGUI(Rect rect)
|
||||
{
|
||||
base.OnGUI(rect);
|
||||
HeaderState.AutoWidth(rect.width);
|
||||
if (Event.current.type == EventType.MouseDown && Event.current.button == 0 &&
|
||||
rect.Contains(Event.current.mousePosition))
|
||||
{
|
||||
SetSelection(Array.Empty<int>(), TreeViewSelectionOptions.FireSelectionChanged);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制行
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
protected override void RowGUI(RowGUIArgs args)
|
||||
{
|
||||
for (int i = 0; i < args.GetNumVisibleColumns(); ++i)
|
||||
{
|
||||
CellGUI(args.GetCellRect(i), args.item, args.GetColumn(i), ref args);
|
||||
}
|
||||
}
|
||||
|
||||
private void CellGUI(Rect cellRect, TreeViewItem item, int column, ref RowGUIArgs args)
|
||||
{
|
||||
if (item is PackageTreeViewItem packageTreeViewItem)
|
||||
{
|
||||
Color oldColor = GUI.color;
|
||||
if (!packageTreeViewItem.Package.Enable)
|
||||
{
|
||||
GUI.color = Color.gray;
|
||||
}
|
||||
|
||||
CenterRectUsingSingleLineHeight(ref cellRect);
|
||||
if (column == 0)
|
||||
{
|
||||
var iconRect = new Rect(cellRect.x + 4, cellRect.y + 1, cellRect.height - 2, cellRect.height - 2);
|
||||
var icon = packageTreeViewItem.Package.Default ? Styles.Package : Styles.PackageLow;
|
||||
GUI.DrawTexture(iconRect, icon, ScaleMode.ScaleToFit);
|
||||
|
||||
var nameRect = new Rect(cellRect.x + iconRect.xMax + 1, cellRect.y, cellRect.width - iconRect.width,
|
||||
cellRect.height);
|
||||
if (packageTreeViewItem.Package.Default)
|
||||
{
|
||||
DefaultGUI.BoldLabel(nameRect, item.displayName, args.selected, args.focused);
|
||||
}
|
||||
else
|
||||
{
|
||||
DefaultGUI.Label(nameRect, item.displayName, args.selected, args.focused);
|
||||
}
|
||||
}
|
||||
|
||||
GUI.color = oldColor;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 接口实现
|
||||
|
||||
/// <summary>
|
||||
/// 是否能多选
|
||||
/// </summary>
|
||||
/// <param name="item">选中的文件</param>
|
||||
/// <returns></returns>
|
||||
protected override bool CanMultiSelect(TreeViewItem item)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 能否重新命名
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
protected override bool CanRename(TreeViewItem item)
|
||||
{
|
||||
return item.displayName.Length > 0;
|
||||
}
|
||||
|
||||
protected override Rect GetRenameRect(Rect rowRect, int row, TreeViewItem item)
|
||||
{
|
||||
return rowRect;
|
||||
}
|
||||
|
||||
protected override float GetCustomRowHeight(int row, TreeViewItem item)
|
||||
{
|
||||
return 30;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 事件回调
|
||||
|
||||
/// <summary>
|
||||
/// 更改名称完成
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
protected override void RenameEnded(RenameEndedArgs args)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(args.newName) && args.newName != args.originalName)
|
||||
{
|
||||
if (NameIsOnly(args.newName))
|
||||
{
|
||||
var packages = CollectorSetting.Instance.Packages;
|
||||
var package = packages[args.itemID - 1];
|
||||
if (package.Name == args.originalName)
|
||||
{
|
||||
package.Name = args.newName;
|
||||
}
|
||||
|
||||
Reload();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError(Language.RepetitiveName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
args.acceptedRename = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SelectionChanged(IList<int> selectedIds)
|
||||
{
|
||||
var selectedBundles = new List<string>();
|
||||
foreach (var id in selectedIds)
|
||||
{
|
||||
var item = FindItem(id, rootItem);
|
||||
if (item != null)
|
||||
selectedBundles.Add(item.displayName);
|
||||
}
|
||||
|
||||
m_Window.UpdateSelectedPackage(selectedBundles.Count > 0 ? selectedBundles[0] : string.Empty);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 菜单事件
|
||||
|
||||
/// <summary>
|
||||
/// 点击的时候
|
||||
/// </summary>
|
||||
protected override void ContextClicked()
|
||||
{
|
||||
if (HasSelection())
|
||||
{
|
||||
mContextOnItem = false;
|
||||
return;
|
||||
}
|
||||
|
||||
GenericMenu menu = new GenericMenu();
|
||||
menu.AddItem(new GUIContent(Language.AddPackage), false, CreateResGroup, null);
|
||||
menu.ShowAsContext();
|
||||
}
|
||||
|
||||
protected override void ContextClickedItem(int id)
|
||||
{
|
||||
if (mContextOnItem)
|
||||
{
|
||||
mContextOnItem = false;
|
||||
return;
|
||||
}
|
||||
|
||||
mContextOnItem = true;
|
||||
List<int> selectedNodes = new List<int>();
|
||||
foreach (var nodeID in GetSelection())
|
||||
{
|
||||
selectedNodes.Add(nodeID);
|
||||
}
|
||||
|
||||
GenericMenu menu = new GenericMenu();
|
||||
if (selectedNodes.Count == 1)
|
||||
{
|
||||
menu.AddItem(new GUIContent(Language.AddGroup), false, CreateResGroup, null);
|
||||
try
|
||||
{
|
||||
var index = selectedNodes[0] - 1;
|
||||
var package = CollectorSetting.Instance.Packages[index];
|
||||
menu.AddItem(new GUIContent(package.Enable ? Language.Disable : Language.Enable), false,
|
||||
ChangeEnable,
|
||||
selectedNodes);
|
||||
|
||||
var str = package.Default ? Language.DisableDefPackage : Language.EnableDefPackage;
|
||||
menu.AddItem(new GUIContent(str), false, ChangeDefPackage, selectedNodes);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e);
|
||||
}
|
||||
|
||||
menu.AddItem(new GUIContent(Language.ReName), false, RenameGroupName, selectedNodes);
|
||||
menu.AddItem(new GUIContent(Language.Del), false, DeleteGroups, selectedNodes);
|
||||
}
|
||||
|
||||
menu.ShowAsContext();
|
||||
}
|
||||
|
||||
protected override void KeyEvent()
|
||||
{
|
||||
if (Event.current.keyCode == KeyCode.Delete && GetSelection().Count > 0)
|
||||
{
|
||||
var list = GetSelection();
|
||||
DeleteGroups(list.ToList());
|
||||
}
|
||||
}
|
||||
|
||||
void ChangeDefPackage(object b)
|
||||
{
|
||||
if (b is List<int> selectedNodes)
|
||||
{
|
||||
var packages = CollectorSetting.Instance.Packages;
|
||||
foreach (var id in selectedNodes)
|
||||
{
|
||||
var pack = packages[id - 1];
|
||||
pack.Default = !pack.Default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ChangeEnable(object b)
|
||||
{
|
||||
if (b is List<int> selectedNodes)
|
||||
{
|
||||
var packages = CollectorSetting.Instance.Packages;
|
||||
foreach (var id in selectedNodes)
|
||||
{
|
||||
var pack = packages[id - 1];
|
||||
pack.Enable = !pack.Enable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CreateResGroup(object context)
|
||||
{
|
||||
var package = new PackageConfig()
|
||||
{
|
||||
Name = GetOnlyName()
|
||||
};
|
||||
CollectorSetting.Instance.Packages.Add(package);
|
||||
var id = CollectorSetting.Instance.Packages.Count;
|
||||
ReloadAndSelect(new List<int>() { id });
|
||||
}
|
||||
|
||||
void DeleteGroups(object b)
|
||||
{
|
||||
if (b is List<int> selectedNodes)
|
||||
{
|
||||
foreach (var i in selectedNodes)
|
||||
{
|
||||
var index = i - 1;
|
||||
CollectorSetting.Instance.Packages.RemoveAt(index);
|
||||
}
|
||||
|
||||
ReloadAndSelect(new List<int>());
|
||||
m_Window.UpdateSelectedPackage(string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
void RenameGroupName(object context)
|
||||
{
|
||||
if (context is List<int> selectedNodes && selectedNodes.Count > 0)
|
||||
{
|
||||
TreeViewItem item = FindItem(selectedNodes[0], rootItem);
|
||||
BeginRename(item, 0.25f);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 工具方法
|
||||
|
||||
bool NameIsOnly(string name)
|
||||
{
|
||||
var packages = CollectorSetting.Instance.Packages;
|
||||
foreach (var package in packages)
|
||||
{
|
||||
if (package.Name == name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
string GetOnlyName()
|
||||
{
|
||||
var index = CollectorSetting.Instance.Packages.Count;
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
var name = $"package{index + i}";
|
||||
if (NameIsOnly(name))
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
return $"package{DateTimeOffset.Now.ToUnixTimeSeconds()}";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d89d8be5d8fb487aa4f5c21469255890
|
||||
timeCreated: 1679369408
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c44a0a8c03cb4b6796415eace15ed796
|
||||
timeCreated: 1679993913
|
||||
@@ -1,103 +0,0 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace NBC.Asset.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class VerticalSplitter
|
||||
{
|
||||
[NonSerialized] Rect m_Rect = new Rect(0, 0, 0, 3);
|
||||
public Rect SplitterRect => m_Rect;
|
||||
|
||||
[FormerlySerializedAs("m_currentPercent")] [SerializeField]
|
||||
float m_CurrentPercent;
|
||||
|
||||
bool m_Resizing;
|
||||
float m_MinPercent;
|
||||
float m_MaxPercent;
|
||||
|
||||
public VerticalSplitter(float percent = .6f, float minPer = .4f, float maxPer = .9f)
|
||||
{
|
||||
m_CurrentPercent = percent;
|
||||
m_MinPercent = minPer;
|
||||
m_MaxPercent = maxPer;
|
||||
}
|
||||
|
||||
public bool OnGUI(Rect content, out Rect top, out Rect bot)
|
||||
{
|
||||
m_Rect.x = content.x;
|
||||
m_Rect.y = (int)(content.y + content.height * m_CurrentPercent);
|
||||
m_Rect.width = content.width;
|
||||
|
||||
EditorGUIUtility.AddCursorRect(m_Rect, MouseCursor.ResizeVertical);
|
||||
if (Event.current.type == EventType.MouseDown && m_Rect.Contains(Event.current.mousePosition))
|
||||
m_Resizing = true;
|
||||
|
||||
if (m_Resizing)
|
||||
{
|
||||
EditorGUIUtility.AddCursorRect(content, MouseCursor.ResizeVertical);
|
||||
|
||||
var mousePosInRect = Event.current.mousePosition.y - content.y;
|
||||
m_CurrentPercent = Mathf.Clamp(mousePosInRect / content.height, m_MinPercent, m_MaxPercent);
|
||||
m_Rect.y = Mathf.Min((int)(content.y + content.height * m_CurrentPercent),
|
||||
content.yMax - m_Rect.height);
|
||||
if (Event.current.type == EventType.MouseUp)
|
||||
m_Resizing = false;
|
||||
}
|
||||
|
||||
top = new Rect(content.x, content.y, content.width, m_Rect.yMin - content.yMin);
|
||||
bot = new Rect(content.x, m_Rect.yMax, content.width, content.yMax - m_Rect.yMax);
|
||||
return m_Resizing;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Serializable]
|
||||
public class HorizontalSplitter
|
||||
{
|
||||
[NonSerialized] Rect m_Rect = new Rect(0, 0, 3, 0);
|
||||
|
||||
public Rect SplitterRect => m_Rect;
|
||||
|
||||
[FormerlySerializedAs("m_currentPercent")] [SerializeField]
|
||||
float m_CurrentPercent;
|
||||
|
||||
bool m_Resizing;
|
||||
float m_MinPercent;
|
||||
float m_MaxPercent;
|
||||
|
||||
public HorizontalSplitter(float percent = .6f, float minPer = .4f, float maxPer = .9f)
|
||||
{
|
||||
m_CurrentPercent = percent;
|
||||
m_MinPercent = minPer;
|
||||
m_MaxPercent = maxPer;
|
||||
}
|
||||
|
||||
public bool OnGUI(Rect content, out Rect left, out Rect right)
|
||||
{
|
||||
m_Rect.y = content.y;
|
||||
m_Rect.x = (int)(content.x + content.width * m_CurrentPercent);
|
||||
m_Rect.height = content.height;
|
||||
|
||||
EditorGUIUtility.AddCursorRect(m_Rect, MouseCursor.ResizeHorizontal);
|
||||
if (Event.current.type == EventType.MouseDown && m_Rect.Contains(Event.current.mousePosition))
|
||||
m_Resizing = true;
|
||||
|
||||
if (m_Resizing)
|
||||
{
|
||||
EditorGUIUtility.AddCursorRect(content, MouseCursor.ResizeHorizontal);
|
||||
|
||||
var mousePosInRect = Event.current.mousePosition.x - content.x;
|
||||
m_CurrentPercent = Mathf.Clamp(mousePosInRect / content.width, m_MinPercent, m_MaxPercent);
|
||||
m_Rect.x = Mathf.Min((int)(content.x + content.width * m_CurrentPercent), content.xMax - m_Rect.width);
|
||||
if (Event.current.type == EventType.MouseUp)
|
||||
m_Resizing = false;
|
||||
}
|
||||
left = new Rect(content.x, content.y, content.width * m_CurrentPercent, content.height);
|
||||
right = new Rect(m_Rect.xMax, content.y, content.width - content.width * m_CurrentPercent, content.height);
|
||||
return m_Resizing;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5ff764a382104fe1970089f4ae39dd83
|
||||
timeCreated: 1679805403
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d1b3fb95b2f24d68876df91fc6676eda
|
||||
timeCreated: 1680142226
|
||||
@@ -1,283 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEditor;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC.Asset.Editor
|
||||
{
|
||||
public class HistoryWindow : EditorWindow
|
||||
{
|
||||
[MenuItem(Language.HistoryWindowNameMenuPath, false, 4)]
|
||||
public static void ShowWindow()
|
||||
{
|
||||
var s = string.Empty;
|
||||
HistoryWindow wnd = GetWindow<HistoryWindow>(Language.HistoryWindowName, true, Defs.DockedWindowTypes);
|
||||
wnd.minSize = new Vector2(Defs.DefWindowWidth, Defs.DefWindowHeight);
|
||||
}
|
||||
|
||||
|
||||
const int _splitterThickness = 2;
|
||||
|
||||
public VersionHistoryData SelectVersion;
|
||||
|
||||
/// <summary>
|
||||
/// 选中需要比较的版本
|
||||
/// </summary>
|
||||
public VersionHistoryData SelectCompareVersion;
|
||||
|
||||
readonly VerticalSplitter _verticalSplitter = new VerticalSplitter(0.7f, 0.7f, 0.8f);
|
||||
readonly HorizontalSplitter _horizontalSplitter = new HorizontalSplitter(0.3f, 0.3f, 0.4f);
|
||||
|
||||
private HistoryVersionTreeEditor _versionList;
|
||||
private HistoryBundleTreeEditor _bundleTreeEditor;
|
||||
|
||||
private List<VersionHistoryData> _versionHistory = new List<VersionHistoryData>();
|
||||
|
||||
public List<VersionHistoryData> ShowVersionHistory => _versionHistory;
|
||||
|
||||
public void UpdateCompareSelectedVersion(string name)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
{
|
||||
foreach (var version in _versionHistory)
|
||||
{
|
||||
if (version.ShowName != name) continue;
|
||||
SelectCompareVersion = version;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectCompareVersion = null;
|
||||
}
|
||||
|
||||
_versionList?.Reload();
|
||||
}
|
||||
|
||||
public void UpdateSelectedVersion(string name)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
{
|
||||
foreach (var version in _versionHistory)
|
||||
{
|
||||
if (version.ShowName != name) continue;
|
||||
SelectVersion = version;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectVersion = null;
|
||||
}
|
||||
|
||||
_bundleTreeEditor?.Reload();
|
||||
}
|
||||
|
||||
public void ReloadVersions()
|
||||
{
|
||||
_versionHistory = HistoryUtil.GetHistoryVersions();
|
||||
if (SelectCompareVersion == null && _versionHistory.Count > 1)
|
||||
{
|
||||
SelectCompareVersion = _versionHistory[1];
|
||||
}
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
ReloadVersions();
|
||||
UpdateSelectedVersion(string.Empty);
|
||||
}
|
||||
|
||||
protected void OnEnable()
|
||||
{
|
||||
SelectVersion = null;
|
||||
SelectCompareVersion = null;
|
||||
ReloadVersions();
|
||||
Styles.Initialize();
|
||||
}
|
||||
|
||||
protected void OnGUI()
|
||||
{
|
||||
var barHeight = _splitterThickness;
|
||||
Rect contentRect = new Rect(_splitterThickness, barHeight, position.width - _splitterThickness * 4,
|
||||
position.height - _splitterThickness);
|
||||
|
||||
var resizingPackage = _horizontalSplitter.OnGUI(contentRect, out var bundleRect, out var infoRect);
|
||||
|
||||
DrawVersionList(bundleRect);
|
||||
bool resizingVer = _verticalSplitter.OnGUI(infoRect, out var top, out var bot);
|
||||
DrawBundleList(top);
|
||||
DrawCompareInfo(bot);
|
||||
if (resizingPackage || resizingVer)
|
||||
Repaint();
|
||||
}
|
||||
|
||||
|
||||
void DrawVersionList(Rect rect)
|
||||
{
|
||||
if (_versionList == null)
|
||||
{
|
||||
_versionList = new HistoryVersionTreeEditor(new TreeViewState(), this,
|
||||
HistoryVersionTreeEditor.CreateDefaultMultiColumnHeaderState());
|
||||
}
|
||||
|
||||
_versionList.OnGUI(rect);
|
||||
}
|
||||
|
||||
void DrawBundleList(Rect rect)
|
||||
{
|
||||
if (_bundleTreeEditor == null)
|
||||
{
|
||||
_bundleTreeEditor = new HistoryBundleTreeEditor(new TreeViewState(), this,
|
||||
HistoryBundleTreeEditor.CreateDefaultMultiColumnHeaderState());
|
||||
}
|
||||
|
||||
_bundleTreeEditor.OnGUI(rect);
|
||||
}
|
||||
|
||||
void DrawCompareInfo(Rect rect)
|
||||
{
|
||||
if (SelectVersion == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GUILayout.BeginArea(rect);
|
||||
|
||||
if (SelectCompareVersion == null)
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField(Language.NoSelectHistoryCompareVersion);
|
||||
}
|
||||
else if (SelectCompareVersion == SelectVersion)
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField(Language.NoSelectHistoryCompareOneVersion);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawCompareDetails();
|
||||
}
|
||||
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
|
||||
void DrawCompareDetails()
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
var compareInfo = HistoryUtil.CompareVersion(SelectVersion, SelectCompareVersion);
|
||||
var simpleData = compareInfo.SimpleChangeData;
|
||||
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
var strAdd = GetPackageChangeInfo(simpleData.PackageAddBundle);
|
||||
EditorGUILayout.TextField(Language.HistoryAddBundleCount, strAdd);
|
||||
if (GUILayout.Button(Language.Copy, GUILayout.Width(50)))
|
||||
{
|
||||
EditUtil.CopyToClipBoard(strAdd);
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
var strChange = GetPackageChangeInfo(simpleData.PackageChangeBundle);
|
||||
EditorGUILayout.TextField(Language.HistoryChangeBundleCount, strChange);
|
||||
if (GUILayout.Button(Language.Copy, GUILayout.Width(50)))
|
||||
{
|
||||
EditUtil.CopyToClipBoard(strChange);
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
var strRemove = GetPackageChangeInfo(simpleData.PackageRemoveBundle);
|
||||
EditorGUILayout.TextField(Language.HistoryRemoveBundleCount, strRemove);
|
||||
if (GUILayout.Button(Language.Copy, GUILayout.Width(50)))
|
||||
{
|
||||
EditUtil.CopyToClipBoard(strRemove);
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
var strDownload = GetPackageDownloadInfo(simpleData.PackageDownloadSize);
|
||||
EditorGUILayout.TextField(Language.HistoryDownloadSize, strDownload);
|
||||
if (GUILayout.Button(Language.Copy, GUILayout.Width(50)))
|
||||
{
|
||||
EditUtil.CopyToClipBoard(strDownload);
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
|
||||
EditorGUILayout.Space();
|
||||
if (GUILayout.Button(Language.HistoryCompareBuild, GUILayout.Height(40)))
|
||||
{
|
||||
var saveJson =
|
||||
JsonConvert.SerializeObject(compareInfo,
|
||||
Formatting.Indented); //JsonUtility.ToJson(compareInfo, true);
|
||||
|
||||
var saveFolder =
|
||||
EditorUtility.OpenFolderPanel(Language.BuildProfilerTips, Environment.CurrentDirectory, "");
|
||||
|
||||
|
||||
var savePath = $"{saveFolder}/history_compare_{DateTime.Now.ToString("yyyyMMddHHmmss")}.json";
|
||||
File.WriteAllText(savePath, saveJson);
|
||||
EditorUtility.DisplayDialog(Language.Tips, Language.Success + $", path={savePath}", Language.Confirm);
|
||||
}
|
||||
}
|
||||
|
||||
string GetPackageChangeInfo(Dictionary<string, List<string>> dictionary)
|
||||
{
|
||||
var all = 0;
|
||||
var packageStr = "";
|
||||
var index = 0;
|
||||
foreach (var key in dictionary.Keys)
|
||||
{
|
||||
index++;
|
||||
var value = dictionary[key];
|
||||
all += value.Count;
|
||||
packageStr += $"{key}={value.Count}";
|
||||
if (index < dictionary.Count)
|
||||
{
|
||||
packageStr += "、 ";
|
||||
}
|
||||
}
|
||||
|
||||
var str = string.Format(Language.HistoryBundleChangeTitle, all, packageStr);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
string GetPackageDownloadInfo(Dictionary<string, long> dictionary)
|
||||
{
|
||||
long all = 0;
|
||||
var packageStr = "";
|
||||
var index = 0;
|
||||
foreach (var key in dictionary.Keys)
|
||||
{
|
||||
index++;
|
||||
var value = dictionary[key];
|
||||
all += value;
|
||||
packageStr += $"{key}={Util.GetFriendlySize(value)}";
|
||||
if (index < dictionary.Count)
|
||||
{
|
||||
packageStr += "、 ";
|
||||
}
|
||||
}
|
||||
|
||||
var str = string.Format(Language.HistoryBundleChangeTitle, Util.GetFriendlySize(all), packageStr);
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c688eedf74e6448b950e6975f675b3b1
|
||||
timeCreated: 1680142237
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a69a28535dc4e99b1b9bdf70b380d4d
|
||||
timeCreated: 1680143027
|
||||
@@ -1,230 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC.Asset.Editor
|
||||
{
|
||||
public sealed class HistoryBundleViewItem : TreeViewItem
|
||||
{
|
||||
private BundleData _bundle;
|
||||
|
||||
public BundleData Bundle => _bundle;
|
||||
|
||||
public HistoryBundleViewItem(int id, BundleData bundle) : base(id, id, bundle.Name)
|
||||
{
|
||||
_bundle = bundle;
|
||||
}
|
||||
}
|
||||
|
||||
public class HistoryBundleTreeEditor : TreeView
|
||||
{
|
||||
public static MultiColumnHeaderState CreateDefaultMultiColumnHeaderState()
|
||||
{
|
||||
return new MultiColumnHeaderState(GetColumns());
|
||||
}
|
||||
|
||||
private static MultiColumnHeaderState.Column[] GetColumns()
|
||||
{
|
||||
List<MultiColumnHeaderState.Column> retVal = new List<MultiColumnHeaderState.Column>();
|
||||
retVal.Add(EditUtil.GetMultiColumnHeaderColumn(Language.HistoryBundleName, 260));
|
||||
retVal.Add(EditUtil.GetMultiColumnHeaderColumn(Language.HistorySize, 70, 50, 100));
|
||||
retVal.Add(EditUtil.GetMultiColumnHeaderColumn(Language.HistoryHash, 240,200,300));
|
||||
|
||||
return retVal.ToArray();
|
||||
}
|
||||
enum MyColumns
|
||||
{
|
||||
BundleName,
|
||||
Size,
|
||||
Hash,
|
||||
}
|
||||
/// <summary>
|
||||
/// 当前选中了
|
||||
/// </summary>
|
||||
private bool _contextOnItem = false;
|
||||
|
||||
HistoryWindow _window;
|
||||
public MultiColumnHeaderState HeaderState;
|
||||
|
||||
public HistoryBundleTreeEditor(TreeViewState state, HistoryWindow window, MultiColumnHeaderState header) :
|
||||
base(state,
|
||||
new MultiColumnHeader(header))
|
||||
{
|
||||
_window = window;
|
||||
HeaderState = header;
|
||||
showBorder = true;
|
||||
showAlternatingRowBackgrounds = true;
|
||||
|
||||
Reload();
|
||||
}
|
||||
|
||||
private TreeViewItem _root = null;
|
||||
|
||||
protected override TreeViewItem BuildRoot()
|
||||
{
|
||||
_root = new TreeViewItem
|
||||
{
|
||||
id = -1,
|
||||
depth = -1,
|
||||
children = new List<TreeViewItem>()
|
||||
};
|
||||
int id = 0;
|
||||
|
||||
if (_window.SelectVersion != null)
|
||||
{
|
||||
List<BundleData> list = new List<BundleData>();
|
||||
foreach (var package in _window.SelectVersion.Packages)
|
||||
{
|
||||
list.AddRange(package.Bundles);
|
||||
}
|
||||
|
||||
|
||||
foreach (var bundle in list)
|
||||
{
|
||||
id++;
|
||||
var t = new HistoryBundleViewItem(id, bundle);
|
||||
_root.AddChild(t);
|
||||
}
|
||||
}
|
||||
|
||||
return _root;
|
||||
}
|
||||
|
||||
|
||||
#region 绘制
|
||||
|
||||
|
||||
public override void OnGUI(Rect rect)
|
||||
{
|
||||
base.OnGUI(rect);
|
||||
HeaderState.AutoWidth(rect.width, 0);
|
||||
if (UnityEngine.Event.current.type == EventType.MouseDown && UnityEngine.Event.current.button == 0 &&
|
||||
rect.Contains(UnityEngine.Event.current.mousePosition))
|
||||
{
|
||||
SetSelection(Array.Empty<int>(), TreeViewSelectionOptions.FireSelectionChanged);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected override void RowGUI(RowGUIArgs args)
|
||||
{
|
||||
for (int i = 0; i < args.GetNumVisibleColumns(); ++i)
|
||||
{
|
||||
CellGUI(args.GetCellRect(i), args.item, args.GetColumn(i), ref args);
|
||||
}
|
||||
}
|
||||
|
||||
private void CellGUI(Rect cellRect, TreeViewItem item, int column, ref RowGUIArgs args)
|
||||
{
|
||||
HistoryBundleViewItem bundleTreeViewItem = item as HistoryBundleViewItem;
|
||||
if (bundleTreeViewItem == null) return;
|
||||
var bundleData = bundleTreeViewItem.Bundle;
|
||||
Color oldColor = GUI.color;
|
||||
CenterRectUsingSingleLineHeight(ref cellRect);
|
||||
// if (!File.Exists(assetData.Path))
|
||||
// {
|
||||
// GUI.color = Color.red;
|
||||
// }
|
||||
|
||||
switch ((MyColumns)column)
|
||||
{
|
||||
case MyColumns.BundleName:
|
||||
EditorGUI.LabelField(cellRect, bundleData.Name);
|
||||
break;
|
||||
case MyColumns.Hash:
|
||||
EditorGUI.LabelField(cellRect, bundleData.Hash);
|
||||
break;
|
||||
case MyColumns.Size:
|
||||
EditorGUI.LabelField(cellRect, Util.GetFriendlySize(bundleData.Size), GUITools.DefLabelStyle);
|
||||
break;
|
||||
}
|
||||
|
||||
GUI.color = oldColor;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 事件
|
||||
|
||||
/// <summary>
|
||||
/// 点击的时候
|
||||
/// </summary>
|
||||
protected override void ContextClicked()
|
||||
{
|
||||
if (HasSelection())
|
||||
{
|
||||
_contextOnItem = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void DoubleClickedItem(int id)
|
||||
{
|
||||
if (FindItem(id, rootItem) is AssetTreeViewItem assetItem)
|
||||
{
|
||||
UnityEngine.Object o = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(assetItem.Asset.Path);
|
||||
EditorGUIUtility.PingObject(o);
|
||||
Selection.activeObject = o;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ContextClickedItem(int id)
|
||||
{
|
||||
if (_contextOnItem)
|
||||
{
|
||||
_contextOnItem = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_contextOnItem = true;
|
||||
List<int> selectedNodes = new List<int>();
|
||||
foreach (var nodeID in GetSelection())
|
||||
{
|
||||
selectedNodes.Add(nodeID);
|
||||
}
|
||||
|
||||
GenericMenu menu = new GenericMenu();
|
||||
if (selectedNodes.Count == 1)
|
||||
{
|
||||
menu.AddItem(new GUIContent(Language.CopyPath), false, CopyPath, selectedNodes);
|
||||
menu.AddItem(new GUIContent(Language.CopyAddressPath), false, CopyAddressPath, selectedNodes);
|
||||
}
|
||||
|
||||
menu.ShowAsContext();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 私有方法
|
||||
|
||||
private void CopyAddressPath(object context)
|
||||
{
|
||||
if (context is List<int> selectedNodes && selectedNodes.Count > 0)
|
||||
{
|
||||
TreeViewItem item = FindItem(selectedNodes[0], rootItem);
|
||||
if (item is AssetTreeViewItem assetTreeViewItem)
|
||||
{
|
||||
EditUtil.CopyToClipBoard(assetTreeViewItem.Asset.Address);
|
||||
Debug.Log($"copy success:{assetTreeViewItem.Asset.Address}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CopyPath(object context)
|
||||
{
|
||||
if (context is List<int> selectedNodes && selectedNodes.Count > 0)
|
||||
{
|
||||
TreeViewItem item = FindItem(selectedNodes[0], rootItem);
|
||||
if (item is AssetTreeViewItem assetTreeViewItem)
|
||||
{
|
||||
EditUtil.CopyToClipBoard(assetTreeViewItem.Asset.Path);
|
||||
Debug.Log($"copy success:{assetTreeViewItem.Asset.Path}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de6b7df37676439d8f14de84f5028069
|
||||
timeCreated: 1680146377
|
||||
@@ -1,328 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC.Asset.Editor
|
||||
{
|
||||
public class HistoryVersionTreeViewItem : TreeViewItem
|
||||
{
|
||||
private VersionHistoryData _version;
|
||||
|
||||
public VersionHistoryData Version => _version;
|
||||
|
||||
public HistoryVersionTreeViewItem(int id, VersionHistoryData version) : base(id, id, version.ShowName)
|
||||
{
|
||||
_version = version;
|
||||
}
|
||||
}
|
||||
|
||||
public class HistoryVersionTreeEditor : TreeView
|
||||
{
|
||||
public static MultiColumnHeaderState CreateDefaultMultiColumnHeaderState()
|
||||
{
|
||||
return new MultiColumnHeaderState(GetColumns());
|
||||
}
|
||||
|
||||
private static MultiColumnHeaderState.Column[] GetColumns()
|
||||
{
|
||||
List<MultiColumnHeaderState.Column> retVal = new List<MultiColumnHeaderState.Column>();
|
||||
var fist = EditUtil.GetMultiColumnHeaderColumn(Language.HistoryVersionName, 200, 200, 1000);
|
||||
retVal.Add(fist);
|
||||
return retVal.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当前选中了
|
||||
/// </summary>
|
||||
private bool _contextOnItem = false;
|
||||
|
||||
HistoryWindow _window;
|
||||
public MultiColumnHeaderState HeaderState;
|
||||
|
||||
public HistoryVersionTreeEditor(TreeViewState state, HistoryWindow window, MultiColumnHeaderState header) :
|
||||
base(state,
|
||||
new MultiColumnHeader(header))
|
||||
{
|
||||
_window = window;
|
||||
HeaderState = header;
|
||||
showBorder = true;
|
||||
showAlternatingRowBackgrounds = true;
|
||||
|
||||
Reload();
|
||||
}
|
||||
|
||||
|
||||
private TreeViewItem _root;
|
||||
|
||||
protected override TreeViewItem BuildRoot()
|
||||
{
|
||||
_root = new TreeViewItem
|
||||
{
|
||||
id = -1,
|
||||
depth = -1,
|
||||
children = new List<TreeViewItem>()
|
||||
};
|
||||
int id = 0;
|
||||
if (_window.ShowVersionHistory != null)
|
||||
{
|
||||
foreach (var version in _window.ShowVersionHistory)
|
||||
{
|
||||
id++;
|
||||
var t = new HistoryVersionTreeViewItem(id, version);
|
||||
_root.AddChild(t);
|
||||
}
|
||||
}
|
||||
|
||||
return _root;
|
||||
}
|
||||
|
||||
internal void Refresh()
|
||||
{
|
||||
var selection = GetSelection();
|
||||
|
||||
SelectionChanged(selection);
|
||||
}
|
||||
|
||||
#region 绘制
|
||||
|
||||
public override void OnGUI(Rect rect)
|
||||
{
|
||||
base.OnGUI(rect);
|
||||
HeaderState.AutoWidth(rect.width);
|
||||
if (Event.current.type == EventType.MouseDown && Event.current.button == 0 &&
|
||||
rect.Contains(Event.current.mousePosition))
|
||||
{
|
||||
SetSelection(Array.Empty<int>(), TreeViewSelectionOptions.FireSelectionChanged);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制行
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
protected override void RowGUI(RowGUIArgs args)
|
||||
{
|
||||
for (int i = 0; i < args.GetNumVisibleColumns(); ++i)
|
||||
{
|
||||
CellGUI(args.GetCellRect(i), args.item, args.GetColumn(i), ref args);
|
||||
}
|
||||
}
|
||||
|
||||
private void CellGUI(Rect cellRect, TreeViewItem item, int column, ref RowGUIArgs args)
|
||||
{
|
||||
if (item is HistoryVersionTreeViewItem versionTreeViewItem)
|
||||
{
|
||||
CenterRectUsingSingleLineHeight(ref cellRect);
|
||||
if (column == 0)
|
||||
{
|
||||
var iconRect = new Rect(cellRect.x + 4, cellRect.y + 1, cellRect.height - 2, cellRect.height - 2);
|
||||
GUI.DrawTexture(iconRect, Styles.Package, ScaleMode.ScaleToFit);
|
||||
|
||||
var nameRect = new Rect(cellRect.x + iconRect.xMax + 1, cellRect.y, cellRect.width - iconRect.width,
|
||||
cellRect.height);
|
||||
|
||||
if (_window.SelectCompareVersion != null &&
|
||||
_window.SelectCompareVersion.ShowName == item.displayName)
|
||||
{
|
||||
DefaultGUI.Label(nameRect, "[√]" + item.displayName, args.selected, args.focused);
|
||||
}
|
||||
else
|
||||
{
|
||||
DefaultGUI.Label(nameRect, item.displayName, args.selected, args.focused);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 接口实现
|
||||
|
||||
/// <summary>
|
||||
/// 点击的时候
|
||||
/// </summary>
|
||||
protected override void ContextClicked()
|
||||
{
|
||||
if (HasSelection())
|
||||
{
|
||||
_contextOnItem = false;
|
||||
return;
|
||||
}
|
||||
|
||||
GenericMenu menu = new GenericMenu();
|
||||
menu.AddItem(new GUIContent(Language.Refresh), false, o => { _window.Refresh(); }, null);
|
||||
menu.ShowAsContext();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否能多选
|
||||
/// </summary>
|
||||
/// <param name="item">选中的文件</param>
|
||||
/// <returns></returns>
|
||||
protected override bool CanMultiSelect(TreeViewItem item)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override float GetCustomRowHeight(int row, TreeViewItem item)
|
||||
{
|
||||
return 30;
|
||||
}
|
||||
|
||||
protected override void ContextClickedItem(int id)
|
||||
{
|
||||
if (_contextOnItem)
|
||||
{
|
||||
_contextOnItem = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_contextOnItem = true;
|
||||
List<int> selectedNodes = new List<int>();
|
||||
foreach (var nodeID in GetSelection())
|
||||
{
|
||||
selectedNodes.Add(nodeID);
|
||||
}
|
||||
|
||||
GenericMenu menu = new GenericMenu();
|
||||
if (selectedNodes.Count == 1)
|
||||
{
|
||||
var index = selectedNodes[0] - 1;
|
||||
var select = false;
|
||||
if (_window.SelectCompareVersion != null && _window.ShowVersionHistory != null)
|
||||
{
|
||||
if (_window.ShowVersionHistory.Count > index)
|
||||
{
|
||||
var version = _window.ShowVersionHistory[index];
|
||||
if (version != null)
|
||||
{
|
||||
if (version.ShowName == _window.SelectCompareVersion.ShowName)
|
||||
{
|
||||
select = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (select)
|
||||
{
|
||||
menu.AddItem(new GUIContent(Language.HistoryUnSelectCompare), false, HistoryUnSelectCompare,
|
||||
selectedNodes);
|
||||
}
|
||||
else
|
||||
{
|
||||
menu.AddItem(new GUIContent(Language.HistorySelectCompare), false, HistorySelectCompare,
|
||||
selectedNodes);
|
||||
}
|
||||
|
||||
menu.AddItem(new GUIContent(Language.HistoryUse), false, HistoryUse,
|
||||
selectedNodes);
|
||||
menu.AddItem(new GUIContent(Language.HistoryCopyToFolder), false, HistoryCopyToFolder,
|
||||
selectedNodes);
|
||||
menu.AddItem(new GUIContent(Language.HistoryDelete), false, HistoryDelete,
|
||||
selectedNodes);
|
||||
}
|
||||
|
||||
menu.ShowAsContext();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 事件回调
|
||||
|
||||
protected override void SelectionChanged(IList<int> selectedIds)
|
||||
{
|
||||
var selectedBundles = new List<string>();
|
||||
foreach (var id in selectedIds)
|
||||
{
|
||||
var item = FindItem(id, rootItem);
|
||||
if (item != null)
|
||||
selectedBundles.Add(item.displayName);
|
||||
}
|
||||
|
||||
_window.UpdateSelectedVersion(selectedBundles.Count > 0 ? selectedBundles[0] : string.Empty);
|
||||
}
|
||||
|
||||
private void HistoryUse(object context)
|
||||
{
|
||||
if (context is List<int> selectedNodes && selectedNodes.Count > 0)
|
||||
{
|
||||
TreeViewItem item = FindItem(selectedNodes[0], rootItem);
|
||||
if (item is HistoryVersionTreeViewItem versionTreeViewItem)
|
||||
{
|
||||
versionTreeViewItem.Version?.CopyToStreamingAssets();
|
||||
EditorUtility.DisplayDialog(Language.Tips, Language.Success, Language.Confirm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void HistoryCopyToFolder(object context)
|
||||
{
|
||||
if (context is List<int> selectedNodes && selectedNodes.Count > 0)
|
||||
{
|
||||
TreeViewItem item = FindItem(selectedNodes[0], rootItem);
|
||||
if (item is HistoryVersionTreeViewItem versionTreeViewItem)
|
||||
{
|
||||
var saveFolder =
|
||||
EditorUtility.OpenFolderPanel(Language.BuildProfilerTips, Environment.CurrentDirectory, "");
|
||||
versionTreeViewItem.Version?.CopyToFolder(saveFolder + "/");
|
||||
EditorUtility.DisplayDialog(Language.Tips, Language.Success + $", path:{saveFolder}",
|
||||
Language.Confirm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void HistoryDelete(object context)
|
||||
{
|
||||
if (context is List<int> selectedNodes && selectedNodes.Count > 0)
|
||||
{
|
||||
TreeViewItem item = FindItem(selectedNodes[0], rootItem);
|
||||
if (item is HistoryVersionTreeViewItem versionTreeViewItem)
|
||||
{
|
||||
if (versionTreeViewItem.Version != null)
|
||||
{
|
||||
HistoryUtil.DeleteHistoryVersions(versionTreeViewItem.Version.FileName);
|
||||
_window.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void HistorySelectCompare(object context)
|
||||
{
|
||||
if (context is List<int> selectedNodes && selectedNodes.Count > 0)
|
||||
{
|
||||
TreeViewItem item = FindItem(selectedNodes[0], rootItem);
|
||||
if (item is HistoryVersionTreeViewItem versionTreeViewItem)
|
||||
{
|
||||
if (versionTreeViewItem.Version != null)
|
||||
{
|
||||
_window.UpdateCompareSelectedVersion(versionTreeViewItem.Version.ShowName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void HistoryUnSelectCompare(object context)
|
||||
{
|
||||
if (_window.SelectCompareVersion == null) return;
|
||||
if (context is List<int> selectedNodes && selectedNodes.Count > 0)
|
||||
{
|
||||
TreeViewItem item = FindItem(selectedNodes[0], rootItem);
|
||||
if (item is HistoryVersionTreeViewItem versionTreeViewItem)
|
||||
{
|
||||
var v = versionTreeViewItem.Version;
|
||||
if (v != null && _window.SelectCompareVersion.ShowName == v.ShowName)
|
||||
{
|
||||
_window.UpdateCompareSelectedVersion(string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ee881dcc31542749793be9f5a205289
|
||||
timeCreated: 1680143063
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2e81e596c994206a6f118b862803ec2
|
||||
timeCreated: 1679586791
|
||||
@@ -1,112 +0,0 @@
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC.Asset.Editor
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public class ResInspectorUI
|
||||
{
|
||||
static ResInspectorUI()
|
||||
{
|
||||
UnityEditor.Editor.finishedDefaultHeaderGUI -= OnPostHeaderGUI;
|
||||
UnityEditor.Editor.finishedDefaultHeaderGUI += OnPostHeaderGUI;
|
||||
}
|
||||
|
||||
#region style
|
||||
|
||||
private static GUIStyle _style_bg;
|
||||
|
||||
private static GUIStyle style_bg
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_style_bg == null)
|
||||
{
|
||||
_style_bg = new GUIStyle(EditorStyles.helpBox);
|
||||
}
|
||||
|
||||
return _style_bg;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private static void OnPostHeaderGUI(UnityEditor.Editor editor)
|
||||
{
|
||||
if (editor.targets.Length == 1)
|
||||
{
|
||||
var t = editor.target;
|
||||
try
|
||||
{
|
||||
ShowRulePath(FindAsset(t));
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
// XLog.LogError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static BuildAsset FindAsset(Object t)
|
||||
{
|
||||
var path = AssetDatabase.GetAssetPath(t);
|
||||
var cache = Caches.Get();
|
||||
var buildAsset = cache.Assets.Find(p => p.Path == path);
|
||||
return buildAsset;
|
||||
}
|
||||
|
||||
private static void ShowRulePath(BuildAsset ruleAsset)
|
||||
{
|
||||
if (ruleAsset != null)
|
||||
{
|
||||
GUILayout.Space(10);
|
||||
EditorGUILayout.BeginVertical(style_bg);
|
||||
|
||||
|
||||
if (ruleAsset.Address != ruleAsset.Path)
|
||||
{
|
||||
EditorGUILayout.LabelField(Language.InspectorUITitle, EditorStyles.centeredGreyMiniLabel);
|
||||
DrawAddressPath(ruleAsset);
|
||||
DrawPath(ruleAsset);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.LabelField(Language.InspectorUITitleNotOpen, EditorStyles.centeredGreyMiniLabel);
|
||||
DrawPath(ruleAsset);
|
||||
}
|
||||
|
||||
|
||||
EditorGUILayout.Separator();
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
}
|
||||
|
||||
private static void DrawAddressPath(BuildAsset ruleAsset)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label(Language.InspectorUIAddressPath, GUILayout.MaxWidth(65));
|
||||
EditorGUILayout.TextField(ruleAsset.Address);
|
||||
if (GUILayout.Button(Language.Copy, GUILayout.Width(40)))
|
||||
{
|
||||
EditUtil.CopyToClipBoard(ruleAsset.Address);
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
private static void DrawPath(BuildAsset ruleAsset)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label(Language.InspectorUIPath, GUILayout.MaxWidth(65));
|
||||
EditorGUILayout.TextField(ruleAsset.Path);
|
||||
if (GUILayout.Button(Language.Copy, GUILayout.Width(40)))
|
||||
{
|
||||
EditUtil.CopyToClipBoard(ruleAsset.Path);
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e9d152b95ff4e8c8b680638a49eb471
|
||||
timeCreated: 1679586795
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1fee7201455f42508993118250b8ed78
|
||||
timeCreated: 1679544185
|
||||
@@ -1,32 +0,0 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC.Asset.Editor
|
||||
{
|
||||
public class LabelGUI
|
||||
{
|
||||
Rect buttonRect;
|
||||
|
||||
public void OnGUI(ISelectTag selectTag)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
GUILayout.Label(Language.Tags, GUILayout.Width(148));
|
||||
EditorGUI.BeginDisabledGroup(true);
|
||||
EditorGUILayout.TextField(string.Empty, selectTag.ShowTags);
|
||||
EditorGUI.EndDisabledGroup();
|
||||
if (GUILayout.Button("+", GUILayout.Width(20)))
|
||||
{
|
||||
PopupWindow.Show(buttonRect, new LabelMaskPopupContent(buttonRect, selectTag));
|
||||
}
|
||||
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
buttonRect = GUILayoutUtility.GetLastRect();
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d7a20ce70574a6dbd7ea8b68e91c88f
|
||||
timeCreated: 1679552946
|
||||
@@ -1,244 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC.Asset.Editor
|
||||
{
|
||||
public class LabelMaskPopupContent : PopupWindowContent
|
||||
{
|
||||
private GUIStyle _toggleMixed;
|
||||
|
||||
// private readonly GUIContent _manageLabelsButtonContent =
|
||||
// EditorGUIUtility.TrIconContent("_Popup@2x", "Manage Labels");
|
||||
|
||||
private readonly GUIStyle _toolbarButtonStyle = "RL FooterButton";
|
||||
|
||||
private readonly GUIStyle _hintLabelStyle;
|
||||
|
||||
private readonly SearchField _searchField;
|
||||
private string _searchValue;
|
||||
private readonly List<GUIStyle> _searchStyles;
|
||||
private Rect _activatorRect;
|
||||
private float _labelToggleControlRectHeight;
|
||||
private float _labelToggleControlRectWidth;
|
||||
private string _controlToFocus;
|
||||
|
||||
private int _lastItemCount = -1;
|
||||
private Vector2 _rect;
|
||||
|
||||
private List<string> _labelsAll;
|
||||
private readonly List<string> _labels;
|
||||
|
||||
private ISelectTag _selectTag;
|
||||
|
||||
public LabelMaskPopupContent(Rect activatorRect, ISelectTag selectTag)
|
||||
{
|
||||
_selectTag = selectTag;
|
||||
_labels = new List<string>();
|
||||
if (!string.IsNullOrEmpty(selectTag.ShowTags))
|
||||
{
|
||||
_labels.AddRange(selectTag.ShowTags.Split(","));
|
||||
}
|
||||
_labels.Remove(string.Empty);
|
||||
_searchField = new SearchField();
|
||||
_activatorRect = activatorRect;
|
||||
_searchStyles = new List<GUIStyle>
|
||||
{
|
||||
GUITools.GetStyle("ToolbarSeachTextField"),
|
||||
GUITools.GetStyle("ToolbarSeachCancelButton"),
|
||||
GUITools.GetStyle("ToolbarSeachCancelButtonEmpty")
|
||||
};
|
||||
|
||||
_hintLabelStyle = new GUIStyle(GUI.skin.label)
|
||||
{
|
||||
fontSize = 10,
|
||||
fontStyle = FontStyle.Italic,
|
||||
richText = true
|
||||
};
|
||||
}
|
||||
|
||||
public override Vector2 GetWindowSize()
|
||||
{
|
||||
if (_labelsAll == null)
|
||||
_labelsAll = GetLabelNamesOrderedSelectedFirst();
|
||||
|
||||
if (_lastItemCount != _labelsAll.Count)
|
||||
{
|
||||
int maxLen = 0;
|
||||
string maxStr = "";
|
||||
for (int i = 0; i < _labelsAll.Count; i++)
|
||||
{
|
||||
var len = _labelsAll[i].Length;
|
||||
if (len > maxLen)
|
||||
{
|
||||
maxLen = len;
|
||||
maxStr = _labelsAll[i];
|
||||
}
|
||||
}
|
||||
|
||||
var content = new GUIContent(maxStr);
|
||||
var size = GUI.skin.toggle.CalcSize(content);
|
||||
_labelToggleControlRectHeight = Mathf.Ceil(size.y + GUI.skin.toggle.margin.top);
|
||||
_labelToggleControlRectWidth = size.x + 16;
|
||||
|
||||
float width = Mathf.Clamp(Mathf.Max(size.x, _activatorRect.width), 170, 500);
|
||||
float labelAreaHeight = _labelsAll.Count *
|
||||
(_labelToggleControlRectHeight + GUI.skin.toggle.margin.bottom);
|
||||
float toolbarAreaHeight = 30 + _hintLabelStyle.CalcHeight(new GUIContent(maxStr), width);
|
||||
float paddingHeight = 6;
|
||||
float height = labelAreaHeight + toolbarAreaHeight + paddingHeight;
|
||||
height = Mathf.Clamp(height, 50, 300);
|
||||
_rect = new Vector2(width, height);
|
||||
_lastItemCount = _labelsAll.Count;
|
||||
}
|
||||
|
||||
return _rect;
|
||||
}
|
||||
|
||||
void SetLabelForEntries(string label, bool value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(label)) return;
|
||||
if (value)
|
||||
{
|
||||
if (!_labels.Contains(label))
|
||||
{
|
||||
_labels.Add(label);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_labels.Remove(label);
|
||||
}
|
||||
|
||||
_selectTag.ShowTags = string.Join(",", _labels);
|
||||
}
|
||||
|
||||
List<string> GetLabelNamesOrderedSelectedFirst()
|
||||
{
|
||||
var labels = new List<string>(Defs.UserTags.Count);
|
||||
labels.AddRange(Defs.UserTags);
|
||||
return labels;
|
||||
}
|
||||
|
||||
Vector2 m_ScrollPosition;
|
||||
|
||||
public override void OnGUI(Rect fullRect)
|
||||
{
|
||||
int count = -1;
|
||||
if (_labelsAll == null)
|
||||
_labelsAll = GetLabelNamesOrderedSelectedFirst();
|
||||
|
||||
var areaRect = new Rect(fullRect.xMin + 3, fullRect.yMin + 3, fullRect.width - 6, fullRect.height - 6);
|
||||
GUILayout.BeginArea(areaRect);
|
||||
|
||||
GUILayoutUtility.GetRect(areaRect.width, 1);
|
||||
|
||||
Rect searchRect = EditorGUILayout.GetControlRect();
|
||||
_searchValue = _searchField.OnGUI(searchRect, _searchValue, _searchStyles[0], _searchStyles[1],
|
||||
_searchStyles[2]);
|
||||
|
||||
EditorGUI.BeginDisabledGroup(true);
|
||||
string labelText;
|
||||
int searchLabelIndex = _labelsAll.IndexOf(_searchValue);
|
||||
if (searchLabelIndex >= 0)
|
||||
{
|
||||
count = _labels.Contains(_searchValue) ? 1 : 0;
|
||||
|
||||
labelText = string.Format(
|
||||
count > 0 ? Language.LabelHintSearchFoundIsDisabled : Language.LabelHintSearchFoundIsEnabled,
|
||||
_searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
labelText = !string.IsNullOrEmpty(_searchValue)
|
||||
? string.Format(Language.LabelHintSearchFoundIsEnabled, _searchValue)
|
||||
: Language.LabelHintIdle;
|
||||
}
|
||||
|
||||
Rect hintRect = EditorGUILayout.GetControlRect(true,
|
||||
_hintLabelStyle.CalcHeight(new GUIContent(labelText), fullRect.width), _hintLabelStyle);
|
||||
hintRect.x -= 3;
|
||||
hintRect.width += 6;
|
||||
hintRect.y -= 3;
|
||||
EditorGUI.LabelField(hintRect, new GUIContent(labelText), _hintLabelStyle);
|
||||
EditorGUI.EndDisabledGroup();
|
||||
|
||||
if (Event.current.isKey &&
|
||||
(Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter) &&
|
||||
_searchField.HasFocus())
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_searchValue))
|
||||
{
|
||||
if (searchLabelIndex >= 0)
|
||||
{
|
||||
SetLabelForEntries(_searchValue, count <= 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Defs.AddTag(_searchValue);
|
||||
SetLabelForEntries(_searchValue, true);
|
||||
_labelsAll.Insert(0, _searchValue);
|
||||
}
|
||||
|
||||
_controlToFocus = _searchValue;
|
||||
GUI.ScrollTo(new Rect(0, searchLabelIndex * 19, 0, 0));
|
||||
_searchValue = "";
|
||||
_lastItemCount = -1;
|
||||
|
||||
Event.current.Use();
|
||||
GUIUtility.ExitGUI();
|
||||
editorWindow.Repaint();
|
||||
}
|
||||
}
|
||||
|
||||
var scrollViewHeight = areaRect.height - (hintRect.y + hintRect.height + 2);
|
||||
m_ScrollPosition = EditorGUILayout.BeginScrollView(m_ScrollPosition, false, false);
|
||||
Vector2 yPositionDrawRange = new Vector2(m_ScrollPosition.y - 19, m_ScrollPosition.y + scrollViewHeight);
|
||||
|
||||
for (int i = 0; i < _labelsAll.Count; i++)
|
||||
{
|
||||
var labelName = _labelsAll[i];
|
||||
if (!string.IsNullOrEmpty(_searchValue))
|
||||
{
|
||||
if (labelName.IndexOf(_searchValue, StringComparison.OrdinalIgnoreCase) < 0)
|
||||
continue;
|
||||
}
|
||||
|
||||
var toggleRect = EditorGUILayout.GetControlRect(GUILayout.Width(_labelToggleControlRectWidth),
|
||||
GUILayout.Height(_labelToggleControlRectHeight));
|
||||
if (toggleRect.height > 1)
|
||||
{
|
||||
// only draw toggles if they are in view
|
||||
if (toggleRect.y < yPositionDrawRange.x || toggleRect.y > yPositionDrawRange.y)
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var oldState = _labels.Contains(labelName);
|
||||
|
||||
GUI.SetNextControlName(labelName);
|
||||
var newState = EditorGUI.ToggleLeft(toggleRect, new GUIContent(labelName), oldState);
|
||||
EditorGUI.showMixedValue = false;
|
||||
if (oldState != newState)
|
||||
{
|
||||
SetLabelForEntries(labelName, newState);
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.EndScrollView();
|
||||
GUILayout.EndArea();
|
||||
|
||||
if (Event.current.type == EventType.Repaint &&
|
||||
_labelsAll != null && _controlToFocus != null)
|
||||
{
|
||||
GUI.FocusControl(_controlToFocus);
|
||||
_controlToFocus = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bc72c242e83946cc93372777f829ee16
|
||||
timeCreated: 1679543808
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d28dbbfb07c40fd9d621945c99e2e16
|
||||
timeCreated: 1679322317
|
||||
@@ -1,475 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEditor;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace NBC.Asset.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class ProfilerInfo
|
||||
{
|
||||
public int CurrentIndex;
|
||||
public List<DebugInfo> DebugInfos = new List<DebugInfo>();
|
||||
|
||||
public DebugInfo Current
|
||||
{
|
||||
get
|
||||
{
|
||||
if (CurrentIndex < DebugInfos.Count && DebugInfos.Count > 0)
|
||||
{
|
||||
return DebugInfos[CurrentIndex];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(DebugInfo debugInfo)
|
||||
{
|
||||
DebugInfos.Add(debugInfo);
|
||||
CurrentIndex = DebugInfos.Count - 1;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
CurrentIndex = 0;
|
||||
DebugInfos.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public class ProfilerWindow : EditorWindow
|
||||
{
|
||||
[MenuItem(Language.ProfilerWindowNameMenuPath, false, 3)]
|
||||
public static void ShowWindow()
|
||||
{
|
||||
ProfilerWindow wnd =
|
||||
GetWindow<ProfilerWindow>(Language.ProfilerWindowName, true, Defs.DockedWindowTypes);
|
||||
wnd.minSize = new Vector2(Defs.DefWindowWidth, Defs.DefWindowHeight);
|
||||
}
|
||||
|
||||
enum ShowModel
|
||||
{
|
||||
Asset,
|
||||
Bundle
|
||||
}
|
||||
|
||||
enum DataModel
|
||||
{
|
||||
Local,
|
||||
Remote
|
||||
}
|
||||
|
||||
GUIContent _prevFrameIcon;
|
||||
GUIContent _nextFrameIcon;
|
||||
|
||||
private List<GUIStyle> _searchStyles;
|
||||
private SearchField _searchField;
|
||||
private string _searchValue;
|
||||
private ShowModel _showModel = ShowModel.Asset;
|
||||
private DataModel _dataModel = DataModel.Local;
|
||||
private string _remoteUrl;
|
||||
|
||||
readonly VerticalSplitter _verticalSplitter = new VerticalSplitter();
|
||||
|
||||
private string _selectName;
|
||||
|
||||
private ProfilerInfo _profilerInfo = new ProfilerInfo();
|
||||
// private int _currentIndex;
|
||||
// private readonly List<DebugInfo> _debugInfos = new List<DebugInfo>();
|
||||
|
||||
ProfilerAssetListView _assetListView;
|
||||
ProfilerBundleListView _bundleListView;
|
||||
|
||||
private bool _refreshListView;
|
||||
|
||||
protected void OnEnable()
|
||||
{
|
||||
_remoteUrl = EditorPrefs.GetString("ProfilerRemoteUrl", "http://127.0.0.1:8080");
|
||||
EditorApplication.playModeStateChanged -= PlayModeStateChanged;
|
||||
EditorApplication.playModeStateChanged += PlayModeStateChanged;
|
||||
_prevFrameIcon = EditorGUIUtility.IconContent("Profiler.PrevFrame", Language.PrevFrame);
|
||||
_nextFrameIcon = EditorGUIUtility.IconContent("Profiler.NextFrame", Language.NextFrame);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
EditorApplication.playModeStateChanged -= PlayModeStateChanged;
|
||||
}
|
||||
|
||||
private void PlayModeStateChanged(PlayModeStateChange playModeStateChange)
|
||||
{
|
||||
if (playModeStateChange == PlayModeStateChange.EnteredPlayMode)
|
||||
{
|
||||
_profilerInfo?.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnGUI()
|
||||
{
|
||||
_refreshListView = false;
|
||||
if (_searchField == null) _searchField = new SearchField();
|
||||
if (_profilerInfo == null) _profilerInfo = new ProfilerInfo();
|
||||
DrawToolBar();
|
||||
|
||||
var r = EditorGUILayout.GetControlRect();
|
||||
Rect contentRect = new Rect(r.x, r.y, r.width, position.height - r.y);
|
||||
|
||||
bool resizingVer = _verticalSplitter.OnGUI(contentRect, out var top, out var bot);
|
||||
|
||||
var selectName = _selectName;
|
||||
|
||||
if (_showModel == ShowModel.Asset)
|
||||
{
|
||||
DrawAssetView(top);
|
||||
DrawBundleView(bot);
|
||||
if (_assetListView != null)
|
||||
{
|
||||
selectName = _assetListView.SelectName;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawBundleView(top);
|
||||
DrawAssetView(bot);
|
||||
if (_assetListView != null)
|
||||
{
|
||||
selectName = _bundleListView.SelectName;
|
||||
}
|
||||
}
|
||||
|
||||
if (selectName != _selectName)
|
||||
{
|
||||
_selectName = selectName;
|
||||
_refreshListView = true;
|
||||
}
|
||||
|
||||
if (_refreshListView)
|
||||
{
|
||||
_refreshListView = false;
|
||||
SetShowInfo();
|
||||
}
|
||||
|
||||
if (resizingVer)
|
||||
Repaint();
|
||||
}
|
||||
|
||||
void DrawToolBar()
|
||||
{
|
||||
if (_searchStyles == null)
|
||||
{
|
||||
_searchStyles = new List<GUIStyle>
|
||||
{
|
||||
GUITools.GetStyle("ToolbarSeachTextField"),
|
||||
GUITools.GetStyle("ToolbarSeachCancelButton"),
|
||||
GUITools.GetStyle("ToolbarSeachCancelButtonEmpty")
|
||||
};
|
||||
}
|
||||
|
||||
EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
|
||||
|
||||
var showModeName = _showModel == ShowModel.Asset
|
||||
? Language.ProfilerAssetMode
|
||||
: Language.ProfilerBundleMode;
|
||||
var guiMode = new GUIContent(Language.ProfilerShowMode + showModeName);
|
||||
Rect rMode = GUILayoutUtility.GetRect(guiMode, EditorStyles.toolbarDropDown);
|
||||
if (EditorGUI.DropdownButton(rMode, guiMode, FocusType.Passive, EditorStyles.toolbarDropDown))
|
||||
{
|
||||
var menu = new GenericMenu();
|
||||
menu.AddItem(new GUIContent(Language.ProfilerAssetMode), false,
|
||||
() =>
|
||||
{
|
||||
_showModel = ShowModel.Asset;
|
||||
_refreshListView = true;
|
||||
});
|
||||
menu.AddItem(new GUIContent(Language.ProfilerBundleMode), false,
|
||||
() =>
|
||||
{
|
||||
_showModel = ShowModel.Bundle;
|
||||
_refreshListView = true;
|
||||
});
|
||||
menu.DropDown(rMode);
|
||||
}
|
||||
|
||||
var dataModeName = _dataModel == DataModel.Local
|
||||
? Language.ProfilerLocalData
|
||||
: Language.ProfilerRemoteData;
|
||||
var dataMode = new GUIContent(Language.ProfilerDataMode + dataModeName);
|
||||
Rect rdataMode = GUILayoutUtility.GetRect(dataMode, EditorStyles.toolbarDropDown);
|
||||
if (EditorGUI.DropdownButton(rdataMode, dataMode, FocusType.Passive, EditorStyles.toolbarDropDown))
|
||||
{
|
||||
var menu = new GenericMenu();
|
||||
menu.AddItem(new GUIContent(Language.ProfilerLocalData), false,
|
||||
() =>
|
||||
{
|
||||
_dataModel = DataModel.Local;
|
||||
_refreshListView = true;
|
||||
});
|
||||
menu.AddItem(new GUIContent(Language.ProfilerRemoteData), false,
|
||||
() =>
|
||||
{
|
||||
_dataModel = DataModel.Remote;
|
||||
_refreshListView = true;
|
||||
});
|
||||
menu.DropDown(rdataMode);
|
||||
}
|
||||
|
||||
|
||||
if (GUILayout.Button(Language.ImportProfiler, EditorStyles.toolbarButton))
|
||||
{
|
||||
DebugInfoImport();
|
||||
}
|
||||
|
||||
if (GUILayout.Button(Language.BuildProfiler, EditorStyles.toolbarButton))
|
||||
{
|
||||
DebugInfoBuild();
|
||||
}
|
||||
|
||||
if (GUILayout.Button(Language.Clear, EditorStyles.toolbarButton))
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.Label(_profilerInfo.CurrentIndex >= _profilerInfo.DebugInfos.Count
|
||||
? Language.CurrentFrame
|
||||
: Language.CurrentFrame + $"{_profilerInfo.Current.Frame} (" + (_profilerInfo.CurrentIndex + 1) +
|
||||
"/" +
|
||||
(_profilerInfo.DebugInfos.Count) + ")",
|
||||
EditorStyles.miniLabel);
|
||||
|
||||
using (new EditorGUI.DisabledScope(_profilerInfo.CurrentIndex <= 0))
|
||||
{
|
||||
if (GUILayout.Button(_prevFrameIcon, EditorStyles.toolbarButton))
|
||||
{
|
||||
_profilerInfo.CurrentIndex--;
|
||||
_refreshListView = true;
|
||||
}
|
||||
}
|
||||
|
||||
using (new EditorGUI.DisabledScope(_profilerInfo.CurrentIndex >= (_profilerInfo.DebugInfos.Count - 1)))
|
||||
{
|
||||
if (GUILayout.Button(_nextFrameIcon, EditorStyles.toolbarButton))
|
||||
{
|
||||
_profilerInfo.CurrentIndex++;
|
||||
_refreshListView = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (GUILayout.Button(Language.Current, EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
|
||||
{
|
||||
GetDebugInfo();
|
||||
}
|
||||
|
||||
|
||||
Rect searchRect = EditorGUILayout.GetControlRect();
|
||||
var newSearchValue = _searchField.OnGUI(searchRect, _searchValue, _searchStyles[0], _searchStyles[1],
|
||||
_searchStyles[2]);
|
||||
if (newSearchValue != _searchValue)
|
||||
{
|
||||
_searchValue = newSearchValue;
|
||||
_refreshListView = true;
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
if (_dataModel == DataModel.Remote)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
|
||||
GUILayout.Label(Language.ProfilerRemoteUrl, GUILayout.Width(80));
|
||||
var newUrl = EditorGUILayout.TextField(string.Empty, _remoteUrl);
|
||||
if (_remoteUrl != null && newUrl != _remoteUrl)
|
||||
{
|
||||
_remoteUrl = newUrl;
|
||||
EditorPrefs.SetString("ProfilerRemoteUrl", _remoteUrl);
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
|
||||
void DrawAssetView(Rect rect)
|
||||
{
|
||||
if (_assetListView == null)
|
||||
{
|
||||
_assetListView = new ProfilerAssetListView(new TreeViewState(), this,
|
||||
ProfilerAssetListView.CreateDefaultMultiColumnHeaderState());
|
||||
}
|
||||
|
||||
_assetListView.OnGUI(rect);
|
||||
}
|
||||
|
||||
void DrawBundleView(Rect rect)
|
||||
{
|
||||
if (_bundleListView == null)
|
||||
{
|
||||
_bundleListView = new ProfilerBundleListView(new TreeViewState(), this,
|
||||
ProfilerBundleListView.CreateDefaultMultiColumnHeaderState());
|
||||
}
|
||||
|
||||
_bundleListView.OnGUI(rect);
|
||||
}
|
||||
|
||||
|
||||
private void DebugInfoBuild()
|
||||
{
|
||||
var saveFolder =
|
||||
EditorUtility.OpenFolderPanel(Language.BuildProfilerTips, Environment.CurrentDirectory, "");
|
||||
var savePath = $"{saveFolder}/debug_info_{DateTime.Now.ToString("yyyyMMddHHmmss")}.json";
|
||||
var json = JsonUtility.ToJson(_profilerInfo, true);
|
||||
File.WriteAllText(savePath, json);
|
||||
EditorUtility.DisplayDialog(Language.Tips, Language.Success + $", path:{savePath}", Language.Confirm);
|
||||
}
|
||||
|
||||
private void DebugInfoImport()
|
||||
{
|
||||
var path = EditorUtility.OpenFilePanel(Language.ImportProfilerTips, Environment.CurrentDirectory, "json");
|
||||
if (File.Exists(path))
|
||||
{
|
||||
var data = Util.ReadJson<ProfilerInfo>(path);
|
||||
if (data != null)
|
||||
{
|
||||
_profilerInfo = data;
|
||||
_refreshListView = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Clear()
|
||||
{
|
||||
_profilerInfo?.Clear();
|
||||
_assetListView?.SetData(null);
|
||||
_bundleListView?.SetData(null);
|
||||
}
|
||||
|
||||
private void GetDebugInfo()
|
||||
{
|
||||
if (_dataModel == DataModel.Local)
|
||||
{
|
||||
var debugInfo = Assets.GetDebugInfos();
|
||||
_profilerInfo.Add(debugInfo);
|
||||
_refreshListView = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
GetRemoteDebugInfo();
|
||||
}
|
||||
}
|
||||
|
||||
private async void GetRemoteDebugInfo()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_remoteUrl))
|
||||
{
|
||||
EditorUtility.DisplayDialog(Language.Error, Language.ProfilerRemoteUrlIsNull, Language.Confirm);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = await EditUtil.GetHttpRequest(_remoteUrl);
|
||||
if (!string.IsNullOrEmpty(result))
|
||||
{
|
||||
Debug.Log("请求远程数据====" + result);
|
||||
try
|
||||
{
|
||||
var data = JsonUtility.FromJson<DebugInfo>(result);
|
||||
if (data == null) return;
|
||||
_profilerInfo.Add(data);
|
||||
_refreshListView = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError($"解析远程数据失败,e={e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetShowInfo()
|
||||
{
|
||||
if (_profilerInfo.CurrentIndex >= _profilerInfo.DebugInfos.Count) return;
|
||||
SetAssetShowInfo();
|
||||
SetBundleShowInfo();
|
||||
}
|
||||
|
||||
private void SetAssetShowInfo()
|
||||
{
|
||||
List<DebugAssetInfo> list = new List<DebugAssetInfo>();
|
||||
var currentDebugInfo = _profilerInfo.Current;
|
||||
if (_showModel == ShowModel.Asset)
|
||||
{
|
||||
list.AddRange(currentDebugInfo.AssetInfos);
|
||||
}
|
||||
else
|
||||
{
|
||||
//bundle模式,根据选中bundle筛选asset
|
||||
var bundle = currentDebugInfo.BundleInfos.Find(a => a.BundleName == _selectName);
|
||||
if (bundle != null)
|
||||
{
|
||||
foreach (var asset in currentDebugInfo.AssetInfos)
|
||||
{
|
||||
if (asset.Dependency.Count > 0)
|
||||
{
|
||||
if (asset.Dependency[0] == bundle.BundleName) list.Add(asset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(_searchValue))
|
||||
{
|
||||
for (var i = 0; i < list.Count; i++)
|
||||
{
|
||||
var l = list[i];
|
||||
if (!l.Path.Contains(_searchValue))
|
||||
{
|
||||
list.RemoveAt(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_assetListView?.SetData(list);
|
||||
}
|
||||
|
||||
private void SetBundleShowInfo()
|
||||
{
|
||||
var currentDebugInfo = _profilerInfo.Current;
|
||||
List<DebugBundleInfo> list = new List<DebugBundleInfo>();
|
||||
if (_showModel == ShowModel.Asset)
|
||||
{
|
||||
//asset模式,根据选中asset筛选bundle
|
||||
var asset = currentDebugInfo.AssetInfos.Find(a => a.Path == _selectName);
|
||||
if (asset != null)
|
||||
{
|
||||
foreach (var bundle in currentDebugInfo.BundleInfos)
|
||||
{
|
||||
if (asset.Dependency.Contains(bundle.BundleName)) list.Add(bundle);
|
||||
}
|
||||
}
|
||||
|
||||
_bundleListView?.SetData(list);
|
||||
}
|
||||
else
|
||||
{
|
||||
list.AddRange(currentDebugInfo.BundleInfos);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(_searchValue))
|
||||
{
|
||||
for (var i = 0; i < list.Count; i++)
|
||||
{
|
||||
var l = list[i];
|
||||
if (!l.BundleName.Contains(_searchValue))
|
||||
{
|
||||
list.RemoveAt(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_bundleListView?.SetData(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 957e27fe287a4dce9079af2e9886c8ad
|
||||
timeCreated: 1679759831
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 17e05001805b4ab4ba6e1912f3913361
|
||||
timeCreated: 1679800462
|
||||
@@ -1,156 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC.Asset.Editor
|
||||
{
|
||||
public class ProfilerAssetListView : TreeView
|
||||
{
|
||||
public sealed class AssetViewItem : TreeViewItem
|
||||
{
|
||||
private DebugAssetInfo _asset;
|
||||
|
||||
public DebugAssetInfo Asset => _asset;
|
||||
|
||||
public AssetViewItem(int id, DebugAssetInfo asset) : base(id, id, asset.Path)
|
||||
{
|
||||
_asset = asset;
|
||||
icon = AssetDatabase.GetCachedIcon(asset.Path) as Texture2D;
|
||||
}
|
||||
}
|
||||
|
||||
public static MultiColumnHeaderState CreateDefaultMultiColumnHeaderState()
|
||||
{
|
||||
return new MultiColumnHeaderState(GetColumns());
|
||||
}
|
||||
|
||||
private static MultiColumnHeaderState.Column[] GetColumns()
|
||||
{
|
||||
List<MultiColumnHeaderState.Column> retVal = new List<MultiColumnHeaderState.Column>();
|
||||
|
||||
var f1 = EditUtil.GetMultiColumnHeaderColumn(Language.ProfilerAssetPath, 350, 100, 10000);
|
||||
f1.headerTextAlignment = TextAlignment.Left;
|
||||
var f2 = EditUtil.GetMultiColumnHeaderColumn(Language.ProfilerAssetType);
|
||||
var f3 = EditUtil.GetMultiColumnHeaderColumn(Language.ProfilerLoadTime);
|
||||
var f4 = EditUtil.GetMultiColumnHeaderColumn(Language.ProfilerLoadTotalTime, 80, 80);
|
||||
var f5 = EditUtil.GetMultiColumnHeaderColumn(Language.ProfilerLoadScene);
|
||||
var f6 = EditUtil.GetMultiColumnHeaderColumn(Language.ProfilerRefCount, 80, 60);
|
||||
var f7 = EditUtil.GetMultiColumnHeaderColumn(Language.ProfilerStatus);
|
||||
retVal.Add(f1);
|
||||
retVal.Add(f2);
|
||||
retVal.Add(f3);
|
||||
retVal.Add(f4);
|
||||
retVal.Add(f5);
|
||||
retVal.Add(f6);
|
||||
retVal.Add(f7);
|
||||
return retVal.ToArray();
|
||||
}
|
||||
|
||||
enum MyColumns
|
||||
{
|
||||
AssetPath,
|
||||
AssetType,
|
||||
LoadTime,
|
||||
LoadTotalTime,
|
||||
LoadScene,
|
||||
RefCount,
|
||||
Status
|
||||
}
|
||||
|
||||
ProfilerWindow _window;
|
||||
private List<DebugAssetInfo> _assetInfos;
|
||||
|
||||
public string SelectName;
|
||||
|
||||
public ProfilerAssetListView(TreeViewState state, ProfilerWindow window, MultiColumnHeaderState mchs) : base(
|
||||
state,
|
||||
new MultiColumnHeader(mchs))
|
||||
{
|
||||
_window = window;
|
||||
showBorder = true;
|
||||
showAlternatingRowBackgrounds = true;
|
||||
Reload();
|
||||
}
|
||||
|
||||
public void SetData(List<DebugAssetInfo> list)
|
||||
{
|
||||
_assetInfos = list;
|
||||
Reload();
|
||||
}
|
||||
|
||||
protected override TreeViewItem BuildRoot()
|
||||
{
|
||||
TreeViewItem root = new TreeViewItem(-1, -1);
|
||||
root.children = new List<TreeViewItem>();
|
||||
if (_assetInfos != null)
|
||||
{
|
||||
for (var i = 0; i < _assetInfos.Count; i++)
|
||||
{
|
||||
root.AddChild(new AssetViewItem(i, _assetInfos[i]));
|
||||
}
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
protected override void SingleClickedItem(int id)
|
||||
{
|
||||
if (FindItem(id, rootItem) is AssetViewItem assetItem)
|
||||
{
|
||||
SelectName = assetItem.Asset.Path;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected override void RowGUI(RowGUIArgs args)
|
||||
{
|
||||
for (int i = 0; i < args.GetNumVisibleColumns(); ++i)
|
||||
{
|
||||
CellGUI(args.GetCellRect(i), args.item, args.GetColumn(i), ref args);
|
||||
}
|
||||
}
|
||||
|
||||
private void CellGUI(Rect cellRect, TreeViewItem item, int column, ref RowGUIArgs args)
|
||||
{
|
||||
AssetViewItem assetTreeViewItem = item as AssetViewItem;
|
||||
if (assetTreeViewItem == null) return;
|
||||
var assetData = assetTreeViewItem.Asset;
|
||||
switch ((MyColumns)column)
|
||||
{
|
||||
case MyColumns.AssetPath:
|
||||
{
|
||||
var iconRect = new Rect(cellRect.x + 1, cellRect.y + 1, cellRect.height - 2, cellRect.height - 2);
|
||||
if (item.icon != null)
|
||||
{
|
||||
GUI.DrawTexture(iconRect, item.icon, ScaleMode.ScaleToFit);
|
||||
}
|
||||
|
||||
var nameRect = new Rect(cellRect.x + iconRect.xMax + 1, cellRect.y, cellRect.width - iconRect.width,
|
||||
cellRect.height);
|
||||
|
||||
DefaultGUI.Label(nameRect, item.displayName, args.selected, args.focused);
|
||||
}
|
||||
break;
|
||||
case MyColumns.AssetType:
|
||||
EditorGUI.LabelField(cellRect, assetData.Type, GUITools.DefLabelStyle);
|
||||
break;
|
||||
case MyColumns.LoadTime:
|
||||
EditorGUI.LabelField(cellRect, assetData.LoadTime, GUITools.DefLabelStyle);
|
||||
break;
|
||||
case MyColumns.LoadTotalTime:
|
||||
EditorGUI.LabelField(cellRect, assetData.LoadTotalTime + "ms", GUITools.DefLabelStyle);
|
||||
break;
|
||||
case MyColumns.LoadScene:
|
||||
EditorGUI.LabelField(cellRect, assetData.LoadScene, GUITools.DefLabelStyle);
|
||||
break;
|
||||
case MyColumns.RefCount:
|
||||
EditorGUI.LabelField(cellRect, assetData.Ref.ToString(), GUITools.DefLabelStyle);
|
||||
break;
|
||||
case MyColumns.Status:
|
||||
EditorGUI.LabelField(cellRect, assetData.Status, GUITools.DefLabelStyle);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9f2f0e315cb4be8baec1371ce79ca9e
|
||||
timeCreated: 1679800687
|
||||
@@ -1,144 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC.Asset.Editor
|
||||
{
|
||||
public class ProfilerBundleListView : TreeView
|
||||
{
|
||||
public sealed class BundleViewItem : TreeViewItem
|
||||
{
|
||||
private DebugBundleInfo _bundle;
|
||||
|
||||
public DebugBundleInfo Bundle => _bundle;
|
||||
|
||||
public BundleViewItem(int id, DebugBundleInfo bundle) : base(id, id, bundle.BundleName)
|
||||
{
|
||||
_bundle = bundle;
|
||||
}
|
||||
}
|
||||
|
||||
public static MultiColumnHeaderState CreateDefaultMultiColumnHeaderState()
|
||||
{
|
||||
return new MultiColumnHeaderState(GetColumns());
|
||||
}
|
||||
|
||||
private static MultiColumnHeaderState.Column[] GetColumns()
|
||||
{
|
||||
List<MultiColumnHeaderState.Column> retVal = new List<MultiColumnHeaderState.Column>();
|
||||
|
||||
var f1 = EditUtil.GetMultiColumnHeaderColumn(Language.ProfilerBundleName, 410, 100, 10000);
|
||||
f1.headerTextAlignment = TextAlignment.Left;
|
||||
var f3 = EditUtil.GetMultiColumnHeaderColumn(Language.ProfilerLoadTime);
|
||||
var f4 = EditUtil.GetMultiColumnHeaderColumn(Language.ProfilerLoadTotalTime);
|
||||
var f5 = EditUtil.GetMultiColumnHeaderColumn(Language.ProfilerLoadScene);
|
||||
var f6 = EditUtil.GetMultiColumnHeaderColumn(Language.ProfilerRefCount);
|
||||
var f7 = EditUtil.GetMultiColumnHeaderColumn(Language.ProfilerStatus);
|
||||
retVal.Add(f1);
|
||||
retVal.Add(f3);
|
||||
retVal.Add(f4);
|
||||
retVal.Add(f5);
|
||||
retVal.Add(f6);
|
||||
retVal.Add(f7);
|
||||
return retVal.ToArray();
|
||||
}
|
||||
|
||||
enum MyColumns
|
||||
{
|
||||
BundleName,
|
||||
LoadTime,
|
||||
LoadTotalTime,
|
||||
LoadScene,
|
||||
RefCount,
|
||||
Status
|
||||
}
|
||||
|
||||
ProfilerWindow _window;
|
||||
private List<DebugBundleInfo> _bundleInfos;
|
||||
private readonly GUIStyle _defLabelStyle;
|
||||
public string SelectName;
|
||||
|
||||
public ProfilerBundleListView(TreeViewState state, ProfilerWindow window, MultiColumnHeaderState mchs) : base(
|
||||
state,
|
||||
new MultiColumnHeader(mchs))
|
||||
{
|
||||
_window = window;
|
||||
showBorder = true;
|
||||
showAlternatingRowBackgrounds = true;
|
||||
|
||||
_defLabelStyle = new GUIStyle(GUI.skin.label)
|
||||
{
|
||||
richText = true,
|
||||
alignment = TextAnchor.MiddleCenter
|
||||
};
|
||||
|
||||
Reload();
|
||||
}
|
||||
|
||||
public void SetData(List<DebugBundleInfo> list)
|
||||
{
|
||||
_bundleInfos = list;
|
||||
Reload();
|
||||
}
|
||||
|
||||
protected override TreeViewItem BuildRoot()
|
||||
{
|
||||
TreeViewItem root = new TreeViewItem(-1, -1);
|
||||
root.children = new List<TreeViewItem>();
|
||||
if (_bundleInfos != null)
|
||||
{
|
||||
for (var i = 0; i < _bundleInfos.Count; i++)
|
||||
{
|
||||
root.AddChild(new BundleViewItem(i, _bundleInfos[i]));
|
||||
}
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
protected override void SingleClickedItem(int id)
|
||||
{
|
||||
if (FindItem(id, rootItem) is BundleViewItem item)
|
||||
{
|
||||
SelectName = item.Bundle.BundleName;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RowGUI(RowGUIArgs args)
|
||||
{
|
||||
for (int i = 0; i < args.GetNumVisibleColumns(); ++i)
|
||||
{
|
||||
CellGUI(args.GetCellRect(i), args.item, args.GetColumn(i), ref args);
|
||||
}
|
||||
}
|
||||
|
||||
private void CellGUI(Rect cellRect, TreeViewItem item, int column, ref RowGUIArgs args)
|
||||
{
|
||||
BundleViewItem treeViewItem = item as BundleViewItem;
|
||||
if (treeViewItem == null) return;
|
||||
var bundleData = treeViewItem.Bundle;
|
||||
switch ((MyColumns)column)
|
||||
{
|
||||
case MyColumns.BundleName:
|
||||
EditorGUI.LabelField(cellRect, bundleData.BundleName);
|
||||
break;
|
||||
case MyColumns.LoadTime:
|
||||
EditorGUI.LabelField(cellRect, bundleData.LoadTime, _defLabelStyle);
|
||||
break;
|
||||
case MyColumns.LoadTotalTime:
|
||||
EditorGUI.LabelField(cellRect, bundleData.LoadTotalTime + "ms", _defLabelStyle);
|
||||
break;
|
||||
case MyColumns.LoadScene:
|
||||
EditorGUI.LabelField(cellRect, bundleData.LoadScene, _defLabelStyle);
|
||||
break;
|
||||
case MyColumns.RefCount:
|
||||
EditorGUI.LabelField(cellRect, bundleData.Ref.ToString(), _defLabelStyle);
|
||||
break;
|
||||
case MyColumns.Status:
|
||||
EditorGUI.LabelField(cellRect, bundleData.Status, _defLabelStyle);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7cd1d8c3f2b845469c0379a8ba6a3580
|
||||
timeCreated: 1679800679
|
||||
Reference in New Issue
Block a user