Added the ability to specify the name of the actor in the toolbox, works in searching as well.

This commit is contained in:
Chandler Cox
2022-11-11 17:03:04 -06:00
parent 62cd59549d
commit 6b4da88ef0
2 changed files with 31 additions and 5 deletions

View File

@@ -219,12 +219,12 @@ namespace FlaxEditor.Windows
{ {
if (child is Tab tab) if (child is Tab tab)
{ {
if (tab.Text == groupName) if (tab.Text == groupName.Trim())
{ {
var tree = tab.GetChild<Panel>().GetChild<Tree>(); var tree = tab.GetChild<Panel>().GetChild<Tree>();
if (tree != null) if (tree != null)
{ {
tree.AddChild(CreateActorItem(Utilities.Utils.GetPropertyNameUI(actorType.Name), actorType)); tree.AddChild(string.IsNullOrEmpty(attribute.Name) ? CreateActorItem(Utilities.Utils.GetPropertyNameUI(actorType.Name), actorType) : CreateActorItem(attribute.Name, actorType));
tree.SortChildren(); tree.SortChildren();
} }
actorTabExists = true; actorTabExists = true;
@@ -235,8 +235,8 @@ namespace FlaxEditor.Windows
if (actorTabExists) if (actorTabExists)
continue; continue;
var group = CreateGroupWithList(actorGroups, groupName); var group = CreateGroupWithList(actorGroups, groupName.Trim());
group.AddChild(CreateActorItem(Utilities.Utils.GetPropertyNameUI(actorType.Name), actorType)); group.AddChild(string.IsNullOrEmpty(attribute.Name) ? CreateActorItem(Utilities.Utils.GetPropertyNameUI(actorType.Name), actorType) : CreateActorItem(attribute.Name, actorType));
group.SortChildren(); group.SortChildren();
} }
} }
@@ -253,7 +253,17 @@ namespace FlaxEditor.Windows
foreach (var actorType in Editor.CodeEditing.Actors.Get()) foreach (var actorType in Editor.CodeEditing.Actors.Get())
{ {
var text = actorType.Name; ActorToolboxAttribute attribute = null;
foreach (var e in actorType.GetAttributes(true))
{
if (e is ActorToolboxAttribute actorToolboxAttribute)
{
attribute = actorToolboxAttribute;
break;
}
}
var text = (attribute == null) ? actorType.Name : string.IsNullOrEmpty(attribute.Name) ? actorType.Name : attribute.Name;
if (!QueryFilterHelper.Match(filterText, text, out QueryFilterHelper.Range[] ranges)) if (!QueryFilterHelper.Match(filterText, text, out QueryFilterHelper.Range[] ranges))
continue; continue;

View File

@@ -13,6 +13,11 @@ namespace FlaxEngine
/// The path to be used in the tool box /// The path to be used in the tool box
/// </summary> /// </summary>
public string Group; public string Group;
/// <summary>
/// The name to be used for the actor in the tool box. Will default to actor name if now used.
/// </summary>
public string Name;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ActorToolboxAttribute"/> class. /// Initializes a new instance of the <see cref="ActorToolboxAttribute"/> class.
@@ -22,5 +27,16 @@ namespace FlaxEngine
{ {
Group = group; Group = group;
} }
/// <summary>
/// Initializes a new instance of the <see cref="ActorToolboxAttribute"/> class.
/// </summary>
/// <param name="group">The group used to creat the tab</param>
/// <param name="name">The name to use rather than default</param>
public ActorToolboxAttribute(string group, string name)
: this(group)
{
Name = name;
}
} }
} }