Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ef305d06fe | |||
| 27c901a24d | |||
| aa2648584f | |||
| 8a5a35f46f | |||
| 6dc9fbcaae | |||
| e02042777f | |||
| 12a6c465d2 | |||
| 810919883f | |||
| c3378c3bc4 | |||
| 1af4ffb925 |
+636
-627
File diff suppressed because it is too large
Load Diff
+26
-17
@@ -22,9 +22,11 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
|
|||||||
|
|
||||||
const int k_MaxTypePopupLineCount = 13;
|
const int k_MaxTypePopupLineCount = 13;
|
||||||
static readonly Type k_UnityObjectType = typeof(UnityEngine.Object);
|
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.");
|
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,TypePopupCache> m_TypePopups = new Dictionary<string,TypePopupCache>();
|
||||||
|
readonly Dictionary<string,GUIContent> m_TypeNameCaches = new Dictionary<string,GUIContent>();
|
||||||
|
|
||||||
SerializedProperty m_TargetProperty;
|
SerializedProperty m_TargetProperty;
|
||||||
|
|
||||||
@@ -40,7 +42,7 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
|
|||||||
popupPosition.x += EditorGUIUtility.labelWidth;
|
popupPosition.x += EditorGUIUtility.labelWidth;
|
||||||
popupPosition.height = EditorGUIUtility.singleLineHeight;
|
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;
|
m_TargetProperty = property;
|
||||||
popup.TypePopup.Show(popupPosition);
|
popup.TypePopup.Show(popupPosition);
|
||||||
}
|
}
|
||||||
@@ -60,17 +62,14 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
|
|||||||
|
|
||||||
Type baseType = property.GetManagedReferenceFieldType();
|
Type baseType = property.GetManagedReferenceFieldType();
|
||||||
var popup = new AdvancedTypePopup(
|
var popup = new AdvancedTypePopup(
|
||||||
AppDomain.CurrentDomain.GetAssemblies()
|
TypeCache.GetTypesDerivedFrom(baseType).Where(p =>
|
||||||
.SelectMany(assembly => assembly.GetTypes())
|
p.IsClass &&
|
||||||
.Where(p =>
|
(p.IsPublic || p.IsNestedPublic) &&
|
||||||
p.IsClass &&
|
!p.IsAbstract &&
|
||||||
(p.IsPublic || p.IsNestedPublic) &&
|
!p.IsGenericType &&
|
||||||
!p.IsAbstract &&
|
!k_UnityObjectType.IsAssignableFrom(p) &&
|
||||||
!p.IsGenericType &&
|
Attribute.IsDefined(p,typeof(SerializableAttribute))
|
||||||
baseType.IsAssignableFrom(p) &&
|
),
|
||||||
!k_UnityObjectType.IsAssignableFrom(p) &&
|
|
||||||
Attribute.IsDefined(p,typeof(SerializableAttribute))
|
|
||||||
),
|
|
||||||
k_MaxTypePopupLineCount,
|
k_MaxTypePopupLineCount,
|
||||||
state
|
state
|
||||||
);
|
);
|
||||||
@@ -86,22 +85,32 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static string GetTypeName (SerializedProperty property) {
|
GUIContent GetTypeName (SerializedProperty property) {
|
||||||
if (string.IsNullOrEmpty(property.managedReferenceFullTypename)) {
|
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();
|
Type type = property.GetManagedReferenceType();
|
||||||
|
string typeName = null;
|
||||||
|
|
||||||
AddTypeMenuAttribute typeMenu = TypeMenuUtility.GetAttribute(type);
|
AddTypeMenuAttribute typeMenu = TypeMenuUtility.GetAttribute(type);
|
||||||
if (typeMenu != null) {
|
if (typeMenu != null) {
|
||||||
string typeName = typeMenu.GetTypeNameWithoutPath();
|
typeName = typeMenu.GetTypeNameWithoutPath();
|
||||||
if (!string.IsNullOrWhiteSpace(typeName)) {
|
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) {
|
public override float GetPropertyHeight (SerializedProperty property,GUIContent label) {
|
||||||
|
|||||||
-18
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "MackySoft.SerializeReferenceExtensions.Example",
|
|
||||||
"rootNamespace": "",
|
|
||||||
"references": [
|
|
||||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50"
|
|
||||||
],
|
|
||||||
"includePlatforms": [],
|
|
||||||
"excludePlatforms": [],
|
|
||||||
"allowUnsafeCode": false,
|
|
||||||
"overrideReferences": false,
|
|
||||||
"precompiledReferences": [],
|
|
||||||
"autoReferenced": true,
|
|
||||||
"defineConstraints": [
|
|
||||||
"UNITY_2019_3_OR_NEWER"
|
|
||||||
],
|
|
||||||
"versionDefines": [],
|
|
||||||
"noEngineReferences": false
|
|
||||||
}
|
|
||||||
-7
@@ -1,7 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: b427d1329953ae946a0fcb528efcb3a3
|
|
||||||
AssemblyDefinitionImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -1,10 +1,17 @@
|
|||||||
{
|
{
|
||||||
"name": "com.mackysoft.serializereference-extensions",
|
"name": "com.mackysoft.serializereference-extensions",
|
||||||
"displayName": "SerializeReference Extensions",
|
"displayName": "SerializeReference Extensions",
|
||||||
"version": "1.0.1",
|
"version": "1.1.1",
|
||||||
"unity": "2019.4",
|
"unity": "2019.4",
|
||||||
"description": "Provide popup to specify the type of the field serialized by the [SerializeReference] attribute in the inspector.",
|
"description": "Provide popup to specify the type of the field serialized by the [SerializeReference] attribute in the inspector.",
|
||||||
"keywords": [ "SerializeReference", "Editor" ],
|
"keywords": [ "SerializeReference", "Editor" ],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {}
|
"dependencies": {},
|
||||||
|
"samples": [
|
||||||
|
{
|
||||||
|
"displayName": "Example",
|
||||||
|
"description": "",
|
||||||
|
"path": "Example"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
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
@@ -1,12 +1,16 @@
|
|||||||
# Unity SerializeReferenceExtensions
|
# Unity SerializeReferenceExtensions
|
||||||
|
|
||||||
|
[](https://github.com/mackysoft/Unity-SerializeReferenceExtensions/actions/workflows/build.yaml)
|
||||||
|
[](https://github.com/mackysoft/Unity-SerializeReferenceExtensions/releases)
|
||||||
|
[](https://openupm.com/packages/com.mackysoft.serializereference-extensions/)
|
||||||
|
|
||||||
**Inspired by [this post](https://qiita.com/tsukimi_neko/items/7922b2433ed4d8616cce).**
|
**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 `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.
|
The `SubclassSelector` attribute allows you to easily set subclasses of those abstract classes in the Editor that are serialized by `SerializeReference` attribute.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
#### Features
|
#### Features
|
||||||
|
|
||||||
@@ -14,6 +18,31 @@ The `SubclassSelector` attribute allows you to easily set subclasses of those ab
|
|||||||
- **[New]** Type finding by fuzzy finder.
|
- **[New]** Type finding by fuzzy finder.
|
||||||
- **[New]** Override the type name and path by the `AddTypeMenu` attribute.
|
- **[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
|
## 🔰 Usage
|
||||||
|
|
||||||
```cs
|
```cs
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 2010
|
# Visual Studio 15
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MackySoft.SerializeReferenceExtensions", "MackySoft.SerializeReferenceExtensions.csproj", "{416A0403-CB55-36CC-5B0D-0D345FA05F49}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MackySoft.SerializeReferenceExtensions", "MackySoft.SerializeReferenceExtensions.csproj", "{416A0403-CB55-36CC-5B0D-0D345FA05F49}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MackySoft.SerializeReferenceExtensions.Example", "MackySoft.SerializeReferenceExtensions.Example.csproj", "{19A3DFD2-76AC-5BD2-796C-431D7979E720}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MackySoft.SerializeReferenceExtensions.Example", "MackySoft.SerializeReferenceExtensions.Example.csproj", "{19A3DFD2-76AC-5BD2-796C-431D7979E720}"
|
||||||
|
|||||||
Reference in New Issue
Block a user