diff --git a/Source/Editor/Modules/SourceCodeEditing/CachedTypesCollection.cs b/Source/Editor/Modules/SourceCodeEditing/CachedTypesCollection.cs index 32e0fe17f..cacaa1db4 100644 --- a/Source/Editor/Modules/SourceCodeEditing/CachedTypesCollection.cs +++ b/Source/Editor/Modules/SourceCodeEditing/CachedTypesCollection.cs @@ -57,7 +57,7 @@ namespace FlaxEditor.Modules.SourceCodeEditing _list.Clear(); _hasValidData = true; - Editor.Log("Searching for valid " + _type); + Editor.Log("Searching for valid " + (_type != ScriptType.Null ? _type.ToString() : "types")); Profiler.BeginEvent("Search " + _type); var start = DateTime.Now; diff --git a/Source/Editor/Windows/Assets/PrefabWindow.Hierarchy.cs b/Source/Editor/Windows/Assets/PrefabWindow.Hierarchy.cs index 2a096680a..986c2ba60 100644 --- a/Source/Editor/Windows/Assets/PrefabWindow.Hierarchy.cs +++ b/Source/Editor/Windows/Assets/PrefabWindow.Hierarchy.cs @@ -263,21 +263,22 @@ namespace FlaxEditor.Windows.Assets } if (attribute == null) continue; - var splitPath = attribute.Path.Split('/'); + var parts = attribute.Path.Split('/'); ContextMenuChildMenu childCM = null; bool mainCM = true; - for (int i = 0; i < splitPath?.Length; i++) + for (int i = 0; i < parts.Length; i++) { - if (i == splitPath.Length - 1) + var part = parts[i].Trim(); + if (i == parts.Length - 1) { if (mainCM) { - contextMenu.AddButton(splitPath[i].Trim(), () => Spawn(actorType.Type)); + contextMenu.AddButton(part, () => Spawn(actorType.Type)); mainCM = false; } - else + else if (childCM != null) { - childCM?.ContextMenu.AddButton(splitPath[i].Trim(), () => Spawn(actorType.Type)); + childCM.ContextMenu.AddButton(part, () => Spawn(actorType.Type)); childCM.ContextMenu.AutoSort = true; } } @@ -285,14 +286,15 @@ namespace FlaxEditor.Windows.Assets { if (mainCM) { - childCM = contextMenu.GetOrAddChildMenu(splitPath[i].Trim()); + childCM = contextMenu.GetOrAddChildMenu(part); + childCM.ContextMenu.AutoSort = true; mainCM = false; } - else + else if (childCM != null) { - childCM = childCM?.ContextMenu.GetOrAddChildMenu(splitPath[i].Trim()); + childCM = childCM.ContextMenu.GetOrAddChildMenu(part); + childCM.ContextMenu.AutoSort = true; } - childCM.ContextMenu.AutoSort = true; } } } diff --git a/Source/Editor/Windows/ContentWindow.ContextMenu.cs b/Source/Editor/Windows/ContentWindow.ContextMenu.cs index 56cba9b9e..89f13d6a3 100644 --- a/Source/Editor/Windows/ContentWindow.ContextMenu.cs +++ b/Source/Editor/Windows/ContentWindow.ContextMenu.cs @@ -3,6 +3,7 @@ using System; using FlaxEditor.Content; using FlaxEditor.GUI.ContextMenu; +using FlaxEditor.Scripting; using FlaxEngine; using FlaxEngine.Assertions; using FlaxEngine.Json; @@ -148,13 +149,18 @@ namespace FlaxEditor.Windows { cm.AddButton("New folder", NewFolder); } - - // loop through each proxy and user defined json type and add them to the context menu + + // Loop through each proxy and user defined json type and add them to the context menu + var actorType = new ScriptType(typeof(Actor)); + var scriptType = new ScriptType(typeof(Script)); foreach (var type in Editor.CodeEditing.All.Get()) { - if (type.IsAbstract || !type.HasAttribute(typeof(ContentContextMenuAttribute), true) || Editor.CodeEditing.Actors.Get().Contains(type) || Editor.CodeEditing.Scripts.Get().Contains(type)) + if (type.IsAbstract) + continue; + if (actorType.IsAssignableFrom(type) || scriptType.IsAssignableFrom(type)) continue; + // Get attribute ContentContextMenuAttribute attribute = null; foreach (var typeAttribute in type.GetAttributes(true)) { @@ -164,41 +170,43 @@ namespace FlaxEditor.Windows break; } } + if (attribute == null) + continue; + // Get context proxy ContentProxy p; if (type.Type.IsSubclassOf(typeof(ContentProxy))) { - p = Editor.ContentDatabase.Proxy.Find(T => T.GetType() == type.Type); + p = Editor.ContentDatabase.Proxy.Find(x => x.GetType() == type.Type); } else { - // user can use attribute to put their own assets into the content context menu + // 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)) { - var splitPath = attribute.Path.Split('/'); + var parts = attribute.Path.Split('/'); ContextMenuChildMenu childCM = null; bool mainCM = true; - for (int i = 0; i < splitPath?.Length; i++) + for (int i = 0; i < parts?.Length; i++) { - if (i == splitPath.Length - 1) + var part = parts[i].Trim(); + if (i == parts.Length - 1) { if (mainCM) { - cm.AddButton(splitPath[i].Trim(), () => NewItem(p)); + cm.AddButton(part, () => NewItem(p)); mainCM = false; } - else + else if (childCM != null) { - childCM?.ContextMenu.AddButton(splitPath[i].Trim(), () => NewItem(p)); + childCM.ContextMenu.AddButton(part, () => NewItem(p)); childCM.ContextMenu.AutoSort = true; } } @@ -206,19 +214,20 @@ namespace FlaxEditor.Windows { if (mainCM) { - childCM = cm.GetOrAddChildMenu(splitPath[i].Trim()); + childCM = cm.GetOrAddChildMenu(part); + childCM.ContextMenu.AutoSort = true; mainCM = false; } - else + else if (childCM != null) { - childCM = childCM?.ContextMenu.GetOrAddChildMenu(splitPath[i].Trim()); + childCM = childCM.ContextMenu.GetOrAddChildMenu(part); + childCM.ContextMenu.AutoSort = true; } - childCM.ContextMenu.AutoSort = true; } } } } - + if (folder.CanHaveAssets) { cm.AddButton("Import file", () => diff --git a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs index a9c946c46..1378ace9c 100644 --- a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs +++ b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs @@ -65,7 +65,6 @@ namespace FlaxEditor.Windows { if (actorType.IsAbstract) continue; - ActorContextMenuAttribute attribute = null; foreach (var e in actorType.GetAttributes(true)) { @@ -77,40 +76,42 @@ namespace FlaxEditor.Windows } if (attribute == null) continue; - var splitPath = attribute?.Path.Split('/'); + var parts = attribute.Path.Split('/'); ContextMenuChildMenu childCM = convertMenu; bool mainCM = true; - for (int i = 0; i < splitPath?.Length; i++) + for (int i = 0; i < parts.Length; i++) { - if (i == splitPath.Length - 1) + var part = parts[i].Trim(); + if (i == parts.Length - 1) { if (mainCM) { - convertMenu.ContextMenu.AddButton(splitPath[i].Trim(), () => Editor.SceneEditing.Convert(actorType.Type)); + convertMenu.ContextMenu.AddButton(part, () => Editor.SceneEditing.Convert(actorType.Type)); mainCM = false; } else { - childCM?.ContextMenu.AddButton(splitPath[i].Trim(), () => Editor.SceneEditing.Convert(actorType.Type)); + childCM.ContextMenu.AddButton(part, () => Editor.SceneEditing.Convert(actorType.Type)); childCM.ContextMenu.AutoSort = true; } } else { // Remove new path for converting menu - if (splitPath[i] == "New") + if (parts[i] == "New") continue; if (mainCM) { - childCM = convertMenu.ContextMenu.GetOrAddChildMenu(splitPath[i].Trim()); + childCM = convertMenu.ContextMenu.GetOrAddChildMenu(part); + childCM.ContextMenu.AutoSort = true; mainCM = false; } else { - childCM = childCM?.ContextMenu.GetOrAddChildMenu(splitPath[i].Trim()); + childCM = childCM.ContextMenu.GetOrAddChildMenu(part); + childCM.ContextMenu.AutoSort = true; } - childCM.ContextMenu.AutoSort = true; } } }