Skip to content

Commit

Permalink
Implement TypeFilters.UnitySmart
Browse files Browse the repository at this point in the history
  • Loading branch information
Exanite committed Nov 6, 2024
1 parent da6cedb commit 41aaa12
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
20 changes: 1 addition & 19 deletions DependencyInjection/ObjectBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
using Sirenix.OdinInspector;
using UniDi;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using Object = UnityEngine.Object;
using SerializationUtility = Exanite.Core.Utilities.SerializationUtility;

Expand All @@ -16,21 +14,6 @@ namespace Exanite.Core.DependencyInjection
[Serializable]
public class ObjectBinding : ISerializationCallbackReceiver
{
/// <summary>
/// Types ignored by <see cref="BindTypeFilter.Smart"/>.
/// </summary>
public static IReadOnlyCollection<Type> IgnoredTypes { get; } = new HashSet<Type>
{
typeof(MonoBehaviour),
typeof(Behaviour),
typeof(Component),
typeof(ScriptableObject),
typeof(Object),
typeof(UIBehaviour),
typeof(Graphic),
typeof(MaskableGraphic),
};

[PropertyOrder(0)]
[LabelText("Object")]
[SerializeField] private Object instance = new();
Expand Down Expand Up @@ -91,8 +74,7 @@ private IEnumerable<Type> GetTypesToBindNonCustom()

if ((filter & BindTypeFilter.Smart) != 0)
{
typeFilter.Add(new InheritanceHierarchyTypeFilter(IgnoredTypes, false, false));
typeFilter.Interfaces();
typeFilter.Add(TypeFilters.UnitySmart);
}

if ((filter & BindTypeFilter.Self) != 0)
Expand Down
33 changes: 32 additions & 1 deletion Types/TypeFilters.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using Object = UnityEngine.Object;

namespace Exanite.Core.Types
{
public static class TypeFilters
Expand All @@ -8,7 +15,31 @@ public static class TypeFilters
public static ITypeFilter Smart { get; } = new TypeFilter().InheritanceHierarchy().Interfaces();

#if UNITY_2021_3_OR_NEWER
// Todo public static TypeFilter UnitySmart { get; } = new TypeFilter().InheritanceHierarchy().Interfaces();
/// <summary>
/// Types ignored by the <see cref="UnitySmart"/> <see cref="ITypeFilter"/>.
/// </summary>
public static IReadOnlyCollection<Type> UnityIgnoredTypes { get; }

public static ITypeFilter UnitySmart { get; }

static TypeFilters()
{
UnityIgnoredTypes = new HashSet<Type>
{
typeof(MonoBehaviour),
typeof(Behaviour),
typeof(Component),
typeof(ScriptableObject),
typeof(Object),
typeof(UIBehaviour),
typeof(Graphic),
typeof(MaskableGraphic),
};

UnitySmart = new TypeFilter()
.Add(new InheritanceHierarchyTypeFilter(UnityIgnoredTypes, false, false))
.Interfaces();
}
#endif
}
}

0 comments on commit 41aaa12

Please sign in to comment.