Compare commits

...

7 Commits

Author SHA1 Message Date
github-actions[bot] 8a5a35f46f feat: Update package.json to 1.1.0 2021-05-17 16:30:55 +00:00
mackysoft 6dc9fbcaae Improved performance of SubclassSelectorDrawer
# Changed
- `SubclassSelectorDrawer` now caches the display name of type.
- `SubclassSelectorDrawer` now finds the type via `UnityEditor.TypeCache`.
2021-05-18 01:22:16 +09:00
Makihiro e02042777f Update README.md 2021-05-14 15:57:28 +09:00
Makihiro 12a6c465d2 Update README.md 2021-05-14 02:49:33 +09:00
Makihiro 810919883f Update README.md 2021-05-14 02:44:01 +09:00
Makihiro c3378c3bc4 Update README.md 2021-05-14 02:41:23 +09:00
Makihiro 1af4ffb925 Update README.md 2021-05-14 02:39:59 +09:00
8 changed files with 2500 additions and 2413 deletions
File diff suppressed because it is too large Load Diff
@@ -22,9 +22,11 @@ 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.");
readonly Dictionary<string,TypePopupCache> m_TypePopups = new Dictionary<string,TypePopupCache>();
readonly Dictionary<string,GUIContent> m_TypeNameCaches = new Dictionary<string,GUIContent>();
SerializedProperty m_TargetProperty;
@@ -40,7 +42,7 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
popupPosition.x += EditorGUIUtility.labelWidth;
popupPosition.height = EditorGUIUtility.singleLineHeight;
if (EditorGUI.DropdownButton(popupPosition,new GUIContent(GetTypeName(property)),FocusType.Keyboard)) {
if (EditorGUI.DropdownButton(popupPosition,GetTypeName(property),FocusType.Keyboard)) {
m_TargetProperty = property;
popup.TypePopup.Show(popupPosition);
}
@@ -60,17 +62,14 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
Type baseType = property.GetManagedReferenceFieldType();
var popup = new AdvancedTypePopup(
AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(assembly => assembly.GetTypes())
.Where(p =>
p.IsClass &&
(p.IsPublic || p.IsNestedPublic) &&
!p.IsAbstract &&
!p.IsGenericType &&
baseType.IsAssignableFrom(p) &&
!k_UnityObjectType.IsAssignableFrom(p) &&
Attribute.IsDefined(p,typeof(SerializableAttribute))
),
TypeCache.GetTypesDerivedFrom(baseType).Where(p =>
p.IsClass &&
(p.IsPublic || p.IsNestedPublic) &&
!p.IsAbstract &&
!p.IsGenericType &&
!k_UnityObjectType.IsAssignableFrom(p) &&
Attribute.IsDefined(p,typeof(SerializableAttribute))
),
k_MaxTypePopupLineCount,
state
);
@@ -86,22 +85,32 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
return result;
}
static string GetTypeName (SerializedProperty property) {
GUIContent GetTypeName (SerializedProperty property) {
if (string.IsNullOrEmpty(property.managedReferenceFullTypename)) {
return TypeMenuUtility.k_NullDisplayName;
return k_NullDisplayName;
}
if (m_TypeNameCaches.TryGetValue(property.managedReferenceFullTypename,out GUIContent cachedTypeName)) {
return cachedTypeName;
}
Type type = property.GetManagedReferenceType();
string typeName = null;
AddTypeMenuAttribute typeMenu = TypeMenuUtility.GetAttribute(type);
if (typeMenu != null) {
string typeName = typeMenu.GetTypeNameWithoutPath();
typeName = typeMenu.GetTypeNameWithoutPath();
if (!string.IsNullOrWhiteSpace(typeName)) {
return ObjectNames.NicifyVariableName(typeName);
typeName = ObjectNames.NicifyVariableName(typeName);
}
}
return ObjectNames.NicifyVariableName(type.Name);
if (string.IsNullOrWhiteSpace(typeName)) {
typeName = ObjectNames.NicifyVariableName(type.Name);
}
GUIContent result = new GUIContent(typeName);
m_TypeNameCaches.Add(property.managedReferenceFullTypename,result);
return result;
}
public override float GetPropertyHeight (SerializedProperty property,GUIContent label) {
@@ -1,7 +1,7 @@
{
"name": "com.mackysoft.serializereference-extensions",
"displayName": "SerializeReference Extensions",
"version": "1.0.1",
"version": "1.1.0",
"unity": "2019.4",
"description": "Provide popup to specify the type of the field serialized by the [SerializeReference] attribute in the inspector.",
"keywords": [ "SerializeReference", "Editor" ],
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+30 -1
View File
@@ -1,12 +1,16 @@
# Unity SerializeReferenceExtensions
[![Build](https://github.com/mackysoft/Unity-SerializeReferenceExtensions/actions/workflows/build.yaml/badge.svg)](https://github.com/mackysoft/Unity-SerializeReferenceExtensions/actions/workflows/build.yaml)
[![Release](https://img.shields.io/github/v/release/mackysoft/Unity-SerializeReferenceExtensions)](https://github.com/mackysoft/Unity-SerializeReferenceExtensions/releases)
[![openupm](https://img.shields.io/npm/v/com.mackysoft.serializereference-extensions?label=openupm&registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.mackysoft.serializereference-extensions/)
**Inspired by [this post](https://qiita.com/tsukimi_neko/items/7922b2433ed4d8616cce).**
The `SerializeReference` attribute, added in Unity 2019.3, makes it possible to serialize references to interfaces and abstract classes.
The `SubclassSelector` attribute allows you to easily set subclasses of those abstract classes in the Editor that are serialized by `SerializeReference` attribute.
![SubclassSelector](https://user-images.githubusercontent.com/13536348/113597922-5d912500-9677-11eb-8faa-a33dabc60aa3.gif)
![SubclassSelector](https://user-images.githubusercontent.com/13536348/118233552-03cd1780-b4cd-11eb-9e5b-4824e8f01f1d.gif)
#### Features
@@ -14,6 +18,31 @@ The `SubclassSelector` attribute allows you to easily set subclasses of those ab
- **[New]** Type finding by fuzzy finder.
- **[New]** Override the type name and path by the `AddTypeMenu` attribute.
## 📥 Installation
Download any version from releases.
Releases: https://github.com/mackysoft/Unity-SerializeReferenceExtensions/releases
#### Install via git URL
Or, you can add this package by opening PackageManager and entering
`https://github.com/mackysoft/Unity-SerializeReferenceExtensions.git?path=Assets/MackySoft/MackySoft.SerializeReferenceExtensions`
from the `Add package from git URL` option.
#### Install via Open UPM
Or, you can install this package from the [Open UPM](https://openupm.com/packages/com.mackysoft.serializereference-extensions/) registry.
More details [here](https://openupm.com/).
```
openupm add com.mackysoft.serializereference-extensions
```
## 🔰 Usage
```cs
+2 -2
View File
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MackySoft.SerializeReferenceExtensions", "MackySoft.SerializeReferenceExtensions.csproj", "{416A0403-CB55-36CC-5B0D-0D345FA05F49}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MackySoft.SerializeReferenceExtensions.Example", "MackySoft.SerializeReferenceExtensions.Example.csproj", "{19A3DFD2-76AC-5BD2-796C-431D7979E720}"