Add support for custom file proxies in Editor
This commit is contained in:
@@ -30,9 +30,7 @@ namespace FlaxEditor.Content
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines whether [is virtual proxy].
|
/// Determines whether [is virtual proxy].
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>
|
/// <returns><c>true</c> if [is virtual proxy]; otherwise, <c>false</c>.</returns>
|
||||||
/// <c>true</c> if [is virtual proxy]; otherwise, <c>false</c>.
|
|
||||||
/// </returns>
|
|
||||||
public bool IsVirtualProxy()
|
public bool IsVirtualProxy()
|
||||||
{
|
{
|
||||||
return IsVirtual && CanExport == false;
|
return IsVirtual && CanExport == false;
|
||||||
|
|||||||
@@ -29,6 +29,12 @@ namespace FlaxEditor.Content
|
|||||||
return item is CSharpScriptItem;
|
return item is CSharpScriptItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override ContentItem ConstructItem(string path)
|
||||||
|
{
|
||||||
|
return new CSharpScriptItem(path);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Create(string outputPath, object arg)
|
public override void Create(string outputPath, object arg)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -39,6 +39,16 @@ namespace FlaxEditor.Content
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructs the item for the file.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The file path.</param>
|
||||||
|
/// <returns>Created item or null.</returns>
|
||||||
|
public virtual ContentItem ConstructItem(string path)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether this proxy if for assets.
|
/// Gets a value indicating whether this proxy if for assets.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -87,6 +87,12 @@ namespace FlaxEditor.Content
|
|||||||
return item is CppScriptItem;
|
return item is CppScriptItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override ContentItem ConstructItem(string path)
|
||||||
|
{
|
||||||
|
return new CppScriptItem(path);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void GetTemplatePaths(out string headerTemplate, out string sourceTemplate)
|
protected override void GetTemplatePaths(out string headerTemplate, out string sourceTemplate)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,6 +20,12 @@ namespace FlaxEditor.Content
|
|||||||
return item is FileItem;
|
return item is FileItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override ContentItem ConstructItem(string path)
|
||||||
|
{
|
||||||
|
return new FileItem(path);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override string FileExtension => string.Empty;
|
public override string FileExtension => string.Empty;
|
||||||
|
|
||||||
|
|||||||
@@ -129,12 +129,9 @@ namespace FlaxEditor.Modules
|
|||||||
for (int i = 0; i < Proxy.Count; i++)
|
for (int i = 0; i < Proxy.Count; i++)
|
||||||
{
|
{
|
||||||
if (Proxy[i].IsProxyFor(item))
|
if (Proxy[i].IsProxyFor(item))
|
||||||
{
|
|
||||||
return Proxy[i];
|
return Proxy[i];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,11 +144,8 @@ namespace FlaxEditor.Modules
|
|||||||
for (int i = 0; i < Proxy.Count; i++)
|
for (int i = 0; i < Proxy.Count; i++)
|
||||||
{
|
{
|
||||||
if (Proxy[i].IsProxyFor<T>())
|
if (Proxy[i].IsProxyFor<T>())
|
||||||
{
|
|
||||||
return Proxy[i];
|
return Proxy[i];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,17 +158,12 @@ namespace FlaxEditor.Modules
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(extension))
|
if (string.IsNullOrEmpty(extension))
|
||||||
throw new ArgumentNullException();
|
throw new ArgumentNullException();
|
||||||
|
|
||||||
extension = StringUtils.NormalizeExtension(extension);
|
extension = StringUtils.NormalizeExtension(extension);
|
||||||
|
|
||||||
for (int i = 0; i < Proxy.Count; i++)
|
for (int i = 0; i < Proxy.Count; i++)
|
||||||
{
|
{
|
||||||
if (Proxy[i].FileExtension == extension)
|
if (string.Equals(Proxy[i].FileExtension, extension, StringComparison.Ordinal))
|
||||||
{
|
|
||||||
return Proxy[i];
|
return Proxy[i];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,30 +178,23 @@ namespace FlaxEditor.Modules
|
|||||||
for (int i = 0; i < Proxy.Count; i++)
|
for (int i = 0; i < Proxy.Count; i++)
|
||||||
{
|
{
|
||||||
if (Proxy[i] is AssetProxy proxy && proxy.AcceptsAsset(typeName, path))
|
if (Proxy[i] is AssetProxy proxy && proxy.AcceptsAsset(typeName, path))
|
||||||
{
|
|
||||||
return proxy;
|
return proxy;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the virtual proxy object from given path.
|
/// Gets the virtual proxy object from given path.
|
||||||
/// <br></br>use case if the asset u trying to display is not a flax asset but u like to add custom functionality
|
|
||||||
/// <br></br>to context menu,or display it the asset
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">The asset path.</param>
|
/// <param name="path">The asset path.</param>
|
||||||
/// <returns>Asset proxy or null if cannot find.</returns>
|
/// <returns>Asset proxy or null if cannot find.</returns>
|
||||||
public AssetProxy GetAssetVirtuallProxy(string path)
|
public AssetProxy GetAssetVirtualProxy(string path)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < Proxy.Count; i++)
|
for (int i = 0; i < Proxy.Count; i++)
|
||||||
{
|
{
|
||||||
if (Proxy[i] is AssetProxy proxy && proxy.IsVirtualProxy() && path.EndsWith(proxy.FileExtension, StringComparison.OrdinalIgnoreCase))
|
if (Proxy[i] is AssetProxy proxy && proxy.IsVirtualProxy() && path.EndsWith(proxy.FileExtension, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
|
||||||
return proxy;
|
return proxy;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1016,11 +998,13 @@ namespace FlaxEditor.Modules
|
|||||||
}
|
}
|
||||||
if (item == null)
|
if (item == null)
|
||||||
{
|
{
|
||||||
var proxy = GetAssetVirtuallProxy(path);
|
var proxy = GetAssetVirtualProxy(path);
|
||||||
item = proxy?.ConstructItem(path, assetInfo.TypeName, ref assetInfo.ID);
|
item = proxy?.ConstructItem(path, assetInfo.TypeName, ref assetInfo.ID);
|
||||||
if (item == null)
|
if (item == null)
|
||||||
{
|
{
|
||||||
item = new FileItem(path);
|
item = GetProxy(Path.GetExtension(path))?.ConstructItem(path);
|
||||||
|
if (item == null)
|
||||||
|
item = new FileItem(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user