Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a78f5a340f | |||
| 69f6e31cf1 | |||
| 3ffef8d1b2 | |||
| a9763b033d | |||
| 2b40c3d26e | |||
| f7c1017567 | |||
| 301cb4b12c | |||
| fe02e0fd1e |
+28
-30
@@ -27,48 +27,46 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
|
|||||||
{
|
{
|
||||||
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;
|
||||||
{
|
}
|
||||||
return drawerType;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the property drawer also allows for being applied to child classes, check if they match
|
// 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);
|
var useForChildrenField = customPropertyDrawer.GetType().GetField("m_UseForChildren", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
if (useForChildrenField != null)
|
if (useForChildrenField != null)
|
||||||
|
{
|
||||||
|
object useForChildrenValue = useForChildrenField.GetValue(customPropertyDrawer);
|
||||||
|
if (useForChildrenValue is bool && (bool)useForChildrenValue)
|
||||||
{
|
{
|
||||||
object useForChildrenValue = useForChildrenField.GetValue(customPropertyDrawer);
|
// Check interfaces
|
||||||
if (useForChildrenValue is bool && (bool)useForChildrenValue)
|
if (Array.Exists(interfaceTypes, interfaceType => interfaceType == fieldType))
|
||||||
{
|
{
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+23
@@ -5,6 +5,8 @@ using System.Collections.Generic;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEditor.IMGUI.Controls;
|
using UnityEditor.IMGUI.Controls;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
using UnityEditor.UIElements;
|
||||||
|
|
||||||
namespace MackySoft.SerializeReferenceExtensions.Editor
|
namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||||
{
|
{
|
||||||
@@ -56,7 +58,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,6 +112,21 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
|
|||||||
EditorGUI.EndProperty();
|
EditorGUI.EndProperty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override VisualElement CreatePropertyGUI (SerializedProperty property)
|
||||||
|
{
|
||||||
|
VisualElement root = new VisualElement();
|
||||||
|
if (property.propertyType == SerializedPropertyType.ManagedReference)
|
||||||
|
{
|
||||||
|
TypePopupField typePopupField = new TypePopupField(property, new VisualElement());
|
||||||
|
root.Add(typePopupField);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new Label(k_IsNotManagedReferenceLabel.text);
|
||||||
|
}
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
PropertyDrawer GetCustomPropertyDrawer (SerializedProperty property)
|
PropertyDrawer GetCustomPropertyDrawer (SerializedProperty property)
|
||||||
{
|
{
|
||||||
Type propertyType = ManagedReferenceUtility.GetType(property.managedReferenceFullTypename);
|
Type propertyType = ManagedReferenceUtility.GetType(property.managedReferenceFullTypename);
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
#if UNITY_2019_3_OR_NEWER
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
|
||||||
|
namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||||
|
{
|
||||||
|
public sealed class TypePopupField : BaseField<object>
|
||||||
|
{
|
||||||
|
|
||||||
|
public new static readonly string ussClassName = "unity-base-popup-field";
|
||||||
|
|
||||||
|
public static readonly string textUssClassName = ussClassName + "__text";
|
||||||
|
|
||||||
|
public static readonly string arrowUssClassName = ussClassName + "__arrow";
|
||||||
|
|
||||||
|
public new static readonly string labelUssClassName = ussClassName + "__label";
|
||||||
|
|
||||||
|
public new static readonly string inputUssClassName = ussClassName + "__input";
|
||||||
|
|
||||||
|
readonly SerializedProperty m_Property;
|
||||||
|
|
||||||
|
readonly Toggle m_Toggle;
|
||||||
|
|
||||||
|
readonly VisualElement m_ArrowElement;
|
||||||
|
readonly Label m_TextElement;
|
||||||
|
|
||||||
|
public TypePopupField (SerializedProperty property, VisualElement visualInput) : base(property.displayName, visualInput)
|
||||||
|
{
|
||||||
|
m_Property = property;
|
||||||
|
|
||||||
|
style.flexDirection = FlexDirection.Row;
|
||||||
|
style.flexShrink = 0;
|
||||||
|
style.flexGrow = 1;
|
||||||
|
|
||||||
|
AddToClassList(ussClassName);
|
||||||
|
AddToClassList("unity-base-field__aligned");
|
||||||
|
AddToClassList("unity-base-field__inspector-field");
|
||||||
|
|
||||||
|
labelElement.AddToClassList(labelUssClassName);
|
||||||
|
labelElement.AddToClassList("unity-popup-field__label");
|
||||||
|
labelElement.AddToClassList("unity-property-field__label");
|
||||||
|
|
||||||
|
m_TextElement = new Label(property.displayName)
|
||||||
|
{
|
||||||
|
pickingMode = PickingMode.Ignore
|
||||||
|
};
|
||||||
|
m_TextElement.AddToClassList(textUssClassName);
|
||||||
|
visualInput.AddToClassList(inputUssClassName);
|
||||||
|
visualInput.Add(m_TextElement);
|
||||||
|
visualInput.pickingMode = PickingMode.Ignore;
|
||||||
|
|
||||||
|
m_ArrowElement = new VisualElement();
|
||||||
|
m_ArrowElement.AddToClassList(arrowUssClassName);
|
||||||
|
m_ArrowElement.pickingMode = PickingMode.Ignore;
|
||||||
|
visualInput.Add(m_ArrowElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ad665a39f1251a14ea9f40c0c9cf3a75
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -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.3.1",
|
||||||
"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" ],
|
||||||
|
|||||||
@@ -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",
|
||||||
|
|||||||
@@ -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": {
|
||||||
|
|||||||
@@ -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.
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user