Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3386bbbb93 | |||
| 522393cd91 | |||
| e61a077f9c | |||
| 2dfbdc0405 | |||
| 60adb3e3d3 | |||
| 0b79cd7e40 | |||
| d9bc19329f | |||
| 6d39db142a | |||
| 97d028ef2a | |||
| 9df6eae13c | |||
| 8f4e361790 | |||
| 83b67afcc2 | |||
| 4cac61d3ed | |||
| 6269f7f67a | |||
| 63d2d94953 | |||
| 71fa059b0c | |||
| b7d76fb0c5 | |||
| 69943b46c8 | |||
| 66fc5ae911 | |||
| 1757747985 | |||
| 69f6e31cf1 | |||
| 3ffef8d1b2 | |||
| a9763b033d | |||
| 2b40c3d26e | |||
| f7c1017567 | |||
| 301cb4b12c | |||
| fe02e0fd1e | |||
| 05efde5001 | |||
| f275c468ec | |||
| c141acf129 | |||
| fdc0a286c8 | |||
| e5627b1caf | |||
| 5f54c254f3 | |||
| b8c11e7836 | |||
| f656cd0f12 | |||
| f69bfc6773 |
@@ -14,7 +14,7 @@ jobs:
|
||||
steps:
|
||||
# Checkout
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
lfs: true
|
||||
|
||||
@@ -39,7 +39,7 @@ jobs:
|
||||
|
||||
# Upload
|
||||
- name: Upload .unitypackage
|
||||
uses: actions/upload-artifact@v2
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: Unity Package
|
||||
path: Build
|
||||
@@ -18,7 +18,7 @@ jobs:
|
||||
outputs:
|
||||
sha: ${{ steps.commit.outputs.sha }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
- name: Output package.json (Before)
|
||||
run: cat ${{ env.TARGET_FILE}}
|
||||
|
||||
@@ -69,7 +69,7 @@ jobs:
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- run: echo ${{ needs.update-packagejson.outputs.sha }}
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ needs.update-packagejson.outputs.sha }}
|
||||
|
||||
@@ -97,7 +97,7 @@ jobs:
|
||||
working-directory: .
|
||||
|
||||
# Store artifacts.
|
||||
- uses: actions/upload-artifact@v2
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: SerializeReference-Extensions.unitypackage
|
||||
path: ./Build/SerializeReference-Extensions.unitypackage
|
||||
@@ -119,7 +119,7 @@ jobs:
|
||||
prerelease: false
|
||||
|
||||
# Download(All) Artifacts to current directory
|
||||
- uses: actions/download-artifact@v2
|
||||
- uses: actions/download-artifact@v4
|
||||
|
||||
# Upload to Releases(unitypackage)
|
||||
- uses: actions/upload-release-asset@v1
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using UnityEditor;
|
||||
@@ -42,6 +41,17 @@ public class Grape : Food
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[HideInTypeMenu]
|
||||
public class Banana : Food
|
||||
{
|
||||
public Banana ()
|
||||
{
|
||||
name = "Banana";
|
||||
kcal = 100f;
|
||||
}
|
||||
}
|
||||
|
||||
public class Example : MonoBehaviour
|
||||
{
|
||||
|
||||
@@ -60,7 +70,8 @@ public class Example : MonoBehaviour
|
||||
[SerializeReference, SubclassSelector]
|
||||
public Food foodTwo = new Peach();
|
||||
|
||||
[SerializeReference, SubclassSelector]
|
||||
// UseToStringAsLabel support on UNITY_2021_3_OR_NEWER
|
||||
[SerializeReference, SubclassSelector(UseToStringAsLabel = true)]
|
||||
public Food foodThree = new Grape();
|
||||
|
||||
[SerializeReference]
|
||||
@@ -115,6 +126,4 @@ public class AppleDrawer : PropertyDrawer
|
||||
return EditorGUIUtility.singleLineHeight;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,4 @@
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
using System;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -137,5 +136,4 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
+1
-3
@@ -12,9 +12,7 @@
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [
|
||||
"UNITY_2019_3_OR_NEWER"
|
||||
],
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
+41
-1
@@ -1,17 +1,20 @@
|
||||
// NOTE: managedReferenceValue getter is available only in Unity 2021.3 or later.
|
||||
#if UNITY_2021_3_OR_NEWER
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||
{
|
||||
public static class CopyAndPasteProperty
|
||||
public static class ManagedReferenceContextualPropertyMenu
|
||||
{
|
||||
|
||||
const string kCopiedPropertyPathKey = "SerializeReferenceExtensions.CopiedPropertyPath";
|
||||
const string kClipboardKey = "SerializeReferenceExtensions.CopyAndPasteProperty";
|
||||
|
||||
static readonly GUIContent kPasteContent = new GUIContent("Paste Property");
|
||||
static readonly GUIContent kNewInstanceContent = new GUIContent("New Instance");
|
||||
static readonly GUIContent kResetAndNewInstanceContent = new GUIContent("Reset and New Instance");
|
||||
|
||||
[InitializeOnLoadMethod]
|
||||
static void Initialize ()
|
||||
@@ -38,6 +41,20 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||
{
|
||||
menu.AddDisabledItem(kPasteContent);
|
||||
}
|
||||
|
||||
menu.AddSeparator("");
|
||||
|
||||
bool hasInstance = clonedProperty.managedReferenceValue != null;
|
||||
if (hasInstance)
|
||||
{
|
||||
menu.AddItem(kNewInstanceContent, false, NewInstance, clonedProperty);
|
||||
menu.AddItem(kResetAndNewInstanceContent, false, ResetAndNewInstance, clonedProperty);
|
||||
}
|
||||
else
|
||||
{
|
||||
menu.AddDisabledItem(kNewInstanceContent);
|
||||
menu.AddDisabledItem(kResetAndNewInstanceContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +79,29 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||
JsonUtility.FromJsonOverwrite(json, property.managedReferenceValue);
|
||||
property.serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
static void NewInstance (object customData)
|
||||
{
|
||||
SerializedProperty property = (SerializedProperty)customData;
|
||||
string json = JsonUtility.ToJson(property.managedReferenceValue);
|
||||
|
||||
Undo.RecordObject(property.serializedObject.targetObject, "New Instance");
|
||||
property.managedReferenceValue = JsonUtility.FromJson(json, property.managedReferenceValue.GetType());
|
||||
property.serializedObject.ApplyModifiedProperties();
|
||||
|
||||
Debug.Log($"Create new instance of \"{property.propertyPath}\".");
|
||||
}
|
||||
|
||||
static void ResetAndNewInstance (object customData)
|
||||
{
|
||||
SerializedProperty property = (SerializedProperty)customData;
|
||||
|
||||
Undo.RecordObject(property.serializedObject.targetObject, "Reset and New Instance");
|
||||
property.managedReferenceValue = Activator.CreateInstance(property.managedReferenceValue.GetType());
|
||||
property.serializedObject.ApplyModifiedProperties();
|
||||
|
||||
Debug.Log($"Reset property and created new instance of \"{property.propertyPath}\".");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
+6
-6
@@ -1,10 +1,11 @@
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
using System;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MackySoft.SerializeReferenceExtensions.Editor {
|
||||
namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||
{
|
||||
|
||||
public static class ManagedReferenceUtility {
|
||||
|
||||
public static object SetManagedReference (this SerializedProperty property,Type type) {
|
||||
@@ -12,7 +13,7 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
|
||||
|
||||
#if UNITY_2021_3_OR_NEWER
|
||||
// NOTE: managedReferenceValue getter is available only in Unity 2021.3 or later.
|
||||
if (property.managedReferenceValue != null && type != null)
|
||||
if ((type != null) && (property.managedReferenceValue != null))
|
||||
{
|
||||
// Restore an previous values from json.
|
||||
string json = JsonUtility.ToJson(property.managedReferenceValue);
|
||||
@@ -42,5 +43,4 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
+32
-36
@@ -1,5 +1,4 @@
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using System.Reflection;
|
||||
@@ -26,49 +25,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,5 +77,4 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
||||
namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||
{
|
||||
public static class SerializedPropertyExtensions
|
||||
{
|
||||
public static IEnumerable<SerializedProperty> GetChildProperties (this SerializedProperty parent, int depth = 1)
|
||||
{
|
||||
parent = parent.Copy();
|
||||
|
||||
int depthOfParent = parent.depth;
|
||||
var enumerator = parent.GetEnumerator();
|
||||
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
if (enumerator.Current is not SerializedProperty childProperty)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (childProperty.depth > (depthOfParent + depth))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
yield return childProperty.Copy();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b934aeca38cb7a24cabd6047fe0e298a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+65
-32
@@ -1,5 +1,4 @@
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
using System;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -22,7 +21,7 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||
}
|
||||
|
||||
const int k_MaxTypePopupLineCount = 13;
|
||||
static readonly Type k_UnityObjectType = typeof(UnityEngine.Object);
|
||||
|
||||
static readonly GUIContent k_NullDisplayName = new GUIContent(TypeMenuUtility.k_NullDisplayName);
|
||||
static readonly GUIContent k_IsNotManagedReferenceLabel = new GUIContent("The property type is not manage reference.");
|
||||
|
||||
@@ -31,51 +30,93 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||
|
||||
SerializedProperty m_TargetProperty;
|
||||
|
||||
public override void OnGUI (Rect position,SerializedProperty property,GUIContent label) {
|
||||
EditorGUI.BeginProperty(position,label,property);
|
||||
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
if (property.propertyType == SerializedPropertyType.ManagedReference) {
|
||||
|
||||
// render label first to avoid label overlap for lists
|
||||
if (property.propertyType == SerializedPropertyType.ManagedReference)
|
||||
{
|
||||
// Render label first to avoid label overlap for lists
|
||||
Rect foldoutLabelRect = new Rect(position);
|
||||
foldoutLabelRect.height = EditorGUIUtility.singleLineHeight;
|
||||
foldoutLabelRect.x += EditorGUI.indentLevel * 12;
|
||||
foldoutLabelRect = EditorGUI.IndentedRect(foldoutLabelRect);
|
||||
Rect popupPosition = EditorGUI.PrefixLabel(foldoutLabelRect, label);
|
||||
|
||||
#if UNITY_2021_3_OR_NEWER
|
||||
// Override the label text with the ToString() of the managed reference.
|
||||
var subclassSelectorAttribute = (SubclassSelectorAttribute)attribute;
|
||||
if (subclassSelectorAttribute.UseToStringAsLabel && !property.hasMultipleDifferentValues)
|
||||
{
|
||||
object managedReferenceValue = property.managedReferenceValue;
|
||||
if (managedReferenceValue != null)
|
||||
{
|
||||
label.text = managedReferenceValue.ToString();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Draw the subclass selector popup.
|
||||
if (EditorGUI.DropdownButton(popupPosition,GetTypeName(property),FocusType.Keyboard)) {
|
||||
if (EditorGUI.DropdownButton(popupPosition, GetTypeName(property), FocusType.Keyboard))
|
||||
{
|
||||
TypePopupCache popup = GetTypePopup(property);
|
||||
m_TargetProperty = property;
|
||||
popup.TypePopup.Show(popupPosition);
|
||||
}
|
||||
|
||||
// Check if a custom property drawer exists for this type.
|
||||
PropertyDrawer customDrawer = GetCustomPropertyDrawer(property);
|
||||
if (customDrawer != null)
|
||||
// Draw the foldout.
|
||||
if (!string.IsNullOrEmpty(property.managedReferenceFullTypename))
|
||||
{
|
||||
// Draw the property with custom property drawer.
|
||||
Rect foldoutRect = new Rect(position);
|
||||
foldoutRect.height = EditorGUIUtility.singleLineHeight;
|
||||
property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, GUIContent.none, true);
|
||||
|
||||
if (property.isExpanded)
|
||||
#if UNITY_2022_2
|
||||
// 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);
|
||||
}
|
||||
|
||||
// Draw property if expanded.
|
||||
if (property.isExpanded)
|
||||
{
|
||||
using (new EditorGUI.IndentLevelScope())
|
||||
{
|
||||
using (new EditorGUI.IndentLevelScope())
|
||||
// Check if a custom property drawer exists for this type.
|
||||
PropertyDrawer customDrawer = GetCustomPropertyDrawer(property);
|
||||
if (customDrawer != null)
|
||||
{
|
||||
// Draw the property with custom property drawer.
|
||||
Rect indentedRect = position;
|
||||
float foldoutDifference = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
indentedRect.height = customDrawer.GetPropertyHeight(property, label);
|
||||
indentedRect.y += foldoutDifference;
|
||||
customDrawer.OnGUI(indentedRect, property, label);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Draw the properties of the child elements.
|
||||
// NOTE: In the following code, since the foldout layout isn't working properly, I'll iterate through the properties of the child elements myself.
|
||||
// EditorGUI.PropertyField(position, property, GUIContent.none, true);
|
||||
|
||||
Rect childPosition = position;
|
||||
childPosition.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
foreach (SerializedProperty childProperty in property.GetChildProperties())
|
||||
{
|
||||
float height = EditorGUI.GetPropertyHeight(childProperty, new GUIContent(childProperty.displayName, childProperty.tooltip), true);
|
||||
childPosition.height = height;
|
||||
EditorGUI.PropertyField(childPosition, childProperty, true);
|
||||
|
||||
childPosition.y += height + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUI.PropertyField(position, property, GUIContent.none, true);
|
||||
}
|
||||
} else {
|
||||
EditorGUI.LabelField(position,label,k_IsNotManagedReferenceLabel);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUI.LabelField(position, label, k_IsNotManagedReferenceLabel);
|
||||
}
|
||||
|
||||
EditorGUI.EndProperty();
|
||||
@@ -100,13 +141,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.IsAbstract &&
|
||||
!p.IsGenericType &&
|
||||
!k_UnityObjectType.IsAssignableFrom(p) &&
|
||||
Attribute.IsDefined(p,typeof(SerializableAttribute))
|
||||
),
|
||||
TypeMenuUtility.GetTypes(baseType),
|
||||
k_MaxTypePopupLineCount,
|
||||
state
|
||||
);
|
||||
@@ -117,7 +152,6 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||
foreach (var targetObject in m_TargetProperty.serializedObject.targetObjects) {
|
||||
SerializedObject individualObject = new SerializedObject(targetObject);
|
||||
SerializedProperty individualProperty = individualObject.FindProperty(m_TargetProperty.propertyPath);
|
||||
|
||||
object obj = individualProperty.SetManagedReference(type);
|
||||
individualProperty.isExpanded = (obj != null);
|
||||
|
||||
@@ -177,4 +211,3 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,12 +1,25 @@
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
using System;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
||||
namespace MackySoft.SerializeReferenceExtensions.Editor {
|
||||
public static class TypeMenuUtility {
|
||||
|
||||
public const string k_NullDisplayName = "<null>";
|
||||
static readonly Type k_UnityObjectType = typeof(UnityEngine.Object);
|
||||
|
||||
public static IEnumerable<Type> GetTypes (Type baseType)
|
||||
{
|
||||
return TypeCache.GetTypesDerivedFrom(baseType).Append(baseType).Where(p =>
|
||||
(p.IsPublic || p.IsNestedPublic || p.IsNestedPrivate) &&
|
||||
!p.IsAbstract &&
|
||||
!p.IsGenericType &&
|
||||
!k_UnityObjectType.IsAssignableFrom(p) &&
|
||||
Attribute.IsDefined(p, typeof(SerializableAttribute)) &&
|
||||
!Attribute.IsDefined(p, typeof(HideInTypeMenuAttribute))
|
||||
);
|
||||
}
|
||||
|
||||
public static AddTypeMenuAttribute GetAttribute (Type type) {
|
||||
return Attribute.GetCustomAttribute(type,typeof(AddTypeMenuAttribute)) as AddTypeMenuAttribute;
|
||||
@@ -41,5 +54,4 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
+2
-5
@@ -1,6 +1,4 @@
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
|
||||
using System;
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// An attribute that overrides the name of the type displayed in the SubclassSelector popup.
|
||||
@@ -34,5 +32,4 @@ public sealed class AddTypeMenuAttribute : Attribute {
|
||||
return (splittedDisplayName.Length != 0) ? splittedDisplayName[splittedDisplayName.Length - 1] : null;
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// An attribute that hides the type in the SubclassSelector.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Interface, AllowMultiple = false, Inherited = false)]
|
||||
public sealed class HideInTypeMenuAttribute : Attribute {
|
||||
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f48f5d86a108b94a9c26381f5ce678c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+1
-3
@@ -8,9 +8,7 @@
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [
|
||||
"UNITY_2019_3_OR_NEWER"
|
||||
],
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
+11
-7
@@ -1,12 +1,16 @@
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
using System;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Attribute to specify the type of the field serialized by the SerializeReference attribute in the inspector.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Field,AllowMultiple = false)]
|
||||
public sealed class SubclassSelectorAttribute : PropertyAttribute {
|
||||
|
||||
}
|
||||
#endif
|
||||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
|
||||
public sealed class SubclassSelectorAttribute : PropertyAttribute
|
||||
{
|
||||
|
||||
#if UNITY_2021_3_OR_NEWER
|
||||
// NOTE: Use managedReferenceValue getter to invoke instance method in SubclassSelectorDrawer.
|
||||
public bool UseToStringAsLabel { get; set; }
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "com.mackysoft.serializereference-extensions",
|
||||
"displayName": "SerializeReference Extensions",
|
||||
"author": { "name": "MackySoft", "url": "https://github.com/mackysoft" },
|
||||
"version": "1.2.2",
|
||||
"version": "1.5.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.
|
||||
>
|
||||
@@ -138,7 +139,7 @@ public struct StructCommand : ICommand {
|
||||
|
||||
The `SubclassSelector` attribute supports types that meet the following conditions.
|
||||
|
||||
- Public
|
||||
- Public or nested private
|
||||
- Not abstract
|
||||
- Not generic
|
||||
- Not unity object
|
||||
|
||||
Reference in New Issue
Block a user