Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 69943b46c8 | |||
| 66fc5ae911 | |||
| 1757747985 | |||
| 69f6e31cf1 | |||
| 3ffef8d1b2 | |||
| a9763b033d | |||
| 2b40c3d26e | |||
| f7c1017567 | |||
| 301cb4b12c | |||
| fe02e0fd1e |
+30
-32
@@ -26,49 +26,47 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||
static Type GetCustomPropertyDrawerType (Type type)
|
||||
{
|
||||
Type[] interfaceTypes = type.GetInterfaces();
|
||||
|
||||
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
|
||||
var types = TypeCache.GetTypesWithAttribute<CustomPropertyDrawer>();
|
||||
foreach (Type drawerType in types)
|
||||
{
|
||||
foreach (Type drawerType in assembly.GetTypes())
|
||||
var customPropertyDrawerAttributes = drawerType.GetCustomAttributes(typeof(CustomPropertyDrawer), true);
|
||||
foreach (CustomPropertyDrawer customPropertyDrawer in customPropertyDrawerAttributes)
|
||||
{
|
||||
var customPropertyDrawerAttributes = drawerType.GetCustomAttributes(typeof(CustomPropertyDrawer), true);
|
||||
foreach (CustomPropertyDrawer customPropertyDrawer in customPropertyDrawerAttributes)
|
||||
var field = customPropertyDrawer.GetType().GetField("m_Type", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (field != null)
|
||||
{
|
||||
var field = customPropertyDrawer.GetType().GetField("m_Type", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (field != null)
|
||||
var fieldType = field.GetValue(customPropertyDrawer) as Type;
|
||||
if (fieldType != null)
|
||||
{
|
||||
var fieldType = field.GetValue(customPropertyDrawer) as Type;
|
||||
if (fieldType != null)
|
||||
if (fieldType == type)
|
||||
{
|
||||
if (fieldType == type)
|
||||
return drawerType;
|
||||
}
|
||||
|
||||
// If the property drawer also allows for being applied to child classes, check if they match
|
||||
var useForChildrenField = customPropertyDrawer.GetType().GetField("m_UseForChildren", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (useForChildrenField != null)
|
||||
{
|
||||
object useForChildrenValue = useForChildrenField.GetValue(customPropertyDrawer);
|
||||
if (useForChildrenValue is bool && (bool)useForChildrenValue)
|
||||
{
|
||||
return drawerType;
|
||||
}
|
||||
|
||||
// If the property drawer also allows for being applied to child classes, check if they match
|
||||
var useForChildrenField = customPropertyDrawer.GetType().GetField("m_UseForChildren", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (useForChildrenField != null)
|
||||
{
|
||||
object useForChildrenValue = useForChildrenField.GetValue(customPropertyDrawer);
|
||||
if (useForChildrenValue is bool && (bool)useForChildrenValue)
|
||||
// Check interfaces
|
||||
if (Array.Exists(interfaceTypes, interfaceType => interfaceType == fieldType))
|
||||
{
|
||||
// Check interfaces
|
||||
if (Array.Exists(interfaceTypes, interfaceType => interfaceType == fieldType))
|
||||
return drawerType;
|
||||
}
|
||||
|
||||
// Check derived types
|
||||
Type baseType = type.BaseType;
|
||||
while (baseType != null)
|
||||
{
|
||||
if (baseType == fieldType)
|
||||
{
|
||||
return drawerType;
|
||||
}
|
||||
|
||||
// Check derived types
|
||||
Type baseType = type.BaseType;
|
||||
while (baseType != null)
|
||||
{
|
||||
if (baseType == fieldType)
|
||||
{
|
||||
return drawerType;
|
||||
}
|
||||
|
||||
baseType = baseType.BaseType;
|
||||
}
|
||||
baseType = baseType.BaseType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -56,7 +56,13 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||
{
|
||||
Rect foldoutRect = new Rect(position);
|
||||
foldoutRect.height = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
#if UNITY_2022_2_OR_NEWER
|
||||
// NOTE: Position x must be adjusted.
|
||||
// FIXME: Is there a more essential solution...?
|
||||
foldoutRect.x -= 12;
|
||||
#endif
|
||||
|
||||
property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, GUIContent.none, true);
|
||||
}
|
||||
|
||||
@@ -124,7 +130,7 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||
Type baseType = ManagedReferenceUtility.GetType(managedReferenceFieldTypename);
|
||||
var popup = new AdvancedTypePopup(
|
||||
TypeCache.GetTypesDerivedFrom(baseType).Append(baseType).Where(p =>
|
||||
(p.IsPublic || p.IsNestedPublic) &&
|
||||
(p.IsPublic || p.IsNestedPublic || p.IsNestedPrivate) &&
|
||||
!p.IsAbstract &&
|
||||
!p.IsGenericType &&
|
||||
!k_UnityObjectType.IsAssignableFrom(p) &&
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "com.mackysoft.serializereference-extensions",
|
||||
"displayName": "SerializeReference Extensions",
|
||||
"author": { "name": "MackySoft", "url": "https://github.com/mackysoft" },
|
||||
"version": "1.3.0",
|
||||
"version": "1.4.0",
|
||||
"unity": "2021.3",
|
||||
"description": "Provide popup to specify the type of the field serialized by the [SerializeReference] attribute in the inspector.",
|
||||
"keywords": [ "SerializeReference", "Editor" ],
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"com.unity.ide.rider": "3.0.24",
|
||||
"com.unity.ide.visualstudio": "2.0.18",
|
||||
"com.unity.ide.rider": "3.0.28",
|
||||
"com.unity.ide.visualstudio": "2.0.22",
|
||||
"com.unity.ide.vscode": "1.2.5",
|
||||
"com.unity.test-framework": "1.1.33",
|
||||
"com.unity.modules.ai": "1.0.0",
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.ide.rider": {
|
||||
"version": "3.0.24",
|
||||
"version": "3.0.28",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
@@ -17,7 +17,7 @@
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.ide.visualstudio": {
|
||||
"version": "2.0.18",
|
||||
"version": "2.0.22",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
|
||||
@@ -18,6 +18,7 @@ The `SubclassSelector` attribute allows you to easily set subclasses of those ab
|
||||
- **[New]** Available `CustomPropertyDrawer` for subclasses.
|
||||
- **[New]** Restore values of previous object from JSON when subclass is changed. (required Unity 2021.3 or later)
|
||||
- **[New]** Copy & Paste the subclass properties. (required Unity 2021.3 or later)
|
||||
- **[New]** Clear & reset the subclass properties. (required Unity 2021.3 or later)
|
||||
|
||||
> See below for the reason for the limitation of versions less than Unity 2021.3.
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user