Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public float GetEditorScore( SerializedProperty property )
if ( TargetType is not null && !ForMethod )
{
//
// Order by derived classes so we get the most relevent editor
// Order by derived classes so we get the most relevant editor
//
Type baseType = TargetType;
while ( baseType.BaseType != null )
Expand Down
23 changes: 22 additions & 1 deletion engine/Sandbox.Tools/Inspector/ComponentEditorWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,36 @@ public ComponentEditorWidget( SerializedObject obj ) : base( null )

public static ComponentEditorWidget Create( SerializedObject obj )
{
var componentType = TypeLibrary.GetType( obj.TypeName ).TargetType;

var editor = EditorTypeLibrary.GetTypesWithAttribute<CustomEditorAttribute>( false )
.Where( x => x.Type.TargetType.IsAssignableTo( typeof( ComponentEditorWidget ) ) )
.Where( x => x.Attribute.TargetType.Name == obj.TypeName )
.Select( x => (score: GetEditorScore( x.Attribute.TargetType, componentType ), x.Type) )
.Where( x => x.score > 0 )
.OrderBy( x => x.score )
.FirstOrDefault();

if ( editor.Type == null ) return null;
return editor.Type.Create<ComponentEditorWidget>( new object[] { obj } );
}

private static int GetEditorScore( Type targetType, Type componentType )
{
int score = 0;

//
// Order by derived classes so we get the most relevant editor
//
Type baseType = componentType;
while ( targetType.IsAssignableFrom( baseType ) )
{
score++;
baseType = baseType.BaseType;
}

return score;
}

public virtual void OnHeaderContextMenu( Menu menu )
{

Expand Down