Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a78f5a340f |
@@ -14,7 +14,7 @@ jobs:
|
||||
steps:
|
||||
# Checkout
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
lfs: true
|
||||
|
||||
@@ -39,7 +39,7 @@ jobs:
|
||||
|
||||
# Upload
|
||||
- name: Upload .unitypackage
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: Unity Package
|
||||
path: Build
|
||||
@@ -18,7 +18,7 @@ jobs:
|
||||
outputs:
|
||||
sha: ${{ steps.commit.outputs.sha }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v2
|
||||
- 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@v4
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
ref: ${{ needs.update-packagejson.outputs.sha }}
|
||||
|
||||
@@ -97,7 +97,7 @@ jobs:
|
||||
working-directory: .
|
||||
|
||||
# Store artifacts.
|
||||
- uses: actions/upload-artifact@v4
|
||||
- uses: actions/upload-artifact@v2
|
||||
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@v4
|
||||
- uses: actions/download-artifact@v2
|
||||
|
||||
# Upload to Releases(unitypackage)
|
||||
- uses: actions/upload-release-asset@v1
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using UnityEditor;
|
||||
@@ -41,17 +42,6 @@ public class Grape : Food
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[HideInTypeMenu]
|
||||
public class Banana : Food
|
||||
{
|
||||
public Banana ()
|
||||
{
|
||||
name = "Banana";
|
||||
kcal = 100f;
|
||||
}
|
||||
}
|
||||
|
||||
public class Example : MonoBehaviour
|
||||
{
|
||||
|
||||
@@ -70,8 +60,7 @@ public class Example : MonoBehaviour
|
||||
[SerializeReference, SubclassSelector]
|
||||
public Food foodTwo = new Peach();
|
||||
|
||||
// UseToStringAsLabel support on UNITY_2021_3_OR_NEWER
|
||||
[SerializeReference, SubclassSelector(UseToStringAsLabel = true)]
|
||||
[SerializeReference, SubclassSelector]
|
||||
public Food foodThree = new Grape();
|
||||
|
||||
[SerializeReference]
|
||||
@@ -127,3 +116,5 @@ public class AppleDrawer : PropertyDrawer
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -137,3 +138,4 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
+3
-1
@@ -12,7 +12,9 @@
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"defineConstraints": [
|
||||
"UNITY_2019_3_OR_NEWER"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
+3
-1
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
@@ -44,3 +45,4 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
+3
-1
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using System.Reflection;
|
||||
@@ -78,3 +79,4 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
+3
-1
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
||||
namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||
@@ -27,3 +28,4 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
+29
-17
@@ -1,9 +1,12 @@
|
||||
using System;
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEditor.UIElements;
|
||||
|
||||
namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||
{
|
||||
@@ -21,7 +24,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.");
|
||||
|
||||
@@ -42,19 +45,6 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||
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))
|
||||
{
|
||||
@@ -69,7 +59,7 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||
Rect foldoutRect = new Rect(position);
|
||||
foldoutRect.height = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
#if UNITY_2022_2
|
||||
#if UNITY_2022_2_OR_NEWER
|
||||
// NOTE: Position x must be adjusted.
|
||||
// FIXME: Is there a more essential solution...?
|
||||
foldoutRect.x -= 12;
|
||||
@@ -122,6 +112,21 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||
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)
|
||||
{
|
||||
Type propertyType = ManagedReferenceUtility.GetType(property.managedReferenceFullTypename);
|
||||
@@ -141,7 +146,13 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||
|
||||
Type baseType = ManagedReferenceUtility.GetType(managedReferenceFieldTypename);
|
||||
var popup = new AdvancedTypePopup(
|
||||
TypeMenuUtility.GetTypes(baseType),
|
||||
TypeCache.GetTypesDerivedFrom(baseType).Append(baseType).Where(p =>
|
||||
(p.IsPublic || p.IsNestedPublic) &&
|
||||
!p.IsAbstract &&
|
||||
!p.IsGenericType &&
|
||||
!k_UnityObjectType.IsAssignableFrom(p) &&
|
||||
Attribute.IsDefined(p,typeof(SerializableAttribute))
|
||||
),
|
||||
k_MaxTypePopupLineCount,
|
||||
state
|
||||
);
|
||||
@@ -211,3 +222,4 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,25 +1,12 @@
|
||||
using System;
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
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;
|
||||
@@ -55,3 +42,4 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -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
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f48f5d86a108b94a9c26381f5ce678c
|
||||
guid: ad665a39f1251a14ea9f40c0c9cf3a75
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
+4
-1
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// An attribute that overrides the name of the type displayed in the SubclassSelector popup.
|
||||
@@ -33,3 +35,4 @@ public sealed class AddTypeMenuAttribute : Attribute {
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
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 {
|
||||
|
||||
}
|
||||
+3
-1
@@ -8,7 +8,9 @@
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"defineConstraints": [
|
||||
"UNITY_2019_3_OR_NEWER"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
+5
-9
@@ -1,16 +1,12 @@
|
||||
using System;
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
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
|
||||
{
|
||||
|
||||
#if UNITY_2021_3_OR_NEWER
|
||||
// NOTE: Use managedReferenceValue getter to invoke instance method in SubclassSelectorDrawer.
|
||||
public bool UseToStringAsLabel { get; set; }
|
||||
#endif
|
||||
[AttributeUsage(AttributeTargets.Field,AllowMultiple = false)]
|
||||
public sealed class SubclassSelectorAttribute : PropertyAttribute {
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "com.mackysoft.serializereference-extensions",
|
||||
"displayName": "SerializeReference Extensions",
|
||||
"author": { "name": "MackySoft", "url": "https://github.com/mackysoft" },
|
||||
"version": "1.5.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" ],
|
||||
|
||||
Reference in New Issue
Block a user