Add support for custom file proxies in Editor
This commit is contained in:
@@ -30,9 +30,7 @@ namespace FlaxEditor.Content
|
||||
/// <summary>
|
||||
/// Determines whether [is virtual proxy].
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if [is virtual proxy]; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
/// <returns><c>true</c> if [is virtual proxy]; otherwise, <c>false</c>.</returns>
|
||||
public bool IsVirtualProxy()
|
||||
{
|
||||
return IsVirtual && CanExport == false;
|
||||
|
||||
@@ -29,6 +29,12 @@ namespace FlaxEditor.Content
|
||||
return item is CSharpScriptItem;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ContentItem ConstructItem(string path)
|
||||
{
|
||||
return new CSharpScriptItem(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Create(string outputPath, object arg)
|
||||
{
|
||||
|
||||
@@ -39,6 +39,16 @@ namespace FlaxEditor.Content
|
||||
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>
|
||||
/// Gets a value indicating whether this proxy if for assets.
|
||||
/// </summary>
|
||||
|
||||
@@ -87,6 +87,12 @@ namespace FlaxEditor.Content
|
||||
return item is CppScriptItem;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ContentItem ConstructItem(string path)
|
||||
{
|
||||
return new CppScriptItem(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void GetTemplatePaths(out string headerTemplate, out string sourceTemplate)
|
||||
{
|
||||
|
||||
@@ -20,6 +20,12 @@ namespace FlaxEditor.Content
|
||||
return item is FileItem;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ContentItem ConstructItem(string path)
|
||||
{
|
||||
return new FileItem(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string FileExtension => string.Empty;
|
||||
|
||||
|
||||
@@ -129,12 +129,9 @@ namespace FlaxEditor.Modules
|
||||
for (int i = 0; i < Proxy.Count; i++)
|
||||
{
|
||||
if (Proxy[i].IsProxyFor(item))
|
||||
{
|
||||
return Proxy[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -147,11 +144,8 @@ namespace FlaxEditor.Modules
|
||||
for (int i = 0; i < Proxy.Count; i++)
|
||||
{
|
||||
if (Proxy[i].IsProxyFor<T>())
|
||||
{
|
||||
return Proxy[i];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -164,17 +158,12 @@ namespace FlaxEditor.Modules
|
||||
{
|
||||
if (string.IsNullOrEmpty(extension))
|
||||
throw new ArgumentNullException();
|
||||
|
||||
extension = StringUtils.NormalizeExtension(extension);
|
||||
|
||||
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 null;
|
||||
}
|
||||
|
||||
@@ -189,30 +178,23 @@ namespace FlaxEditor.Modules
|
||||
for (int i = 0; i < Proxy.Count; i++)
|
||||
{
|
||||
if (Proxy[i] is AssetProxy proxy && proxy.AcceptsAsset(typeName, path))
|
||||
{
|
||||
return proxy;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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>
|
||||
/// <param name="path">The asset path.</param>
|
||||
/// <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++)
|
||||
{
|
||||
if (Proxy[i] is AssetProxy proxy && proxy.IsVirtualProxy() && path.EndsWith(proxy.FileExtension, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return proxy;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1016,11 +998,13 @@ namespace FlaxEditor.Modules
|
||||
}
|
||||
if (item == null)
|
||||
{
|
||||
var proxy = GetAssetVirtuallProxy(path);
|
||||
var proxy = GetAssetVirtualProxy(path);
|
||||
item = proxy?.ConstructItem(path, assetInfo.TypeName, ref assetInfo.ID);
|
||||
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