Skip to content

Commit 438ff7f

Browse files
committed
Minor fixes and refactor changes
1 parent b5cfa6f commit 438ff7f

16 files changed

Lines changed: 176 additions & 122 deletions

Assets/Editor Toolbox/Editor/ContextMenu/Operations/SerializeReference/PasteSerializeReferenceOperation.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ internal class PasteSerializeReferenceOperation : IContextMenuOperation
99
{
1010
private bool IsAssignmentValid(SerializedProperty property, object newValue)
1111
{
12+
#if UNITY_2021_3_OR_NEWER
1213
if (newValue == null)
1314
{
1415
return true;
@@ -24,7 +25,7 @@ private bool IsAssignmentValid(SerializedProperty property, object newValue)
2425
{
2526
return true;
2627
}
27-
28+
#endif
2829
return false;
2930
}
3031

Assets/Editor Toolbox/Editor/Internal/Types/TypeAppearanceContext.cs.meta

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Editor Toolbox/Editor/Internal/Types/TypeConstraintSerializeReference.cs.meta

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Editor Toolbox/Editor/Internal/Types/TypeConstraintStandard.cs.meta

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Editor Toolbox/Editor/Internal/Types/TypeField.cs.meta

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Editor Toolbox/Editor/Internal/Types/TypesCachedCollection.cs.meta

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Editor Toolbox/Editor/Internal/Types/TypesEditorCollection.cs.meta

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Editor Toolbox/Editor/Utilities/AssemblyUttility.cs.meta

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Editor Toolbox/Editor/Utilities/TypeUtility.cs

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@ internal static List<Type> GetDerivedTypesUsingTypesCache(Type parentType, Func<
8686
return typesList;
8787
}
8888

89+
internal static List<Type> GetDerivedTypes(Type parentType, Func<Type, Type> typeProcessor)
90+
{
91+
#if UNITY_2019_2_OR_NEWER
92+
return GetDerivedTypesUsingTypesCache(parentType, typeProcessor);
93+
#else
94+
return GetDerviedTypesUsingAssemblies(parentType, typeProcessor);
95+
#endif
96+
}
97+
98+
internal static bool CanBeSourceForGenericTypes(Type type)
99+
{
100+
return type.IsGenericType && !type.IsGenericTypeDefinition;
101+
}
102+
89103
public static TypesCachedCollection GetCollection(Type parentType)
90104
{
91105
return GetCollection(new TypeConstraintContext(parentType));
@@ -131,7 +145,7 @@ public static bool TryGetTypeFromManagedReferenceFullTypeName(string managedRefe
131145

132146
const int typeFormatParts = 2;
133147

134-
var parts = managedReferenceFullTypeName.Split(' ', typeFormatParts, StringSplitOptions.None);
148+
var parts = managedReferenceFullTypeName.Split(new char[] { ' ' }, typeFormatParts, StringSplitOptions.None);
135149
managedReferenceInstanceType = parts.Length == typeFormatParts
136150
? Type.GetType($"{parts[1]}, {parts[0]}") : null;
137151
if (managedReferenceInstanceType != null)
@@ -157,33 +171,34 @@ public static List<Type> FindTypes(TypeConstraintContext constraint)
157171
var parentGenericArgs = parentGenericType.GetGenericArguments();
158172
typesList = GetDerivedTypes(parentGenericType, (sourceType) =>
159173
{
160-
//NOTE: type is a standard type implementation (even if generic), it means we can check the standard way
161-
if (!sourceType.IsGenericTypeDefinition)
174+
var targetType = sourceType;
175+
//NOTE: type is a generic definition, it means we can check if constraints are matched
176+
if (sourceType.IsGenericTypeDefinition)
162177
{
163-
if (!IsTypeAssignableFrom(parentType, sourceType))
178+
var foundGenericArgs = sourceType.GetGenericArguments();
179+
if (foundGenericArgs.Length != parentGenericArgs.Length)
164180
{
165181
return null;
166182
}
167183

168-
return constraint.IsSatisfied(sourceType) ? sourceType : null;
184+
try
185+
{
186+
targetType = sourceType.MakeGenericType(parentType.GenericTypeArguments);
187+
}
188+
catch (ArgumentException)
189+
{
190+
//NOTE: that's the easiest way to check if all generic constraints are ok
191+
return null;
192+
}
169193
}
170194

171-
var foundGenericArgs = sourceType.GetGenericArguments();
172-
if (foundGenericArgs.Length != parentGenericArgs.Length)
195+
//NOTE: we need to check inheritance since all processed types are derived from the generic type definition
196+
if (!IsTypeAssignableFrom(parentType, targetType))
173197
{
174198
return null;
175199
}
176200

177-
try
178-
{
179-
var genericType = sourceType.MakeGenericType(parentType.GenericTypeArguments);
180-
return constraint.IsSatisfied(genericType) ? genericType : null;
181-
}
182-
catch (ArgumentException)
183-
{
184-
//NOTE: that's the easiest way to check if all generic constraints are ok
185-
return null;
186-
}
201+
return constraint.IsSatisfied(targetType) ? targetType : null;
187202
});
188203
}
189204
else
@@ -206,20 +221,6 @@ public static List<Type> FindTypes(TypeConstraintContext constraint)
206221
}
207222

208223
return typesList;
209-
210-
static bool CanBeSourceForGenericTypes(Type type)
211-
{
212-
return type.IsGenericType && !type.IsGenericTypeDefinition;
213-
}
214-
215-
static List<Type> GetDerivedTypes(Type parentType, Func<Type, Type> typeProcessor)
216-
{
217-
#if UNITY_2019_2_OR_NEWER
218-
return GetDerivedTypesUsingTypesCache(parentType, typeProcessor);
219-
#else
220-
return GetDerviedTypesUsingAssemblies(parentType, typeProcessor);
221-
#endif
222-
}
223224
}
224225

225226
public static List<Type> FindTypes(TypeConstraintContext constraint, Assembly assembly)

0 commit comments

Comments
 (0)