Merge branch 'organized-content-new-cm' of https://github.com/Tryibion/FlaxEngine into Tryibion-organized-content-new-cm

This commit is contained in:
Wojtek Figat
2022-11-21 16:15:04 +01:00
23 changed files with 115 additions and 13 deletions

View File

@@ -11,6 +11,7 @@ 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 />

View File

@@ -11,6 +11,7 @@ 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 />

View File

@@ -14,6 +14,7 @@ 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 />

View File

@@ -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>

View File

@@ -38,6 +38,7 @@ 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 />

View File

@@ -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 />

View File

@@ -11,6 +11,7 @@ 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 />

View File

@@ -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>

View File

@@ -11,6 +11,7 @@ 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 />

View File

@@ -14,6 +14,7 @@ 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;

View File

@@ -15,6 +15,7 @@ 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;

View File

@@ -11,6 +11,7 @@ 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 />

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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>

View File

@@ -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;

View File

@@ -13,6 +13,7 @@ namespace FlaxEditor.Content
/// Context proxy object for shader source files (represented by <see cref="ShaderSourceItem"/>).
/// </summary>
/// <seealso cref="FlaxEditor.Content.ContentProxy" />
[ContentContextMenu("New/Shader Source")]
public class ShaderSourceProxy : ContentProxy
{
/// <inheritdoc />

View File

@@ -11,6 +11,7 @@ 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 />

View File

@@ -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()

View File

@@ -39,7 +39,6 @@ namespace FlaxEditor.Windows
// Create context menu
ContextMenuButton b;
ContextMenuChildMenu c;
ContextMenu cm = new ContextMenu
{
Tag = item
@@ -149,22 +148,77 @@ namespace FlaxEditor.Windows
{
cm.AddButton("New folder", NewFolder);
}
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++)
// 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) || Editor.CodeEditing.Actors.Get().Contains(type) || Editor.CodeEditing.Scripts.Get().Contains(type))
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);
p = instance as AssetProxy;
}
if (p == null)
continue;
// create menus
if (p.CanCreate(folder))
{
c.ContextMenu.AddButton(p.Name, () => NewItem(p));
newItems++;
var splitPath = attribute.Path.Split('/');
ContextMenuChildMenu childCM = null;
bool mainCM = true;
for (int i = 0; i < splitPath?.Length; i++)
{
if (i == splitPath.Length - 1)
{
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
{
if (mainCM)
{
childCM = cm.GetOrAddChildMenu(splitPath[i].Trim());
mainCM = false;
}
else
{
childCM = childCM?.ContextMenu.GetOrAddChildMenu(splitPath[i].Trim());
}
childCM.ContextMenu.AutoSort = true;
}
}
}
}
c.Enabled = newItems > 0;
if (folder.CanHaveAssets)
{
cm.AddButton("Import file", () =>

View 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);

View File

@@ -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;
}
}
}