Skip to content

Commit 481c28e

Browse files
committed
Possibility to sort types alphabetically
1 parent e153ee7 commit 481c28e

4 files changed

Lines changed: 19 additions & 3 deletions

File tree

Assets/Editor Toolbox/Editor/Drawers/Regular/SerializedTypeDrawer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ private void UpdateConstraint(TypeConstraintAttribute attribute)
5353
sharedConstraint.ApplyTarget(attribute.AssemblyType);
5454
if (sharedConstraint is TypeConstraintStandard constraint)
5555
{
56+
constraint.IsOrdered = attribute.OrderTypes;
5657
constraint.AllowAbstract = attribute.AllowAbstract;
5758
constraint.AllowObsolete = attribute.AllowObsolete;
5859
constraint.Settings = attribute.TypeSettings;

Assets/Editor Toolbox/Editor/Internal/TypeConstraintContext.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,21 @@ public virtual void ApplyTarget(Type type)
3232

3333
public override bool Equals(object obj)
3434
{
35-
return obj is TypeConstraintContext constraint &&
36-
EqualityComparer<Type>.Default.Equals(targetType, constraint.targetType);
35+
return obj is TypeConstraintContext context &&
36+
EqualityComparer<Type>.Default.Equals(TargetType, context.TargetType) &&
37+
IsOrdered == context.IsOrdered;
3738
}
3839

3940
public override int GetHashCode()
4041
{
41-
return 1673078848 + EqualityComparer<Type>.Default.GetHashCode(targetType);
42+
var hashCode = -509589530;
43+
hashCode = hashCode * -1521134295 + EqualityComparer<Type>.Default.GetHashCode(TargetType);
44+
hashCode = hashCode * -1521134295 + IsOrdered.GetHashCode();
45+
return hashCode;
4246
}
4347

4448

4549
public Type TargetType => targetType;
50+
public bool IsOrdered { get; set; } = true;
4651
}
4752
}

Assets/Editor Toolbox/Editor/Utilities/TypeUtilities.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ public static List<Type> FindTypes(TypeConstraintContext constraint)
106106

107107
typesList.Sort((a, b) => a.FullName.CompareTo(b.FullName));
108108
#endif
109+
if (constraint.IsOrdered)
110+
{
111+
typesList.Sort((t1, t2) => t1.Name.CompareTo(t2.Name));
112+
}
113+
109114
return typesList;
110115
}
111116

Assets/Editor Toolbox/Runtime/Attributes/Regular/TypeConstraintAttribute.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public TypeConstraintAttribute(Type assemblyType)
3939
/// </summary>
4040
public bool AddTextSearchField { get; set; }
4141

42+
/// <summary>
43+
/// Indicates if types should be sorted alphabetically.
44+
/// </summary>
45+
public bool OrderTypes { get; set; } = true;
46+
4247
/// <summary>
4348
/// Gets or sets grouping of selectable classes.
4449
/// Defaults to <see cref="ClassGrouping.None"/> unless explicitly specified.

0 commit comments

Comments
 (0)