Skip to content

Commit

Permalink
Rename TypeConstraintReference to TypeConstraintSerializeReference
Browse files Browse the repository at this point in the history
  • Loading branch information
arimger committed Aug 26, 2024
1 parent 637292e commit 690d3fe
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ReferencePickerAttributeDrawer : ToolboxSelfPropertyDrawer<Referenc
{
private const float labelWidthOffset = -80.0f;

private static readonly TypeConstraintContext sharedConstraint = new TypeConstraintReference(null);
private static readonly TypeConstraintContext sharedConstraint = new TypeConstraintSerializeReference(null);
private static readonly TypeAppearanceContext sharedAppearance = new TypeAppearanceContext(sharedConstraint, TypeGrouping.None, true);
private static readonly TypeField typeField = new TypeField(sharedConstraint, sharedAppearance);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ public class TypeConstraintContext
{
protected Type targetType;


public TypeConstraintContext(Type targetType)
{
this.targetType = targetType;
}


public virtual bool IsSatisfied(Type type)
{
#if UNITY_2019_2_OR_NEWER
Expand Down Expand Up @@ -45,7 +43,6 @@ public override int GetHashCode()
return hashCode;
}


public Type TargetType => targetType;
public Comparison<Type> Comparer { get; set; } = (t1, t2) => t1.Name.CompareTo(t2.Name);
public bool IsOrdered { get; set; } = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

namespace Toolbox.Editor.Internal
{
public class TypeConstraintReference : TypeConstraintContext
/// <summary>
/// Dedicated <see cref="TypeConstraintContext"/> for SerializeReference-based types.
/// </summary>
public class TypeConstraintSerializeReference : TypeConstraintContext
{
public TypeConstraintReference(Type targetType) : base(targetType)
public TypeConstraintSerializeReference(Type targetType) : base(targetType)
{ }


public override bool IsSatisfied(Type type)
{
return base.IsSatisfied(type) &&
Expand All @@ -25,7 +27,7 @@ public override bool IsSatisfied(Type type)

public override bool Equals(object other)
{
return other is TypeConstraintReference constraint &&
return other is TypeConstraintSerializeReference constraint &&
base.Equals(other) &&
EqualityComparer<Type>.Default.Equals(targetType, constraint.targetType);
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Assets/Editor Toolbox/Editor/Internal/TypeField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ private Type RetriveSelectedType(IReadOnlyList<Type> types, int selectedIndex, b

private void DrawTypeConflictWarning(Rect position)
{
const float warningSpace = 18.0f;
const float warningSpace = 20.0f;

var warningPosition = position;
warningPosition.xMax = position.xMin;
warningPosition.xMin -= warningSpace;
warningPosition.y += EditorGUIUtility.standardVerticalSpacing;
var warningIcon = EditorGuiUtility.GetHelpIcon(MessageType.Warning);
var warningLabel = new GUIContent(warningIcon, "Currently active type is not available from the selection. " +
"It may be caused by a conflict between the type filter and cached data.");
Expand Down
6 changes: 3 additions & 3 deletions Assets/Editor Toolbox/Tests/Editor/TypesFilteringTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ public void TestStandardConstraintPass7()
[Test]
public void TestReferenceConstraintPass1()
{
var constraint = new TypeConstraintReference(typeof(Component));
var constraint = new TypeConstraintSerializeReference(typeof(Component));
var collection = TypeUtilities.GetCollection(constraint);
Assert.AreEqual(0, collection.Values.Count);
}

[Test]
public void TestReferenceConstraintPass2()
{
var constraint = new TypeConstraintReference(typeof(ClassBase));
var constraint = new TypeConstraintSerializeReference(typeof(ClassBase));
var collection = TypeUtilities.GetCollection(constraint);
Assert.IsTrue(collection.Contains(typeof(ClassWithInterface1)));
#pragma warning disable CS0612
Expand All @@ -161,7 +161,7 @@ public void TestReferenceConstraintPass2()
[Test]
public void TestReferenceConstraintPass3()
{
var constraint = new TypeConstraintReference(typeof(Interface1));
var constraint = new TypeConstraintSerializeReference(typeof(Interface1));
var collection = TypeUtilities.GetCollection(constraint);
Assert.IsTrue(collection.Contains(typeof(ClassWithInterface1)));
#pragma warning disable CS0612
Expand Down

0 comments on commit 690d3fe

Please sign in to comment.