Compare commits

..

17 Commits

Author SHA1 Message Date
github-actions[bot] 3386bbbb93 feat: Update package.json to 1.5.0 2024-10-26 15:03:50 +00:00
Makihiro 522393cd91 Update Example.cs 2024-10-26 23:44:24 +09:00
Makihiro e61a077f9c Merge branch 'main' of https://github.com/mackysoft/Unity-SerializeReferenceExtensions 2024-10-26 23:41:15 +09:00
Makihiro 2dfbdc0405 Update release.yaml 2024-10-26 23:40:18 +09:00
Makihiro 60adb3e3d3 Merge pull request #74 from mackysoft/feature/use-tostring-as-label
Implement SubclassSelectorAttribute.UseToStringAsLabel
2024-10-26 23:35:48 +09:00
Makihiro 0b79cd7e40 Implement SubclassSelectorAttribute.UseToStringAsLabel 2024-10-26 23:31:00 +09:00
Makihiro d9bc19329f Merge pull request #73 from mackysoft/fix/remove-directive-2019-3
Remove UNITY_2019_3_OR_NEWER directive
2024-10-26 21:33:19 +09:00
Makihiro 6d39db142a Merge branch 'main' into fix/remove-directive-2019-3 2024-10-26 21:28:35 +09:00
Makihiro 97d028ef2a Remove UNITY_2019_3_OR_NEWER directive 2024-10-26 21:27:40 +09:00
Makihiro 9df6eae13c Merge pull request #67 from bulleador/patch-1
fix: foldout arrow rendered out of the inspector in 2022.3 and newer
2024-10-26 21:10:03 +09:00
Makihiro 8f4e361790 Merge pull request #72 from mackysoft/feature/hide-in-type-menu
Feature/hide in type menu
2024-10-26 20:13:10 +09:00
Makihiro 83b67afcc2 Update package.yaml 2024-10-26 20:06:33 +09:00
Makihiro 4cac61d3ed Add HideInTypeMenu example 2024-10-26 20:02:48 +09:00
Makihiro 6269f7f67a Add TypeMenuUtility.GetTypes method 2024-10-26 20:02:37 +09:00
Makihiro 63d2d94953 Add HideInTypeMenuAttribute 2024-10-26 20:01:51 +09:00
Bullet 71fa059b0c fix: foldout arrow rendered out of the inspector in 2022.3 and newer 2024-09-07 15:29:21 +02:00
Makihiro b7d76fb0c5 Update README.md 2024-08-05 18:49:05 +09:00
17 changed files with 97 additions and 62 deletions
+2 -2
View File
@@ -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
+4 -4
View File
@@ -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
+13 -4
View File
@@ -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]
@@ -116,5 +127,3 @@ public class AppleDrawer : PropertyDrawer
}
}
#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;
@@ -138,4 +137,3 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
}
}
#endif
@@ -12,9 +12,7 @@
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [
"UNITY_2019_3_OR_NEWER"
],
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
@@ -1,5 +1,4 @@
#if UNITY_2019_3_OR_NEWER
using System;
using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
@@ -45,4 +44,3 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
}
}
#endif
@@ -1,5 +1,4 @@
#if UNITY_2019_3_OR_NEWER
using System;
using System;
using System.Collections.Generic;
using UnityEditor;
using System.Reflection;
@@ -79,4 +78,3 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
}
}
#endif
@@ -1,5 +1,4 @@
#if UNITY_2019_3_OR_NEWER
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEditor;
namespace MackySoft.SerializeReferenceExtensions.Editor
@@ -28,4 +27,3 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
}
}
}
#endif
@@ -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.");
@@ -43,6 +42,19 @@ 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))
{
@@ -57,7 +69,7 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
Rect foldoutRect = new Rect(position);
foldoutRect.height = EditorGUIUtility.singleLineHeight;
#if UNITY_2022_2_OR_NEWER
#if UNITY_2022_2
// NOTE: Position x must be adjusted.
// FIXME: Is there a more essential solution...?
foldoutRect.x -= 12;
@@ -129,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.IsNestedPrivate) &&
!p.IsAbstract &&
!p.IsGenericType &&
!k_UnityObjectType.IsAssignableFrom(p) &&
Attribute.IsDefined(p,typeof(SerializableAttribute))
),
TypeMenuUtility.GetTypes(baseType),
k_MaxTypePopupLineCount,
state
);
@@ -205,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;
@@ -42,4 +55,3 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
}
}
#endif
@@ -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.
@@ -35,4 +33,3 @@ public sealed class AddTypeMenuAttribute : Attribute {
}
}
#endif
@@ -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 {
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9f48f5d86a108b94a9c26381f5ce678c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -8,9 +8,7 @@
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [
"UNITY_2019_3_OR_NEWER"
],
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
@@ -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 {
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
}
#endif
@@ -2,7 +2,7 @@
"name": "com.mackysoft.serializereference-extensions",
"displayName": "SerializeReference Extensions",
"author": { "name": "MackySoft", "url": "https://github.com/mackysoft" },
"version": "1.4.0",
"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 -1
View File
@@ -139,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