From 8841a603f650757d89a2032c2ef46074de62c849 Mon Sep 17 00:00:00 2001 From: NoriteSC <53096989+NoriteSC@users.noreply.github.com> Date: Fri, 29 Dec 2023 23:15:03 +0100 Subject: [PATCH] Virtual proxy --- Source/Editor/Content/Proxy/AssetProxy.cs | 16 +++++++++++ .../Editor/Modules/ContentDatabaseModule.cs | 28 ++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/Source/Editor/Content/Proxy/AssetProxy.cs b/Source/Editor/Content/Proxy/AssetProxy.cs index 3bd23ad03..7dbd178a9 100644 --- a/Source/Editor/Content/Proxy/AssetProxy.cs +++ b/Source/Editor/Content/Proxy/AssetProxy.cs @@ -22,6 +22,22 @@ namespace FlaxEditor.Content /// public abstract string TypeName { get; } + /// + /// Gets a value indicating whether this instance is virtual Proxy not linked to any asset. + /// + protected virtual bool IsVirtual { get; } + + /// + /// Determines whether [is virtual proxy]. + /// + /// + /// true if [is virtual proxy]; otherwise, false. + /// + public bool IsVirtualProxy() + { + return IsVirtual && CanExport == false; + } + /// /// Checks if this proxy supports the given asset type id at the given path. /// diff --git a/Source/Editor/Modules/ContentDatabaseModule.cs b/Source/Editor/Modules/ContentDatabaseModule.cs index 80f419a6f..fa023bf7b 100644 --- a/Source/Editor/Modules/ContentDatabaseModule.cs +++ b/Source/Editor/Modules/ContentDatabaseModule.cs @@ -196,6 +196,25 @@ namespace FlaxEditor.Modules return null; } + /// + /// Gets the virtual proxy object from given path. + ///

use case if the asset u trying to display is not a flax asset but u like to add custom functionality + ///

to context menu,or display it the asset + ///
+ /// The asset path. + /// Asset proxy or null if cannot find. + public AssetProxy GetAssetVirtuallProxy(string path) + { + for (int i = 0; i < Proxy.Count; i++) + { + if (Proxy[i] is AssetProxy proxy && proxy.IsVirtualProxy() && path.EndsWith(proxy.FileExtension, StringComparison.OrdinalIgnoreCase)) + { + return proxy; + } + } + + return null; + } /// /// Refreshes the given item folder. Tries to find new content items and remove not existing ones. @@ -996,7 +1015,14 @@ namespace FlaxEditor.Modules item = proxy?.ConstructItem(path, assetInfo.TypeName, ref assetInfo.ID); } if (item == null) - item = new FileItem(path); + { + var proxy = GetAssetVirtuallProxy(path); + item = proxy?.ConstructItem(path, assetInfo.TypeName, ref assetInfo.ID); + if (item == null) + { + item = new FileItem(path); + } + } // Link item.ParentFolder = parent.Folder;