Compare commits

..

1 Commits

Author SHA1 Message Date
Makihiro
a78f5a340f UIToolKit test 2024-08-03 23:33:05 +09:00
25 changed files with 159 additions and 422 deletions

View File

@ -12,6 +12,6 @@ body:
- type: textarea
id: feature-description
attributes:
label: Feature description
label: Feature destription
validations:
required: true
required: true

View File

@ -12,6 +12,6 @@ body:
- type: textarea
id: improvement-description
attributes:
label: Improvement description
label: Improvement destription
validations:
required: true
required: true

View File

@ -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

View File

@ -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

View File

@ -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]
@ -126,4 +115,6 @@ public class AppleDrawer : PropertyDrawer
return EditorGUIUtility.singleLineHeight;
}
}
#endif
#endif

View File

@ -13,7 +13,7 @@ OcclusionCullingSettings:
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 10
serializedVersion: 9
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
@ -38,12 +38,13 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 12
m_GIWorkflowMode: 1
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
@ -66,6 +67,9 @@ LightmapSettings:
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 1
m_FinalGather: 0
m_FinalGatherFiltering: 1
m_FinalGatherRayCount: 256
m_ReflectionCompression: 2
m_MixedBakeMode: 2
m_BakeBackend: 1
@ -100,7 +104,7 @@ NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 3
serializedVersion: 2
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
@ -113,7 +117,7 @@ NavMeshSettings:
cellSize: 0.16666667
manualTileSize: 0
tileSize: 256
buildHeightMesh: 0
accuratePlacement: 0
maxJobWorkers: 0
preserveTilesOutsideBounds: 0
debug:
@ -159,17 +163,9 @@ Camera:
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
m_Iso: 200
m_ShutterSpeed: 0.005
m_Aperture: 16
m_FocusDistance: 10
m_FocalLength: 50
m_BladeCount: 5
m_Curvature: {x: 2, y: 11}
m_BarrelClipping: 0.25
m_Anamorphism: 0
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}
m_FocalLength: 50
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
@ -203,13 +199,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 126803971}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &586792171
GameObject:
@ -330,70 +326,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 586792171}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &994260143
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 994260145}
- component: {fileID: 994260144}
m_Layer: 0
m_Name: Example_Generics
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &994260144
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 994260143}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: dff76005e1dfac84287448b12c4b160e, type: 3}
m_Name:
m_EditorClassIdentifier:
contravarianceActions:
- rid: 3354424774140624943
covarianceActions:
- rid: 3354424774140624944
references:
version: 2
RefIds:
- rid: 3354424774140624943
type: {class: DerivedAction1, ns: , asm: Assembly-CSharp}
data:
- rid: 3354424774140624944
type: {class: NetworkActorAction1, ns: , asm: Assembly-CSharp}
data:
--- !u!4 &994260145
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 994260143}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1127138992
GameObject:
@ -420,8 +359,9 @@ Light:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1127138992}
m_Enabled: 1
serializedVersion: 11
serializedVersion: 10
m_Type: 1
m_Shape: 0
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
m_Intensity: 1
m_Range: 10
@ -480,19 +420,11 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1127138992}
serializedVersion: 2
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1660057539 &9223372036854775807
SceneRoots:
m_ObjectHideFlags: 0
m_Roots:
- {fileID: 126803974}
- {fileID: 1127138994}
- {fileID: 586792173}
- {fileID: 994260145}

View File

@ -1,93 +0,0 @@
using System;
using System.Collections.Generic;
using UnityEngine;
public interface IActor { }
public interface IStandardActor : IActor { }
public interface INetworkActor : IActor { }
public interface IContravarianceAction<in T> where T : IActor {
void DoAction (T actor);
}
public interface ICovarianceAction<out T> where T : IActor
{
T Actor { get; }
}
public interface IActorAction : IContravarianceAction<IActor>, ICovarianceAction<IActor> { }
public interface IStandardActorAction : IContravarianceAction<IStandardActor>, ICovarianceAction<IStandardActor> { }
public interface INetworkActorAction : IContravarianceAction<INetworkActor>, ICovarianceAction<INetworkActor> { }
[Serializable]
public sealed class StandardActorAction : IContravarianceAction<IStandardActor>, ICovarianceAction<IStandardActor>
{
public void DoAction (IStandardActor actor)
{
}
public IStandardActor Actor => null;
}
[Serializable]
public sealed class ActorAction : IContravarianceAction<IActor>, ICovarianceAction<IActor>
{
public void DoAction (IActor actor)
{
}
public IActor Actor => null;
}
[Serializable]
public abstract class BaseAction<T> : IContravarianceAction<T>, ICovarianceAction<T> where T : IActor
{
public void DoAction (T actor) {
}
public T Actor => default;
}
[Serializable]
public sealed class DerivedAction1 : BaseAction<IActor> { }
[Serializable]
public sealed class DerivedAction2 : BaseAction<INetworkActor> { }
[Serializable]
public sealed class DerivedAction3 : BaseAction<IStandardActor> { }
[Serializable]
public sealed class NetworkActorAction1 : INetworkActorAction
{
public void DoAction (INetworkActor actor)
{
}
public INetworkActor Actor => null;
}
[Serializable]
public sealed class NetworkActorAction2 : IContravarianceAction<INetworkActor>, ICovarianceAction<INetworkActor>
{
public void DoAction (INetworkActor actor)
{
}
public INetworkActor Actor => null;
}
[Serializable]
public sealed class NetworkActorAction3 : IContravarianceAction<IActor>, ICovarianceAction<IActor>
{
public void DoAction (IActor actor)
{
}
public IActor Actor => null;
}
public class Example_Generics : MonoBehaviour
{
[SerializeReference, SubclassSelector]
public List<IContravarianceAction<INetworkActor>> contravarianceActions = new List<IContravarianceAction<INetworkActor>>();
[SerializeReference, SubclassSelector]
public List<ICovarianceAction<INetworkActor>> covarianceActions = new List<ICovarianceAction<INetworkActor>>();
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: dff76005e1dfac84287448b12c4b160e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,4 +1,5 @@
using System;
#if UNITY_2019_3_OR_NEWER
using System;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
@ -136,4 +137,5 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
}
}
}
}
#endif

View File

@ -12,7 +12,9 @@
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"defineConstraints": [
"UNITY_2019_3_OR_NEWER"
],
"versionDefines": [],
"noEngineReferences": false
}

View File

@ -1,4 +1,5 @@
using System;
#if UNITY_2019_3_OR_NEWER
using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
@ -43,4 +44,5 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
}
}
}
}
#endif

View File

@ -1,4 +1,5 @@
using System;
#if UNITY_2019_3_OR_NEWER
using System;
using System.Collections.Generic;
using UnityEditor;
using System.Reflection;
@ -77,4 +78,5 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
}
}
}
}
#endif

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
#if UNITY_2019_3_OR_NEWER
using System.Collections.Generic;
using UnityEditor;
namespace MackySoft.SerializeReferenceExtensions.Editor
@ -26,4 +27,5 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
}
}
}
}
}
#endif

View File

@ -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.");
@ -39,24 +42,9 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
// Render label first to avoid label overlap for lists
Rect foldoutLabelRect = new Rect(position);
foldoutLabelRect.height = EditorGUIUtility.singleLineHeight;
// NOTE: IndentedRect should be disabled as it causes extra indentation.
//foldoutLabelRect = EditorGUI.IndentedRect(foldoutLabelRect);
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))
{
@ -71,17 +59,9 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
Rect foldoutRect = new Rect(position);
foldoutRect.height = EditorGUIUtility.singleLineHeight;
#if UNITY_2022_2_OR_NEWER && !UNITY_6000_0_OR_NEWER
#if UNITY_2022_2_OR_NEWER
// NOTE: Position x must be adjusted.
// FIXME: Is there a more essential solution...?
// The most promising is UI Toolkit, but it is currently unable to reproduce all of SubclassSelector features. (Complete provision of contextual menu, e.g.)
// 2021.3: No adjustment
// 2022.1: No adjustment
// 2022.2: Adjustment required
// 2022.3: Adjustment required
// 2023.1: Adjustment required
// 2023.2: Adjustment required
// 6000.0: No adjustment
foldoutRect.x -= 12;
#endif
@ -132,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);
@ -151,7 +146,13 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
Type baseType = ManagedReferenceUtility.GetType(managedReferenceFieldTypename);
var popup = new AdvancedTypePopup(
TypeSearch.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
);
@ -221,3 +222,4 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
}
}
#endif

View File

@ -1,10 +1,9 @@
using System;
#if UNITY_2019_3_OR_NEWER
using System;
using System.Linq;
using System.Collections.Generic;
using UnityEditor;
namespace MackySoft.SerializeReferenceExtensions.Editor
{
namespace MackySoft.SerializeReferenceExtensions.Editor {
public static class TypeMenuUtility {
public const string k_NullDisplayName = "<null>";
@ -42,4 +41,5 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
}
}
}
}
#endif

View File

@ -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

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 9f48f5d86a108b94a9c26381f5ce678c
guid: ad665a39f1251a14ea9f40c0c9cf3a75
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -1,142 +0,0 @@
using System;
using System.Linq;
using System.Collections.Generic;
using UnityEditor;
using System.Reflection;
namespace MackySoft.SerializeReferenceExtensions.Editor
{
public static class TypeSearch
{
#if UNITY_2023_2_OR_NEWER
static readonly Dictionary<Type, List<Type>> m_TypeCache = new Dictionary<Type, List<Type>>();
#endif
public static IEnumerable<Type> GetTypes (Type baseType)
{
#if UNITY_2023_2_OR_NEWER
// NOTE: This is a generics solution for Unity 2023.2 and later.
// 2023.2 because SerializeReference supports generic type instances and because the behaviour is stable.
if (baseType.IsGenericType)
{
return GetTypesWithGeneric(baseType);
}
else
{
return GetTypesUsingTypeCache(baseType);
}
#else
return GetTypesUsingTypeCache(baseType);
#endif
}
static IEnumerable<Type> GetTypesUsingTypeCache (Type baseType)
{
return TypeCache.GetTypesDerivedFrom(baseType)
.Append(baseType)
.Where(IsValidType);
}
#if UNITY_2023_2_OR_NEWER
static IEnumerable<Type> GetTypesWithGeneric (Type baseType)
{
if (m_TypeCache.TryGetValue(baseType, out List<Type> result))
{
return result;
}
result = new List<Type>();
Type genericTypeDefinition = null;
Type[] targetTypeArguments = null;
Type[] genericTypeParameters = null;
if (baseType.IsGenericType)
{
genericTypeDefinition = baseType.GetGenericTypeDefinition();
targetTypeArguments = baseType.GetGenericArguments();
genericTypeParameters = genericTypeDefinition.GetGenericArguments();
}
else
{
genericTypeDefinition = baseType;
targetTypeArguments = Type.EmptyTypes;
genericTypeParameters = Type.EmptyTypes;
}
IEnumerable<Type> types = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(x => x.GetTypes())
.Where(IsValidType);
foreach (Type type in types)
{
Type[] interfaceTypes = type.GetInterfaces();
foreach (Type interfaceType in interfaceTypes)
{
if (!interfaceType.IsGenericType || interfaceType.GetGenericTypeDefinition() != genericTypeDefinition)
{
continue;
}
Type[] sourceTypeArguments = interfaceType.GetGenericArguments();
bool allParametersMatch = true;
for (int i = 0; i < genericTypeParameters.Length; i++)
{
var variance = genericTypeParameters[i].GenericParameterAttributes & GenericParameterAttributes.VarianceMask;
Type sourceTypeArgument = sourceTypeArguments[i];
Type targetTypeArgument = targetTypeArguments[i];
if (variance == GenericParameterAttributes.Contravariant)
{
if (!sourceTypeArgument.IsAssignableFrom(targetTypeArgument))
{
allParametersMatch = false;
break;
}
}
else if (variance == GenericParameterAttributes.Covariant)
{
if (!targetTypeArgument.IsAssignableFrom(sourceTypeArgument))
{
allParametersMatch = false;
break;
}
}
else
{
if (sourceTypeArgument != targetTypeArgument)
{
allParametersMatch = false;
break;
}
}
}
if (allParametersMatch)
{
result.Add(type);
break;
}
}
}
m_TypeCache.Add(baseType, result);
return result;
}
#endif
static bool IsValidType (Type type)
{
return
(type.IsPublic || type.IsNestedPublic || type.IsNestedPrivate) &&
!type.IsAbstract &&
!type.IsGenericType &&
!typeof(UnityEngine.Object).IsAssignableFrom(type) &&
Attribute.IsDefined(type, typeof(SerializableAttribute)) &&
!Attribute.IsDefined(type, typeof(HideInTypeMenuAttribute));
}
}
}

View File

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 5ea24172520aa2646954c1d246e7ba5d

View File

@ -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.
@ -32,4 +34,5 @@ public sealed class AddTypeMenuAttribute : Attribute {
return (splittedDisplayName.Length != 0) ? splittedDisplayName[splittedDisplayName.Length - 1] : null;
}
}
}
#endif

View File

@ -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 {
}

View File

@ -8,7 +8,9 @@
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"defineConstraints": [
"UNITY_2019_3_OR_NEWER"
],
"versionDefines": [],
"noEngineReferences": false
}

View File

@ -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

View File

@ -2,7 +2,7 @@
"name": "com.mackysoft.serializereference-extensions",
"displayName": "SerializeReference Extensions",
"author": { "name": "MackySoft", "url": "https://github.com/mackysoft" },
"version": "1.6.1",
"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" ],

View File

@ -19,7 +19,6 @@ The `SubclassSelector` attribute allows you to easily set subclasses of those ab
- **[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)
- **[New]** Covariance / Contravariance support. (required Unity 2023.2 or later)
> See below for the reason for the limitation of versions less than Unity 2021.3.
>
@ -140,7 +139,7 @@ public struct StructCommand : ICommand {
The `SubclassSelector` attribute supports types that meet the following conditions.
- Public or nested private
- Public
- Not abstract
- Not generic
- Not unity object