changed to use attribute to add items to the content context menu, this also allows users to add their own items to the CM
This commit is contained in:
@@ -11,14 +11,12 @@ namespace FlaxEditor.Content
|
||||
/// A <see cref="AnimationGraphFunction"/> asset proxy object.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.BinaryAssetProxy" />
|
||||
[ContentContextMenu("New/Animation/Animation Graph Function")]
|
||||
public class AnimationGraphFunctionProxy : BinaryAssetProxy
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Animation Graph Function";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Animation";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override EditorWindow Open(Editor editor, ContentItem item)
|
||||
{
|
||||
|
||||
@@ -11,13 +11,11 @@ namespace FlaxEditor.Content
|
||||
/// A <see cref="AnimationGraph"/> asset proxy object.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.BinaryAssetProxy" />
|
||||
[ContentContextMenu("New/Animation/Animation Graph")]
|
||||
public class AnimationGraphProxy : BinaryAssetProxy
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Animation Graph";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Animation";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override EditorWindow Open(Editor editor, ContentItem item)
|
||||
|
||||
@@ -14,13 +14,11 @@ namespace FlaxEditor.Content
|
||||
/// A <see cref="Animation"/> asset proxy object.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.BinaryAssetProxy" />
|
||||
[ContentContextMenu("New/Animation/Animation")]
|
||||
public class AnimationProxy : BinaryAssetProxy
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Animation";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Animation";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool CanReimport(ContentItem item)
|
||||
|
||||
@@ -22,11 +22,6 @@ namespace FlaxEditor.Content
|
||||
/// </summary>
|
||||
public abstract string TypeName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The category name used to sort in context menus
|
||||
/// </summary>
|
||||
public abstract string CategoryName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this proxy supports the given asset type id at the given path.
|
||||
/// </summary>
|
||||
|
||||
@@ -62,9 +62,6 @@ namespace FlaxEditor.Content
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Audio Clip";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Audio";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool CanReimport(ContentItem item)
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace FlaxEditor.Content
|
||||
/// Context proxy object for C# script files.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.CSharpScriptProxy" />
|
||||
[ContentContextMenu("New/C# Script")]
|
||||
public class CSharpScriptProxy : ScriptProxy
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -38,13 +38,11 @@ namespace FlaxEditor.Content
|
||||
/// A <see cref="CollisionData"/> asset proxy object.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.BinaryAssetProxy" />
|
||||
[ContentContextMenu("New/Physics/Collision Data")]
|
||||
class CollisionDataProxy : BinaryAssetProxy
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Collision Data";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Physics";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override EditorWindow Open(Editor editor, ContentItem item)
|
||||
|
||||
@@ -75,6 +75,7 @@ namespace FlaxEditor.Content
|
||||
/// Context proxy object for C++ script files.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.CSharpScriptProxy" />
|
||||
[ContentContextMenu("New/C++/C++ Script")]
|
||||
public class CppScriptProxy : CppProxy
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@@ -98,6 +99,7 @@ namespace FlaxEditor.Content
|
||||
/// Context proxy object for C++ Json Asset files.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.CSharpScriptProxy" />
|
||||
[ContentContextMenu("New/C++/C++ Function Library")]
|
||||
public class CppStaticClassProxy : CppProxy
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@@ -115,6 +117,7 @@ namespace FlaxEditor.Content
|
||||
/// Context proxy object for C++ Json Asset files.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.CSharpScriptProxy" />
|
||||
[ContentContextMenu("New/C++/C++ Json Asset")]
|
||||
public class CppAssetProxy : CppProxy
|
||||
{
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -20,9 +20,6 @@ namespace FlaxEditor.Content
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Cube Texture";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Texture";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool CanReimport(ContentItem item)
|
||||
|
||||
@@ -17,9 +17,6 @@ namespace FlaxEditor.Content
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Font";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Font";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool CanReimport(ContentItem item)
|
||||
|
||||
@@ -11,13 +11,11 @@ namespace FlaxEditor.Content
|
||||
/// A <see cref="GameplayGlobals"/> asset proxy object.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.BinaryAssetProxy" />
|
||||
[ContentContextMenu("New/Gameplay Globals")]
|
||||
public class GameplayGlobalsProxy : BinaryAssetProxy
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Gameplay Globals";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Globals";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override EditorWindow Open(Editor editor, ContentItem item)
|
||||
|
||||
@@ -20,9 +20,6 @@ namespace FlaxEditor.Content
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "IES Profile";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Lighting";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool CanReimport(ContentItem item)
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace FlaxEditor.Content
|
||||
/// Json assets proxy.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.JsonAssetBaseProxy" />
|
||||
[ContentContextMenu("New/Json Asset")]
|
||||
public abstract class JsonAssetProxy : JsonAssetBaseProxy
|
||||
{
|
||||
/// <summary>
|
||||
@@ -31,9 +32,6 @@ namespace FlaxEditor.Content
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Json Asset";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Json Asset";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string FileExtension => Extension;
|
||||
@@ -168,20 +166,6 @@ namespace FlaxEditor.Content
|
||||
/// <inheritdoc />
|
||||
public override string Name { get; } = Utilities.Utils.GetPropertyNameUI(typeof(T).Name);
|
||||
|
||||
private string _categoryName;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => _categoryName;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the category name
|
||||
/// </summary>
|
||||
/// <param name="name">This is the category name</param>
|
||||
public void SetCategoryName(string name)
|
||||
{
|
||||
_categoryName = name;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool CanCreate(ContentFolder targetLocation)
|
||||
{
|
||||
|
||||
@@ -11,13 +11,11 @@ namespace FlaxEditor.Content
|
||||
/// A <see cref="MaterialFunction"/> asset proxy object.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.BinaryAssetProxy" />
|
||||
[ContentContextMenu("New/Material/Material Function")]
|
||||
public class MaterialFunctionProxy : BinaryAssetProxy
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Material Function";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Material";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override EditorWindow Open(Editor editor, ContentItem item)
|
||||
|
||||
@@ -14,15 +14,13 @@ namespace FlaxEditor.Content
|
||||
/// A <see cref="MaterialInstance"/> asset proxy object.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.BinaryAssetProxy" />
|
||||
[ContentContextMenu("New/Material/Material Instance")]
|
||||
public class MaterialInstanceProxy : BinaryAssetProxy
|
||||
{
|
||||
private MaterialPreview _preview;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Material Instance";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Material";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override EditorWindow Open(Editor editor, ContentItem item)
|
||||
|
||||
@@ -15,15 +15,13 @@ namespace FlaxEditor.Content
|
||||
/// A <see cref="Material"/> asset proxy object.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.BinaryAssetProxy" />
|
||||
[ContentContextMenu("New/Material/Material")]
|
||||
public class MaterialProxy : BinaryAssetProxy
|
||||
{
|
||||
private MaterialPreview _preview;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Material";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Material";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override EditorWindow Open(Editor editor, ContentItem item)
|
||||
|
||||
@@ -21,9 +21,6 @@ namespace FlaxEditor.Content
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Model";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Model";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool CanReimport(ContentItem item)
|
||||
|
||||
@@ -11,13 +11,11 @@ namespace FlaxEditor.Content
|
||||
/// A <see cref="ParticleEmitterFunction"/> asset proxy object.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.BinaryAssetProxy" />
|
||||
[ContentContextMenu("New/Particles/Particle Emitter Function")]
|
||||
public class ParticleEmitterFunctionProxy : BinaryAssetProxy
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Particle Emitter Function";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Particles";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override EditorWindow Open(Editor editor, ContentItem item)
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace FlaxEditor.Content
|
||||
/// A <see cref="ParticleEmitter"/> asset proxy object.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.BinaryAssetProxy" />
|
||||
[ContentContextMenu("New/Particles/Particle Emitter")]
|
||||
public class ParticleEmitterProxy : BinaryAssetProxy
|
||||
{
|
||||
private ParticleEmitterPreview _preview;
|
||||
@@ -22,9 +23,6 @@ namespace FlaxEditor.Content
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Particle Emitter";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Particles";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override EditorWindow Open(Editor editor, ContentItem item)
|
||||
|
||||
@@ -39,6 +39,7 @@ namespace FlaxEditor.Content
|
||||
/// A <see cref="ParticleSystem"/> asset proxy object.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.BinaryAssetProxy" />
|
||||
[ContentContextMenu("New/Particles/Particle System")]
|
||||
public class ParticleSystemProxy : BinaryAssetProxy
|
||||
{
|
||||
private ParticleSystemPreview _preview;
|
||||
@@ -46,9 +47,6 @@ namespace FlaxEditor.Content
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Particle System";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Particles";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override EditorWindow Open(Editor editor, ContentItem item)
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace FlaxEditor.Content
|
||||
/// Content proxy for <see cref="PrefabItem"/>.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.JsonAssetBaseProxy" />
|
||||
[ContentContextMenu("New/Prefab")]
|
||||
public sealed class PrefabProxy : JsonAssetBaseProxy
|
||||
{
|
||||
private PrefabPreview _preview;
|
||||
@@ -31,9 +32,6 @@ namespace FlaxEditor.Content
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Prefab";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Prefab";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string FileExtension => Extension;
|
||||
|
||||
@@ -15,9 +15,6 @@ namespace FlaxEditor.Content
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Previews Cache";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Previews Cache";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override EditorWindow Open(Editor editor, ContentItem item)
|
||||
|
||||
@@ -40,9 +40,6 @@ namespace FlaxEditor.Content
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Scene Animation";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Animation";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override EditorWindow Open(Editor editor, ContentItem item)
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace FlaxEditor.Content
|
||||
/// Content proxy for <see cref="SceneItem"/>.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.JsonAssetBaseProxy" />
|
||||
[ContentContextMenu("New/Scene")]
|
||||
public sealed class SceneProxy : JsonAssetBaseProxy
|
||||
{
|
||||
/// <summary>
|
||||
@@ -19,9 +20,6 @@ namespace FlaxEditor.Content
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Scene";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Scene";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string FileExtension => Extension;
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace FlaxEditor.Content
|
||||
/// Content proxy for json settings assets (e.g <see cref="GameSettings"/> or <see cref="TimeSettings"/>).
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.JsonAssetProxy" />
|
||||
[ContentContextMenu("New/Settings")]
|
||||
public class SettingsProxy : JsonAssetProxy
|
||||
{
|
||||
private readonly Type _type;
|
||||
@@ -20,9 +21,6 @@ namespace FlaxEditor.Content
|
||||
/// Gets the settings type.
|
||||
/// </summary>
|
||||
public Type Type => _type;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Settings";
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SettingsProxy"/> class.
|
||||
|
||||
@@ -14,9 +14,6 @@ namespace FlaxEditor.Content
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Shader";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Shader";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool CanReimport(ContentItem item)
|
||||
|
||||
@@ -11,13 +11,11 @@ namespace FlaxEditor.Content
|
||||
/// A <see cref="SkeletonMask"/> asset proxy object.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.BinaryAssetProxy" />
|
||||
[ContentContextMenu("New/Animation/Skeleton Mask")]
|
||||
public class SkeletonMaskProxy : BinaryAssetProxy
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Skeleton Mask";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Animation";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override EditorWindow Open(Editor editor, ContentItem item)
|
||||
|
||||
@@ -20,9 +20,6 @@ namespace FlaxEditor.Content
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Skinned Model";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Model";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool CanReimport(ContentItem item)
|
||||
|
||||
@@ -20,9 +20,6 @@ namespace FlaxEditor.Content
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Sprite Atlas";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Sprites";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool CanReimport(ContentItem item)
|
||||
|
||||
@@ -20,9 +20,6 @@ namespace FlaxEditor.Content
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Texture";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Texture";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool CanReimport(ContentItem item)
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace FlaxEditor.Content
|
||||
/// A <see cref="VisualScript"/> asset proxy object.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.BinaryAssetProxy" />
|
||||
[ContentContextMenu("New/Visual Script")]
|
||||
public class VisualScriptProxy : BinaryAssetProxy, IScriptTypesContainer
|
||||
{
|
||||
internal VisualScriptProxy()
|
||||
@@ -24,9 +25,6 @@ namespace FlaxEditor.Content
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Visual Script";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CategoryName => "Scripting";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override EditorWindow Open(Editor editor, ContentItem item)
|
||||
|
||||
@@ -927,9 +927,7 @@ namespace FlaxEditor.Modules
|
||||
Proxy.Add(new VisualScriptProxy());
|
||||
Proxy.Add(new LocalizedStringTableProxy());
|
||||
Proxy.Add(new FileProxy());
|
||||
var pm = new SpawnableJsonAssetProxy<PhysicalMaterial>();
|
||||
pm.SetCategoryName("Physics");
|
||||
Proxy.Add(pm);
|
||||
Proxy.Add(new SpawnableJsonAssetProxy<PhysicalMaterial>());
|
||||
|
||||
// Settings
|
||||
Proxy.Add(new SettingsProxy(typeof(GameSettings), Editor.Instance.Icons.GameSettings128));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.CodeDom;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FlaxEditor.Content;
|
||||
@@ -152,64 +153,78 @@ namespace FlaxEditor.Windows
|
||||
{
|
||||
cm.AddButton("New folder", NewFolder);
|
||||
}
|
||||
|
||||
// categorize the asset proxies according to their category name
|
||||
Dictionary<string, List<AssetProxy>> categorizedProxyList = new Dictionary<string, List<AssetProxy>>();
|
||||
for (int i = 0; i < Editor.ContentDatabase.Proxy.Count; i++)
|
||||
|
||||
// loop through each proxy and user defined json type and add them to the context menu
|
||||
foreach (var type in Editor.CodeEditing.All.Get())
|
||||
{
|
||||
var p = Editor.ContentDatabase.Proxy[i];
|
||||
if (type.IsAbstract || !type.HasAttribute(typeof(ContentContextMenuAttribute), true))
|
||||
continue;
|
||||
|
||||
ContentContextMenuAttribute attribute = null;
|
||||
foreach (var typeAttribute in type.GetAttributes(true))
|
||||
{
|
||||
if (typeAttribute is ContentContextMenuAttribute contentContextMenuAttribute)
|
||||
{
|
||||
attribute = contentContextMenuAttribute;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ContentProxy p;
|
||||
if (type.Type.IsSubclassOf(typeof(ContentProxy)))
|
||||
{
|
||||
p = Editor.ContentDatabase.Proxy.Find(T => T.GetType() == type.Type);
|
||||
}
|
||||
else
|
||||
{
|
||||
// user can use attribute to put their own assets into the content context menu
|
||||
var generic = typeof(SpawnableJsonAssetProxy<>).MakeGenericType(type.Type);
|
||||
var instance = Activator.CreateInstance(generic);
|
||||
dynamic obj = instance;
|
||||
p = obj as AssetProxy;
|
||||
}
|
||||
|
||||
if (p == null)
|
||||
continue;
|
||||
|
||||
// create menus
|
||||
if (p.CanCreate(folder))
|
||||
{
|
||||
if (p is AssetProxy ap)
|
||||
var splitPath = attribute.Path.Split('/');
|
||||
ContextMenuChildMenu childCM = null;
|
||||
bool mainCM = true;
|
||||
for (int i = 0; i < splitPath?.Length; i++)
|
||||
{
|
||||
if (categorizedProxyList.ContainsKey(ap.CategoryName))
|
||||
if (i == splitPath.Length - 1)
|
||||
{
|
||||
categorizedProxyList.TryGetValue(ap.CategoryName, out var apList);
|
||||
apList?.Add(ap);
|
||||
if (mainCM)
|
||||
{
|
||||
cm.AddButton(splitPath[i].Trim(), () => NewItem(p));
|
||||
mainCM = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
childCM?.ContextMenu.AddButton(splitPath[i].Trim(), () => NewItem(p));
|
||||
childCM.ContextMenu.AutoSort = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
categorizedProxyList.Add(ap.CategoryName, new List<AssetProxy>() {ap});
|
||||
if (mainCM)
|
||||
{
|
||||
childCM = cm.GetOrAddChildMenu(splitPath[i].Trim());
|
||||
mainCM = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
childCM = childCM?.ContextMenu.GetOrAddChildMenu(splitPath[i].Trim());
|
||||
}
|
||||
childCM.ContextMenu.AutoSort = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c = cm.AddChildMenu("New");
|
||||
c.ContextMenu.Tag = item;
|
||||
c.ContextMenu.AutoSort = true;
|
||||
int newItems = 0;
|
||||
for (int i = 0; i < Editor.ContentDatabase.Proxy.Count; i++)
|
||||
{
|
||||
var p = Editor.ContentDatabase.Proxy[i];
|
||||
if (p.CanCreate(folder))
|
||||
{
|
||||
if (p is AssetProxy ap && categorizedProxyList.TryGetValue(ap.CategoryName, out var apList))
|
||||
{
|
||||
if (apList.Contains(ap))
|
||||
{
|
||||
if (apList.Count > 1)
|
||||
{
|
||||
var childMenu = c.ContextMenu.GetOrAddChildMenu(ap.CategoryName);
|
||||
childMenu.ContextMenu.AutoSort = true;
|
||||
childMenu.ContextMenu.AddButton(p.Name, () => NewItem(p));
|
||||
}
|
||||
else
|
||||
{
|
||||
c.ContextMenu.AddButton(p.Name, () => NewItem(p));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
c.ContextMenu.AddButton(p.Name, () => NewItem(p));
|
||||
}
|
||||
|
||||
newItems++;
|
||||
}
|
||||
}
|
||||
c.Enabled = newItems > 0;
|
||||
|
||||
if (folder.CanHaveAssets)
|
||||
{
|
||||
cm.AddButton("Import file", () =>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
/// <summary>
|
||||
/// Physical materials are used to define the response of a physical object when interacting dynamically with the world.
|
||||
/// </summary>
|
||||
API_CLASS() class FLAXENGINE_API PhysicalMaterial final : public ISerializable
|
||||
API_CLASS(Attributes = "ContentContextMenu(\"New/Physics/Physical Material\")") class FLAXENGINE_API PhysicalMaterial final : public ISerializable
|
||||
{
|
||||
API_AUTO_SERIALIZATION();
|
||||
DECLARE_SCRIPTING_TYPE_MINIMAL(PhysicalMaterial);
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
|
||||
namespace FlaxEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// This attribute is used to show content items that can be created in the content browser context menu. Separate the subcontext menus with a /.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class ContentContextMenuAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// The path to be used in the context menu
|
||||
/// </summary>
|
||||
public string Path;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ContentContextMenuAttribute"/> class.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to use to create the context menu</param>
|
||||
public ContentContextMenuAttribute(string path)
|
||||
{
|
||||
Path = path;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user