Compare commits

..

10 Commits

Author SHA1 Message Date
github-actions[bot] 69943b46c8 feat: Update package.json to 1.4.0 2024-08-03 16:56:21 +00:00
Makihiro 66fc5ae911 Merge pull request #61 from mackysoft/feature/support-nested-private
SubclassSelector now support nested private type
2024-08-04 01:37:48 +09:00
Makihiro 1757747985 SubclassSelector now support nested private type 2024-08-04 01:37:09 +09:00
github-actions[bot] 69f6e31cf1 feat: Update package.json to 1.3.1 2024-04-01 07:34:45 +00:00
Makihiro 3ffef8d1b2 Update packages 2024-04-01 16:33:44 +09:00
Makihiro a9763b033d Fix foldout layout on Unity 2022.2 or newer 2024-04-01 16:32:53 +09:00
Makihiro 2b40c3d26e Merge pull request #56 from theo-rapidfire/fix/use-type-cache
Performance improvement: Use TypeCache instead of manual type iteration
2024-04-01 16:02:36 +09:00
theo-rapidfire f7c1017567 Use TypeCache instead of manual type iteration
fix/use-type-cache
2024-03-28 13:39:48 +01:00
Makihiro 301cb4b12c Update README.md 2024-02-18 04:00:28 +09:00
Makihiro fe02e0fd1e Update text editor packages 2024-02-18 03:35:49 +09:00
6 changed files with 43 additions and 38 deletions
@@ -26,49 +26,47 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
static Type GetCustomPropertyDrawerType (Type type) static Type GetCustomPropertyDrawerType (Type type)
{ {
Type[] interfaceTypes = type.GetInterfaces(); 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); var field = customPropertyDrawer.GetType().GetField("m_Type", BindingFlags.NonPublic | BindingFlags.Instance);
foreach (CustomPropertyDrawer customPropertyDrawer in customPropertyDrawerAttributes) if (field != null)
{ {
var field = customPropertyDrawer.GetType().GetField("m_Type", BindingFlags.NonPublic | BindingFlags.Instance); var fieldType = field.GetValue(customPropertyDrawer) as Type;
if (field != null) if (fieldType != null)
{ {
var fieldType = field.GetValue(customPropertyDrawer) as Type; if (fieldType == type)
if (fieldType != null)
{ {
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; // Check interfaces
} if (Array.Exists(interfaceTypes, interfaceType => interfaceType == fieldType))
// 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 return drawerType;
if (Array.Exists(interfaceTypes, interfaceType => interfaceType == fieldType)) }
// Check derived types
Type baseType = type.BaseType;
while (baseType != null)
{
if (baseType == fieldType)
{ {
return drawerType; return drawerType;
} }
// Check derived types baseType = baseType.BaseType;
Type baseType = type.BaseType;
while (baseType != null)
{
if (baseType == fieldType)
{
return drawerType;
}
baseType = baseType.BaseType;
}
} }
} }
} }
@@ -56,7 +56,13 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
{ {
Rect foldoutRect = new Rect(position); Rect foldoutRect = new Rect(position);
foldoutRect.height = EditorGUIUtility.singleLineHeight; 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; foldoutRect.x -= 12;
#endif
property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, GUIContent.none, true); property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, GUIContent.none, true);
} }
@@ -124,7 +130,7 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
Type baseType = ManagedReferenceUtility.GetType(managedReferenceFieldTypename); Type baseType = ManagedReferenceUtility.GetType(managedReferenceFieldTypename);
var popup = new AdvancedTypePopup( var popup = new AdvancedTypePopup(
TypeCache.GetTypesDerivedFrom(baseType).Append(baseType).Where(p => TypeCache.GetTypesDerivedFrom(baseType).Append(baseType).Where(p =>
(p.IsPublic || p.IsNestedPublic) && (p.IsPublic || p.IsNestedPublic || p.IsNestedPrivate) &&
!p.IsAbstract && !p.IsAbstract &&
!p.IsGenericType && !p.IsGenericType &&
!k_UnityObjectType.IsAssignableFrom(p) && !k_UnityObjectType.IsAssignableFrom(p) &&
@@ -2,7 +2,7 @@
"name": "com.mackysoft.serializereference-extensions", "name": "com.mackysoft.serializereference-extensions",
"displayName": "SerializeReference Extensions", "displayName": "SerializeReference Extensions",
"author": { "name": "MackySoft", "url": "https://github.com/mackysoft" }, "author": { "name": "MackySoft", "url": "https://github.com/mackysoft" },
"version": "1.3.0", "version": "1.4.0",
"unity": "2021.3", "unity": "2021.3",
"description": "Provide popup to specify the type of the field serialized by the [SerializeReference] attribute in the inspector.", "description": "Provide popup to specify the type of the field serialized by the [SerializeReference] attribute in the inspector.",
"keywords": [ "SerializeReference", "Editor" ], "keywords": [ "SerializeReference", "Editor" ],
+2 -2
View File
@@ -1,7 +1,7 @@
{ {
"dependencies": { "dependencies": {
"com.unity.ide.rider": "3.0.24", "com.unity.ide.rider": "3.0.28",
"com.unity.ide.visualstudio": "2.0.18", "com.unity.ide.visualstudio": "2.0.22",
"com.unity.ide.vscode": "1.2.5", "com.unity.ide.vscode": "1.2.5",
"com.unity.test-framework": "1.1.33", "com.unity.test-framework": "1.1.33",
"com.unity.modules.ai": "1.0.0", "com.unity.modules.ai": "1.0.0",
+2 -2
View File
@@ -8,7 +8,7 @@
"url": "https://packages.unity.com" "url": "https://packages.unity.com"
}, },
"com.unity.ide.rider": { "com.unity.ide.rider": {
"version": "3.0.24", "version": "3.0.28",
"depth": 0, "depth": 0,
"source": "registry", "source": "registry",
"dependencies": { "dependencies": {
@@ -17,7 +17,7 @@
"url": "https://packages.unity.com" "url": "https://packages.unity.com"
}, },
"com.unity.ide.visualstudio": { "com.unity.ide.visualstudio": {
"version": "2.0.18", "version": "2.0.22",
"depth": 0, "depth": 0,
"source": "registry", "source": "registry",
"dependencies": { "dependencies": {
+1
View File
@@ -18,6 +18,7 @@ The `SubclassSelector` attribute allows you to easily set subclasses of those ab
- **[New]** Available `CustomPropertyDrawer` for subclasses. - **[New]** Available `CustomPropertyDrawer` for subclasses.
- **[New]** Restore values of previous object from JSON when subclass is changed. (required Unity 2021.3 or later) - **[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]** 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. > See below for the reason for the limitation of versions less than Unity 2021.3.
> >