diff --git a/Source/Editor/Content/Items/AssetItem.cs b/Source/Editor/Content/Items/AssetItem.cs
index 8ececa278..71f298965 100644
--- a/Source/Editor/Content/Items/AssetItem.cs
+++ b/Source/Editor/Content/Items/AssetItem.cs
@@ -1,8 +1,6 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using System;
-using System.IO;
-using System.Text;
using FlaxEngine;
using FlaxEngine.GUI;
@@ -38,14 +36,6 @@ namespace FlaxEditor.Content
ID = id;
}
- ///
- public override void UpdateTooltipText()
- {
- var sb = new StringBuilder();
- OnBuildTooltipText(sb);
- TooltipText = sb.ToString();
- }
-
private sealed class TooltipDoubleClickHook : Control
{
public AssetItem Item;
@@ -74,20 +64,25 @@ namespace FlaxEditor.Content
hook.Item = this;
}
- ///
- /// Called when building tooltip text.
- ///
- /// The String Builder.
- protected virtual void OnBuildTooltipText(StringBuilder sb)
- {
- sb.Append("Type: ").Append(TypeName).AppendLine();
- sb.Append("Size: ").Append(Utilities.Utils.FormatBytesCount((int)new FileInfo(Path).Length)).AppendLine();
- sb.Append("Path: ").Append(Path).AppendLine();
- }
-
///
public override ContentItemType ItemType => ContentItemType.Asset;
+ ///
+ public override string TypeDescription
+ {
+ get
+ {
+ // Translate asset type name
+ var typeName = TypeName;
+ string[] typeNamespaces = typeName.Split('.');
+ if (typeNamespaces.Length != 0 && typeNamespaces.Length != 0)
+ {
+ typeName = Utilities.Utils.GetPropertyNameUI(typeNamespaces[typeNamespaces.Length - 1]);
+ }
+ return typeName;
+ }
+ }
+
///
/// Loads the asset.
///
diff --git a/Source/Editor/Content/Items/CSharpScriptItem.cs b/Source/Editor/Content/Items/CSharpScriptItem.cs
index 9a214a0e8..fd6381eea 100644
--- a/Source/Editor/Content/Items/CSharpScriptItem.cs
+++ b/Source/Editor/Content/Items/CSharpScriptItem.cs
@@ -19,6 +19,9 @@ namespace FlaxEditor.Content
{
}
+ ///
+ public override string TypeDescription => "C# Source Code";
+
///
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.CSharpScript128;
}
diff --git a/Source/Editor/Content/Items/ContentFolder.cs b/Source/Editor/Content/Items/ContentFolder.cs
index cbbc15f24..86c374fee 100644
--- a/Source/Editor/Content/Items/ContentFolder.cs
+++ b/Source/Editor/Content/Items/ContentFolder.cs
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Text;
using FlaxEditor.GUI.Drag;
using FlaxEngine;
using FlaxEngine.GUI;
@@ -120,6 +121,9 @@ namespace FlaxEditor.Content
///
public override bool Exists => Directory.Exists(Path);
+ ///
+ public override string TypeDescription => "Folder";
+
///
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Folder128;
@@ -135,9 +139,10 @@ namespace FlaxEditor.Content
}
///
- public override void UpdateTooltipText()
+ protected override void OnBuildTooltipText(StringBuilder sb)
{
- TooltipText = Path;
+ sb.Append("Type: ").Append(TypeDescription).AppendLine();
+ sb.Append("Path: ").Append(Utilities.Utils.GetAssetNamePathWithExt(Path)).AppendLine();
}
///
diff --git a/Source/Editor/Content/Items/ContentItem.cs b/Source/Editor/Content/Items/ContentItem.cs
index 284f3f1b3..4fe75d2c2 100644
--- a/Source/Editor/Content/Items/ContentItem.cs
+++ b/Source/Editor/Content/Items/ContentItem.cs
@@ -2,6 +2,8 @@
using System;
using System.Collections.Generic;
+using System.IO;
+using System.Text;
using FlaxEditor.Content.GUI;
using FlaxEditor.GUI.Drag;
using FlaxEngine;
@@ -273,6 +275,11 @@ namespace FlaxEditor.Content
///
public string NamePath => FlaxEditor.Utilities.Utils.GetAssetNamePath(Path);
+ ///
+ /// Gets the content item type description (for UI).
+ ///
+ public abstract string TypeDescription { get; }
+
///
/// Gets the default name of the content item thumbnail. Returns null if not used.
///
@@ -353,11 +360,32 @@ namespace FlaxEditor.Content
}
///
- /// Updates the tooltip text text.
+ /// Updates the tooltip text.
///
public virtual void UpdateTooltipText()
{
- TooltipText = "Path: " + Path;
+ var sb = new StringBuilder();
+ OnBuildTooltipText(sb);
+ if (sb.Length != 0 && sb[sb.Length - 1] == '\n')
+ {
+ // Remove new-line from end
+ int sub = 1;
+ if (sb.Length != 1 && sb[sb.Length - 2] == '\r')
+ sub = 2;
+ sb.Length -= sub;
+ }
+ TooltipText = sb.ToString();
+ }
+
+ ///
+ /// Called when building tooltip text.
+ ///
+ /// The output string builder.
+ protected virtual void OnBuildTooltipText(StringBuilder sb)
+ {
+ sb.Append("Type: ").Append(TypeDescription).AppendLine();
+ sb.Append("Size: ").Append(Utilities.Utils.FormatBytesCount((int)new FileInfo(Path).Length)).AppendLine();
+ sb.Append("Path: ").Append(Utilities.Utils.GetAssetNamePathWithExt(Path)).AppendLine();
}
///
diff --git a/Source/Editor/Content/Items/CppScriptItem.cs b/Source/Editor/Content/Items/CppScriptItem.cs
index c4fbb99e8..aea12ecd3 100644
--- a/Source/Editor/Content/Items/CppScriptItem.cs
+++ b/Source/Editor/Content/Items/CppScriptItem.cs
@@ -19,6 +19,9 @@ namespace FlaxEditor.Content
{
}
+ ///
+ public override string TypeDescription => Path.EndsWith(".h") ? "C++ Header File" : "C++ Source Code";
+
///
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.CPPScript128;
}
diff --git a/Source/Editor/Content/Items/FileItem.cs b/Source/Editor/Content/Items/FileItem.cs
index 5e355087a..1136ee87e 100644
--- a/Source/Editor/Content/Items/FileItem.cs
+++ b/Source/Editor/Content/Items/FileItem.cs
@@ -25,6 +25,9 @@ namespace FlaxEditor.Content
///
public override ContentItemSearchFilter SearchFilter => ContentItemSearchFilter.Other;
+ ///
+ public override string TypeDescription => "File";
+
///
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Document128;
}
diff --git a/Source/Editor/Content/Items/NewItem.cs b/Source/Editor/Content/Items/NewItem.cs
index da8b0ca9a..94d95f15b 100644
--- a/Source/Editor/Content/Items/NewItem.cs
+++ b/Source/Editor/Content/Items/NewItem.cs
@@ -39,6 +39,9 @@ namespace FlaxEditor.Content
///
public override ContentItemSearchFilter SearchFilter => ContentItemSearchFilter.Other;
+ ///
+ public override string TypeDescription => "New";
+
///
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Document128;
diff --git a/Source/Editor/Content/Items/SceneItem.cs b/Source/Editor/Content/Items/SceneItem.cs
index cf2ada96b..6a56004f0 100644
--- a/Source/Editor/Content/Items/SceneItem.cs
+++ b/Source/Editor/Content/Items/SceneItem.cs
@@ -27,6 +27,9 @@ namespace FlaxEditor.Content
///
public override ContentItemSearchFilter SearchFilter => ContentItemSearchFilter.Scene;
+ ///
+ public override string TypeDescription => "Scene";
+
///
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Scene128;
diff --git a/Source/Editor/Content/Items/ShaderSourceItem.cs b/Source/Editor/Content/Items/ShaderSourceItem.cs
index b5572787c..1e8f8360f 100644
--- a/Source/Editor/Content/Items/ShaderSourceItem.cs
+++ b/Source/Editor/Content/Items/ShaderSourceItem.cs
@@ -26,6 +26,9 @@ namespace FlaxEditor.Content
///
public override ContentItemSearchFilter SearchFilter => ContentItemSearchFilter.Shader;
+ ///
+ public override string TypeDescription => "Shader Source Code";
+
///
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Document128;
}
diff --git a/Source/Editor/Utilities/Utils.cs b/Source/Editor/Utilities/Utils.cs
index 6c872d1ef..0f44c9639 100644
--- a/Source/Editor/Utilities/Utils.cs
+++ b/Source/Editor/Utilities/Utils.cs
@@ -1081,7 +1081,7 @@ namespace FlaxEditor.Utilities
}
///
- /// Updates (recursivly) search popup tree structures based on the filter text.
+ /// Updates (recursively) search popup tree structures based on the filter text.
///
public static void UpdateSearchPopupFilter(TreeNode node, string filterText)
{
@@ -1107,6 +1107,19 @@ namespace FlaxEditor.Utilities
node.Visible = isThisVisible | isAnyChildVisible;
}
+ ///
+ /// Gets the asset name relative to the project root folder (with asset file extension)
+ ///
+ /// The asset path.
+ /// The processed name path.
+ public static string GetAssetNamePathWithExt(string path)
+ {
+ var projectFolder = Globals.ProjectFolder;
+ if (path.StartsWith(projectFolder))
+ path = path.Substring(projectFolder.Length + 1);
+ return path;
+ }
+
///
/// Gets the asset name relative to the project root folder (without asset file extension)
///
@@ -1114,9 +1127,7 @@ namespace FlaxEditor.Utilities
/// The processed name path.
public static string GetAssetNamePath(string path)
{
- var projectFolder = Globals.ProjectFolder;
- if (path.StartsWith(projectFolder))
- path = path.Substring(projectFolder.Length + 1);
+ path = GetAssetNamePathWithExt(path);
return StringUtils.GetPathWithoutExtension(path);
}
diff --git a/Source/Editor/Windows/Profiler/Assets.cs b/Source/Editor/Windows/Profiler/Assets.cs
index 6987a09e0..e2a65d496 100644
--- a/Source/Editor/Windows/Profiler/Assets.cs
+++ b/Source/Editor/Windows/Profiler/Assets.cs
@@ -8,6 +8,7 @@ using FlaxEngine;
using FlaxEngine.Json;
using FlaxEngine.GUI;
using FlaxEditor.GUI.ContextMenu;
+using System.Linq;
namespace FlaxEditor.Windows.Profiler
{
@@ -17,7 +18,7 @@ namespace FlaxEditor.Windows.Profiler
///
internal sealed class Assets : ProfilerMode
{
- private struct Resource
+ private class Resource
{
public string Name;
public string TypeName;
@@ -120,19 +121,18 @@ namespace FlaxEditor.Windows.Profiler
// Capture current assets usage info
var assets = FlaxEngine.Content.Assets;
- var sb = _stringBuilder;
var resources = new Resource[assets.Length];
- var contentDatabase = Editor.Instance.ContentDatabase;
ulong totalMemoryUsage = 0;
for (int i = 0; i < resources.Length; i++)
{
var asset = assets[i];
+ ref var resource = ref resources[i];
if (!asset)
continue;
// Try to reuse cached resource info
var assetId = asset.ID;
- if (!_resourceCache.TryGetValue(assetId, out var resource))
+ if (!_resourceCache.TryGetValue(assetId, out resource))
{
resource = new Resource
{
@@ -154,12 +154,10 @@ namespace FlaxEditor.Windows.Profiler
}
resource.MemoryUsage = asset.MemoryUsage;
- totalMemoryUsage += resource.MemoryUsage;
resource.ReferencesCount = asset.ReferencesCount;
- resources[i] = resource;
+ totalMemoryUsage += resource.MemoryUsage;
}
_memoryUsageChart.AddSample((float)totalMemoryUsage);
- Array.Sort(resources, SortResources);
if (_resources == null)
_resources = new SamplesBuffer();
_resources.Add(resources);
@@ -188,11 +186,6 @@ namespace FlaxEditor.Windows.Profiler
base.OnDestroy();
}
- private static int SortResources(Resource a, Resource b)
- {
- return (int)(b.MemoryUsage - a.MemoryUsage);
- }
-
private void UpdateTable()
{
_table.IsLayoutLocked = true;
@@ -225,13 +218,13 @@ namespace FlaxEditor.Windows.Profiler
var resources = _resources.Get(_memoryUsageChart.SelectedSampleIndex);
if (resources == null || resources.Length == 0)
return;
+ var resourcesOrdered = resources.OrderByDescending(x => x.MemoryUsage);
// Add rows
var rowColor2 = Style.Current.Background * 1.4f;
- for (int i = 0; i < resources.Length; i++)
+ int rowIndex = 0;
+ foreach (var e in resourcesOrdered)
{
- ref var e = ref resources[i];
-
ClickableRow row;
if (_tableRowsCache.Count != 0)
{
@@ -257,8 +250,9 @@ namespace FlaxEditor.Windows.Profiler
// Add row to the table
row.Width = _table.Width;
- row.BackgroundColor = i % 2 == 0 ? rowColor2 : Color.Transparent;
+ row.BackgroundColor = rowIndex % 2 == 0 ? rowColor2 : Color.Transparent;
row.Parent = _table;
+ rowIndex++;
}
}
diff --git a/Source/Editor/Windows/Profiler/MemoryGPU.cs b/Source/Editor/Windows/Profiler/MemoryGPU.cs
index f84e4b697..20a7898e0 100644
--- a/Source/Editor/Windows/Profiler/MemoryGPU.cs
+++ b/Source/Editor/Windows/Profiler/MemoryGPU.cs
@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Text;
using FlaxEditor.GUI;
using FlaxEngine;
@@ -15,7 +16,7 @@ namespace FlaxEditor.Windows.Profiler
///
internal sealed class MemoryGPU : ProfilerMode
{
- private struct Resource
+ private class Resource
{
public string Name;
public string Tooltip;
@@ -126,10 +127,11 @@ namespace FlaxEditor.Windows.Profiler
for (int i = 0; i < resources.Length; i++)
{
var gpuResource = gpuResources[i];
+ ref var resource = ref resources[i];
// Try to reuse cached resource info
var gpuResourceId = gpuResource.ID;
- if (!_resourceCache.TryGetValue(gpuResourceId, out var resource))
+ if (!_resourceCache.TryGetValue(gpuResourceId, out resource))
{
resource = new Resource
{
@@ -194,9 +196,7 @@ namespace FlaxEditor.Windows.Profiler
resource.MemoryUsage = gpuResource.MemoryUsage;
if (resource.MemoryUsage == 1)
resource.MemoryUsage = 0; // Sometimes GPU backend fakes memory usage as 1 to mark as allocated but not resided in actual GPU memory
- resources[i] = resource;
}
- Array.Sort(resources, SortResources);
if (_resources == null)
_resources = new SamplesBuffer();
_resources.Add(resources);
@@ -240,11 +240,6 @@ namespace FlaxEditor.Windows.Profiler
base.OnDestroy();
}
- private static int SortResources(Resource a, Resource b)
- {
- return (int)(b.MemoryUsage - a.MemoryUsage);
- }
-
private void UpdateTable()
{
_table.IsLayoutLocked = true;
@@ -277,13 +272,13 @@ namespace FlaxEditor.Windows.Profiler
var resources = _resources.Get(_memoryUsageChart.SelectedSampleIndex);
if (resources == null || resources.Length == 0)
return;
+ var resourcesOrdered = resources.OrderByDescending(x => x.MemoryUsage);
// Add rows
var rowColor2 = Style.Current.Background * 1.4f;
- for (int i = 0; i < resources.Length; i++)
+ int rowIndex = 0;
+ foreach (var e in resourcesOrdered)
{
- ref var e = ref resources[i];
-
ClickableRow row;
if (_tableRowsCache.Count != 0)
{
@@ -314,8 +309,9 @@ namespace FlaxEditor.Windows.Profiler
// Add row to the table
row.Width = _table.Width;
- row.BackgroundColor = i % 2 == 0 ? rowColor2 : Color.Transparent;
+ row.BackgroundColor = rowIndex % 2 == 0 ? rowColor2 : Color.Transparent;
row.Parent = _table;
+ rowIndex++;
}
}