Compare commits

..

7 Commits

Author SHA1 Message Date
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 42 additions and 37 deletions
@@ -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;
}
}
}
@@ -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);
}
@@ -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.3.1",
"unity": "2021.3",
"description": "Provide popup to specify the type of the field serialized by the [SerializeReference] attribute in the inspector.",
"keywords": [ "SerializeReference", "Editor" ],
+2 -2
View File
@@ -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",
+2 -2
View File
@@ -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": {
+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]** 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.
>