Merge remote-tracking branch 'origin/master' into 1.6
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when building tooltip text.
|
||||
/// </summary>
|
||||
/// <param name="sb">The String Builder.</param>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ContentItemType ItemType => ContentItemType.Asset;
|
||||
|
||||
/// <inheritdoc />
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the asset.
|
||||
/// </summary>
|
||||
|
||||
@@ -19,6 +19,9 @@ namespace FlaxEditor.Content
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string TypeDescription => "C# Source Code";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.CSharpScript128;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
/// <inheritdoc />
|
||||
public override bool Exists => Directory.Exists(Path);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string TypeDescription => "Folder";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Folder128;
|
||||
|
||||
@@ -135,9 +139,10 @@ namespace FlaxEditor.Content
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -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
|
||||
/// </summary>
|
||||
public string NamePath => FlaxEditor.Utilities.Utils.GetAssetNamePath(Path);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content item type description (for UI).
|
||||
/// </summary>
|
||||
public abstract string TypeDescription { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default name of the content item thumbnail. Returns null if not used.
|
||||
/// </summary>
|
||||
@@ -353,11 +360,32 @@ namespace FlaxEditor.Content
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the tooltip text text.
|
||||
/// Updates the tooltip text.
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when building tooltip text.
|
||||
/// </summary>
|
||||
/// <param name="sb">The output string builder.</param>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -19,6 +19,9 @@ namespace FlaxEditor.Content
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string TypeDescription => Path.EndsWith(".h") ? "C++ Header File" : "C++ Source Code";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.CPPScript128;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@ namespace FlaxEditor.Content
|
||||
/// <inheritdoc />
|
||||
public override ContentItemSearchFilter SearchFilter => ContentItemSearchFilter.Other;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string TypeDescription => "File";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Document128;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,9 @@ namespace FlaxEditor.Content
|
||||
/// <inheritdoc />
|
||||
public override ContentItemSearchFilter SearchFilter => ContentItemSearchFilter.Other;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string TypeDescription => "New";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Document128;
|
||||
|
||||
|
||||
@@ -27,6 +27,9 @@ namespace FlaxEditor.Content
|
||||
/// <inheritdoc />
|
||||
public override ContentItemSearchFilter SearchFilter => ContentItemSearchFilter.Scene;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string TypeDescription => "Scene";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Scene128;
|
||||
|
||||
|
||||
@@ -26,6 +26,9 @@ namespace FlaxEditor.Content
|
||||
/// <inheritdoc />
|
||||
public override ContentItemSearchFilter SearchFilter => ContentItemSearchFilter.Shader;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string TypeDescription => "Shader Source Code";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Document128;
|
||||
}
|
||||
|
||||
@@ -1081,7 +1081,7 @@ namespace FlaxEditor.Utilities
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates (recursivly) search popup tree structures based on the filter text.
|
||||
/// Updates (recursively) search popup tree structures based on the filter text.
|
||||
/// </summary>
|
||||
public static void UpdateSearchPopupFilter(TreeNode node, string filterText)
|
||||
{
|
||||
@@ -1107,6 +1107,19 @@ namespace FlaxEditor.Utilities
|
||||
node.Visible = isThisVisible | isAnyChildVisible;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the asset name relative to the project root folder (with asset file extension)
|
||||
/// </summary>
|
||||
/// <param name="path">The asset path.</param>
|
||||
/// <returns>The processed name path.</returns>
|
||||
public static string GetAssetNamePathWithExt(string path)
|
||||
{
|
||||
var projectFolder = Globals.ProjectFolder;
|
||||
if (path.StartsWith(projectFolder))
|
||||
path = path.Substring(projectFolder.Length + 1);
|
||||
return path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the asset name relative to the project root folder (without asset file extension)
|
||||
/// </summary>
|
||||
@@ -1114,9 +1127,7 @@ namespace FlaxEditor.Utilities
|
||||
/// <returns>The processed name path.</returns>
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
/// <seealso cref="FlaxEditor.Windows.Profiler.ProfilerMode" />
|
||||
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<Resource[]>();
|
||||
_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++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
/// <seealso cref="FlaxEditor.Windows.Profiler.ProfilerMode" />
|
||||
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<Resource[]>();
|
||||
_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++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user