From 41aaa125f1e82cc6c9f34c99ef29ac7e30c38232 Mon Sep 17 00:00:00 2001 From: Exanite Date: Wed, 6 Nov 2024 02:39:03 -0500 Subject: [PATCH] Implement TypeFilters.UnitySmart --- DependencyInjection/ObjectBinding.cs | 20 +---------------- Types/TypeFilters.cs | 33 +++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/DependencyInjection/ObjectBinding.cs b/DependencyInjection/ObjectBinding.cs index cfa2d34..f895db9 100644 --- a/DependencyInjection/ObjectBinding.cs +++ b/DependencyInjection/ObjectBinding.cs @@ -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; @@ -16,21 +14,6 @@ namespace Exanite.Core.DependencyInjection [Serializable] public class ObjectBinding : ISerializationCallbackReceiver { - /// - /// Types ignored by . - /// - public static IReadOnlyCollection IgnoredTypes { get; } = new HashSet - { - 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(); @@ -91,8 +74,7 @@ private IEnumerable GetTypesToBindNonCustom() if ((filter & BindTypeFilter.Smart) != 0) { - typeFilter.Add(new InheritanceHierarchyTypeFilter(IgnoredTypes, false, false)); - typeFilter.Interfaces(); + typeFilter.Add(TypeFilters.UnitySmart); } if ((filter & BindTypeFilter.Self) != 0) diff --git a/Types/TypeFilters.cs b/Types/TypeFilters.cs index 9019528..2a25193 100644 --- a/Types/TypeFilters.cs +++ b/Types/TypeFilters.cs @@ -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 @@ -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(); + /// + /// Types ignored by the . + /// + public static IReadOnlyCollection UnityIgnoredTypes { get; } + + public static ITypeFilter UnitySmart { get; } + + static TypeFilters() + { + UnityIgnoredTypes = new HashSet + { + 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 } }