Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 28ce93d8fc | |||
| 55a071abe9 | |||
| 4cdcf995f6 | |||
| cf8b8e3b17 | |||
| 9cbd570556 | |||
| 315cf4df85 | |||
| d730a1cdb1 | |||
| f4cfd057cc | |||
| e7a8195f17 | |||
| 112b5f9457 | |||
| f8b317ba20 |
@@ -0,0 +1,34 @@
|
|||||||
|
name: Bug Report
|
||||||
|
description: File a bug report
|
||||||
|
title: "[BUG] "
|
||||||
|
labels: ["bug"]
|
||||||
|
assignees:
|
||||||
|
- mackysoft
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
Thanks for taking the time to fill out this bug report!
|
||||||
|
- type: textarea
|
||||||
|
id: what-happened
|
||||||
|
attributes:
|
||||||
|
label: What happened?
|
||||||
|
description: Also tell us, what did you expect to happen?
|
||||||
|
placeholder: Tell us what you see!
|
||||||
|
value: "A bug happened!"
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: version
|
||||||
|
attributes:
|
||||||
|
label: Package Version
|
||||||
|
description: What version of this package were you running?
|
||||||
|
placeholder: ex. 1.1.2
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: unity-version
|
||||||
|
attributes:
|
||||||
|
label: Unity Version
|
||||||
|
description: What version of Unity were you running?
|
||||||
|
placeholder: ex. 2020.3.24f1
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
name: Feature Request
|
||||||
|
description: Suggest an idea for this library
|
||||||
|
title: "[FEATURE] "
|
||||||
|
labels: ["enhancement"]
|
||||||
|
assignees:
|
||||||
|
- mackysoft
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
Thanks for taking the time to fill out this feature request!
|
||||||
|
- type: textarea
|
||||||
|
id: feature-description
|
||||||
|
attributes:
|
||||||
|
label: Feature destription
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
name: Improvement Request
|
||||||
|
description: Suggest an improve for this library
|
||||||
|
title: "[IMPROVE] "
|
||||||
|
labels: ["enhancement"]
|
||||||
|
assignees:
|
||||||
|
- mackysoft
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
Thanks for taking the time to fill out this improvement request!
|
||||||
|
- type: textarea
|
||||||
|
id: improvement-description
|
||||||
|
attributes:
|
||||||
|
label: Improvement destription
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
## Description
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Write a brief description of what you what to do with this PR.
|
||||||
|
-->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Changes made
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Itemize the changes.
|
||||||
|
-->
|
||||||
|
|
||||||
|
-
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<LangVersion>8.0</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
@@ -52,11 +52,9 @@
|
|||||||
<UnityBuildTarget>StandaloneWindows:5</UnityBuildTarget>
|
<UnityBuildTarget>StandaloneWindows:5</UnityBuildTarget>
|
||||||
<UnityVersion>2020.3.24f1</UnityVersion>
|
<UnityVersion>2020.3.24f1</UnityVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
|
||||||
<Analyzer Include="C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\Extensions\Microsoft\Visual Studio Tools for Unity\Analyzers\Microsoft.Unity.Analyzers.dll" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Assets\PackageTools\Editor\UnityPackageExporter.cs" />
|
<Compile Include="Assets\PackageTools\Editor\UnityPackageExporter.cs" />
|
||||||
|
<Compile Include="Assets\MackySoft\MackySoft.SerializeReferenceExtensions\Example\ExampleAssets\Scripts\Editor\ExampleEditor.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="UnityEngine">
|
<Reference Include="UnityEngine">
|
||||||
|
|||||||
+29
-2
@@ -23,6 +23,8 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class AdvancedTypePopup : AdvancedDropdown {
|
public class AdvancedTypePopup : AdvancedDropdown {
|
||||||
|
|
||||||
|
const int kMaxNamespaceNestCount = 16;
|
||||||
|
|
||||||
public static void AddTo (AdvancedDropdownItem root,IEnumerable<Type> types) {
|
public static void AddTo (AdvancedDropdownItem root,IEnumerable<Type> types) {
|
||||||
int itemCount = 0;
|
int itemCount = 0;
|
||||||
|
|
||||||
@@ -32,8 +34,30 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
|
|||||||
};
|
};
|
||||||
root.AddChild(nullItem);
|
root.AddChild(nullItem);
|
||||||
|
|
||||||
|
Type[] typeArray = types.OrderByType().ToArray();
|
||||||
|
|
||||||
|
// Single namespace if the root has one namespace and the nest is unbranched.
|
||||||
|
bool isSingleNamespace = true;
|
||||||
|
string[] namespaces = new string[kMaxNamespaceNestCount];
|
||||||
|
foreach (Type type in typeArray) {
|
||||||
|
string[] splittedTypePath = TypeMenuUtility.GetSplittedTypePath(type);
|
||||||
|
if (splittedTypePath.Length <= 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (int k = 0;(splittedTypePath.Length - 1) > k;k++) {
|
||||||
|
string ns = namespaces[k];
|
||||||
|
if (ns == null) {
|
||||||
|
namespaces[k] = splittedTypePath[k];
|
||||||
|
}
|
||||||
|
else if (ns != splittedTypePath[k]) {
|
||||||
|
isSingleNamespace = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add type items.
|
// Add type items.
|
||||||
foreach (Type type in types.OrderByType()) {
|
foreach (Type type in typeArray) {
|
||||||
string[] splittedTypePath = TypeMenuUtility.GetSplittedTypePath(type);
|
string[] splittedTypePath = TypeMenuUtility.GetSplittedTypePath(type);
|
||||||
if (splittedTypePath.Length == 0) {
|
if (splittedTypePath.Length == 0) {
|
||||||
continue;
|
continue;
|
||||||
@@ -42,11 +66,13 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
|
|||||||
AdvancedDropdownItem parent = root;
|
AdvancedDropdownItem parent = root;
|
||||||
|
|
||||||
// Add namespace items.
|
// Add namespace items.
|
||||||
|
if (!isSingleNamespace) {
|
||||||
for (int k = 0;(splittedTypePath.Length - 1) > k;k++) {
|
for (int k = 0;(splittedTypePath.Length - 1) > k;k++) {
|
||||||
AdvancedDropdownItem foundItem = GetItem(parent,splittedTypePath[k]);
|
AdvancedDropdownItem foundItem = GetItem(parent,splittedTypePath[k]);
|
||||||
if (foundItem != null) {
|
if (foundItem != null) {
|
||||||
parent = foundItem;
|
parent = foundItem;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
var newItem = new AdvancedDropdownItem(splittedTypePath[k]) {
|
var newItem = new AdvancedDropdownItem(splittedTypePath[k]) {
|
||||||
id = itemCount++,
|
id = itemCount++,
|
||||||
};
|
};
|
||||||
@@ -54,6 +80,7 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
|
|||||||
parent = newItem;
|
parent = newItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add type item.
|
// Add type item.
|
||||||
var item = new AdvancedTypePopupItem(type,ObjectNames.NicifyVariableName(splittedTypePath[splittedTypePath.Length - 1])) {
|
var item = new AdvancedTypePopupItem(type,ObjectNames.NicifyVariableName(splittedTypePath[splittedTypePath.Length - 1])) {
|
||||||
|
|||||||
+1
-19
@@ -6,36 +6,18 @@ using UnityEditor;
|
|||||||
namespace MackySoft.SerializeReferenceExtensions.Editor {
|
namespace MackySoft.SerializeReferenceExtensions.Editor {
|
||||||
public static class ManagedReferenceUtility {
|
public static class ManagedReferenceUtility {
|
||||||
|
|
||||||
public static Type GetManagedReferenceFieldType (this SerializedProperty property) {
|
|
||||||
if (property.propertyType != SerializedPropertyType.ManagedReference) {
|
|
||||||
throw SerializedPropertyTypeMustBeManagedReference(nameof(property));
|
|
||||||
}
|
|
||||||
return GetType(property.managedReferenceFieldTypename);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Type GetManagedReferenceType (this SerializedProperty property) {
|
|
||||||
if (property.propertyType != SerializedPropertyType.ManagedReference) {
|
|
||||||
throw SerializedPropertyTypeMustBeManagedReference(nameof(property));
|
|
||||||
}
|
|
||||||
return GetType(property.managedReferenceFullTypename);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static object SetManagedReference (this SerializedProperty property,Type type) {
|
public static object SetManagedReference (this SerializedProperty property,Type type) {
|
||||||
object obj = (type != null) ? Activator.CreateInstance(type) : null;
|
object obj = (type != null) ? Activator.CreateInstance(type) : null;
|
||||||
property.managedReferenceValue = obj;
|
property.managedReferenceValue = obj;
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Type GetType (string typeName) {
|
public static Type GetType (string typeName) {
|
||||||
int splitIndex = typeName.IndexOf(' ');
|
int splitIndex = typeName.IndexOf(' ');
|
||||||
var assembly = Assembly.Load(typeName.Substring(0,splitIndex));
|
var assembly = Assembly.Load(typeName.Substring(0,splitIndex));
|
||||||
return assembly.GetType(typeName.Substring(splitIndex + 1));
|
return assembly.GetType(typeName.Substring(splitIndex + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
static ArgumentException SerializedPropertyTypeMustBeManagedReference (string paramName) {
|
|
||||||
return new ArgumentException("The serialized property type must be SerializedPropertyType.ManagedReference.",paramName);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
+14
-9
@@ -34,8 +34,6 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
|
|||||||
EditorGUI.BeginProperty(position,label,property);
|
EditorGUI.BeginProperty(position,label,property);
|
||||||
|
|
||||||
if (property.propertyType == SerializedPropertyType.ManagedReference) {
|
if (property.propertyType == SerializedPropertyType.ManagedReference) {
|
||||||
TypePopupCache popup = GetTypePopup(property);
|
|
||||||
|
|
||||||
// Draw the subclass selector popup.
|
// Draw the subclass selector popup.
|
||||||
Rect popupPosition = new Rect(position);
|
Rect popupPosition = new Rect(position);
|
||||||
popupPosition.width -= EditorGUIUtility.labelWidth;
|
popupPosition.width -= EditorGUIUtility.labelWidth;
|
||||||
@@ -43,6 +41,7 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
|
|||||||
popupPosition.height = EditorGUIUtility.singleLineHeight;
|
popupPosition.height = EditorGUIUtility.singleLineHeight;
|
||||||
|
|
||||||
if (EditorGUI.DropdownButton(popupPosition,GetTypeName(property),FocusType.Keyboard)) {
|
if (EditorGUI.DropdownButton(popupPosition,GetTypeName(property),FocusType.Keyboard)) {
|
||||||
|
TypePopupCache popup = GetTypePopup(property);
|
||||||
m_TargetProperty = property;
|
m_TargetProperty = property;
|
||||||
popup.TypePopup.Show(popupPosition);
|
popup.TypePopup.Show(popupPosition);
|
||||||
}
|
}
|
||||||
@@ -57,10 +56,13 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TypePopupCache GetTypePopup (SerializedProperty property) {
|
TypePopupCache GetTypePopup (SerializedProperty property) {
|
||||||
if (!m_TypePopups.TryGetValue(property.managedReferenceFieldTypename,out TypePopupCache result)) {
|
// Cache this string. This property internally call Assembly.GetName, which result in a large allocation.
|
||||||
|
string managedReferenceFieldTypename = property.managedReferenceFieldTypename;
|
||||||
|
|
||||||
|
if (!m_TypePopups.TryGetValue(managedReferenceFieldTypename,out TypePopupCache result)) {
|
||||||
var state = new AdvancedDropdownState();
|
var state = new AdvancedDropdownState();
|
||||||
|
|
||||||
Type baseType = property.GetManagedReferenceFieldType();
|
Type baseType = ManagedReferenceUtility.GetType(managedReferenceFieldTypename);
|
||||||
var popup = new AdvancedTypePopup(
|
var popup = new AdvancedTypePopup(
|
||||||
TypeCache.GetTypesDerivedFrom(baseType).Where(p =>
|
TypeCache.GetTypesDerivedFrom(baseType).Where(p =>
|
||||||
(p.IsPublic || p.IsNestedPublic) &&
|
(p.IsPublic || p.IsNestedPublic) &&
|
||||||
@@ -79,20 +81,23 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
|
|||||||
m_TargetProperty.serializedObject.ApplyModifiedProperties();
|
m_TargetProperty.serializedObject.ApplyModifiedProperties();
|
||||||
};
|
};
|
||||||
|
|
||||||
m_TypePopups.Add(property.managedReferenceFieldTypename,new TypePopupCache(popup,state));
|
m_TypePopups.Add(managedReferenceFieldTypename,new TypePopupCache(popup,state));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
GUIContent GetTypeName (SerializedProperty property) {
|
GUIContent GetTypeName (SerializedProperty property) {
|
||||||
if (string.IsNullOrEmpty(property.managedReferenceFullTypename)) {
|
// Cache this string.
|
||||||
|
string managedReferenceFullTypename = property.managedReferenceFullTypename;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(managedReferenceFullTypename)) {
|
||||||
return k_NullDisplayName;
|
return k_NullDisplayName;
|
||||||
}
|
}
|
||||||
if (m_TypeNameCaches.TryGetValue(property.managedReferenceFullTypename,out GUIContent cachedTypeName)) {
|
if (m_TypeNameCaches.TryGetValue(managedReferenceFullTypename,out GUIContent cachedTypeName)) {
|
||||||
return cachedTypeName;
|
return cachedTypeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
Type type = property.GetManagedReferenceType();
|
Type type = ManagedReferenceUtility.GetType(managedReferenceFullTypename);
|
||||||
string typeName = null;
|
string typeName = null;
|
||||||
|
|
||||||
AddTypeMenuAttribute typeMenu = TypeMenuUtility.GetAttribute(type);
|
AddTypeMenuAttribute typeMenu = TypeMenuUtility.GetAttribute(type);
|
||||||
@@ -108,7 +113,7 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GUIContent result = new GUIContent(typeName);
|
GUIContent result = new GUIContent(typeName);
|
||||||
m_TypeNameCaches.Add(property.managedReferenceFullTypename,result);
|
m_TypeNameCaches.Add(managedReferenceFullTypename,result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9a6c0659b60e6c44f998f2d392bb5af6
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
using UnityEditor;
|
||||||
|
|
||||||
|
namespace MackySoft.SerializeReferenceExtensions.Example.Editor {
|
||||||
|
|
||||||
|
// Enabling the custom editor slowdown rendering performance.
|
||||||
|
//[CustomEditor(typeof(Example))]
|
||||||
|
public class ExampleEditor : UnityEditor.Editor {
|
||||||
|
|
||||||
|
public override void OnInspectorGUI () {
|
||||||
|
base.OnInspectorGUI();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: cfc194a2f8ebd084b9a5e0be5ec30589
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "com.mackysoft.serializereference-extensions",
|
"name": "com.mackysoft.serializereference-extensions",
|
||||||
"displayName": "SerializeReference Extensions",
|
"displayName": "SerializeReference Extensions",
|
||||||
"version": "1.1.2",
|
"version": "1.1.3",
|
||||||
"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" ],
|
||||||
|
|||||||
Reference in New Issue
Block a user