Compare commits

...

11 Commits

Author SHA1 Message Date
github-actions[bot] 28ce93d8fc feat: Update package.json to 1.1.3 2022-03-28 14:21:42 +00:00
Makihiro 55a071abe9 Merge pull request #7 from mackysoft/fix/subclassselector-drawing-overhead
Improve `SubclassSelectorDrawer` performance
2022-03-28 23:06:54 +09:00
mackysoft 4cdcf995f6 Remove unnecessary namespaces 2022-03-28 23:06:11 +09:00
mackysoft cf8b8e3b17 Create PULL_REQUEST_TEMPLATE.md 2022-03-05 14:22:07 +09:00
mackysoft 9cbd570556 Create Issue templates 2022-03-05 13:59:10 +09:00
Makihiro 315cf4df85 Merge pull request #8 from mackysoft/feature/simple-list
[FEATURE] List the item in the root if namespace is less than or equal to 1
2022-03-05 11:51:21 +09:00
mackysoft d730a1cdb1 Update AdvancedTypePopup.cs 2022-03-05 11:50:53 +09:00
mackysoft f4cfd057cc Items are now listed directly in the root when there is only one namespace. 2022-03-05 11:39:41 +09:00
mackysoft e7a8195f17 Update ExampleEditor.cs 2022-03-05 02:15:38 +09:00
mackysoft 112b5f9457 Add ExamplEditor
Needed to reproduce issue
2022-03-05 02:04:22 +09:00
mackysoft f8b317ba20 Optimize drawing SubclassSelector 2022-03-05 02:00:34 +09:00
12 changed files with 173 additions and 46 deletions
+34
View File
@@ -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
+15
View File
@@ -0,0 +1,15 @@
## Description
<!--
Write a brief description of what you what to do with this PR.
-->
## Changes made
<!--
Itemize the changes.
-->
-
+2 -4
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -52,11 +52,9 @@
<UnityBuildTarget>StandaloneWindows:5</UnityBuildTarget>
<UnityVersion>2020.3.24f1</UnityVersion>
</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>
<Compile Include="Assets\PackageTools\Editor\UnityPackageExporter.cs" />
<Compile Include="Assets\MackySoft\MackySoft.SerializeReferenceExtensions\Example\ExampleAssets\Scripts\Editor\ExampleEditor.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="UnityEngine">
@@ -23,6 +23,8 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
/// </summary>
public class AdvancedTypePopup : AdvancedDropdown {
const int kMaxNamespaceNestCount = 16;
public static void AddTo (AdvancedDropdownItem root,IEnumerable<Type> types) {
int itemCount = 0;
@@ -32,8 +34,30 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
};
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.
foreach (Type type in types.OrderByType()) {
foreach (Type type in typeArray) {
string[] splittedTypePath = TypeMenuUtility.GetSplittedTypePath(type);
if (splittedTypePath.Length == 0) {
continue;
@@ -42,16 +66,19 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
AdvancedDropdownItem parent = root;
// Add namespace items.
for (int k = 0;(splittedTypePath.Length - 1) > k;k++) {
AdvancedDropdownItem foundItem = GetItem(parent,splittedTypePath[k]);
if (foundItem != null) {
parent = foundItem;
} else {
var newItem = new AdvancedDropdownItem(splittedTypePath[k]) {
id = itemCount++,
};
parent.AddChild(newItem);
parent = newItem;
if (!isSingleNamespace) {
for (int k = 0;(splittedTypePath.Length - 1) > k;k++) {
AdvancedDropdownItem foundItem = GetItem(parent,splittedTypePath[k]);
if (foundItem != null) {
parent = foundItem;
}
else {
var newItem = new AdvancedDropdownItem(splittedTypePath[k]) {
id = itemCount++,
};
parent.AddChild(newItem);
parent = newItem;
}
}
}
@@ -6,36 +6,18 @@ using UnityEditor;
namespace MackySoft.SerializeReferenceExtensions.Editor {
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) {
object obj = (type != null) ? Activator.CreateInstance(type) : null;
property.managedReferenceValue = obj;
return obj;
}
static Type GetType (string typeName) {
public static Type GetType (string typeName) {
int splitIndex = typeName.IndexOf(' ');
var assembly = Assembly.Load(typeName.Substring(0,splitIndex));
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
@@ -29,13 +29,11 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
readonly Dictionary<string,GUIContent> m_TypeNameCaches = new Dictionary<string,GUIContent>();
SerializedProperty m_TargetProperty;
public override void OnGUI (Rect position,SerializedProperty property,GUIContent label) {
EditorGUI.BeginProperty(position,label,property);
if (property.propertyType == SerializedPropertyType.ManagedReference) {
TypePopupCache popup = GetTypePopup(property);
// Draw the subclass selector popup.
Rect popupPosition = new Rect(position);
popupPosition.width -= EditorGUIUtility.labelWidth;
@@ -43,6 +41,7 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
popupPosition.height = EditorGUIUtility.singleLineHeight;
if (EditorGUI.DropdownButton(popupPosition,GetTypeName(property),FocusType.Keyboard)) {
TypePopupCache popup = GetTypePopup(property);
m_TargetProperty = property;
popup.TypePopup.Show(popupPosition);
}
@@ -57,10 +56,13 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
}
TypePopupCache GetTypePopup (SerializedProperty property) {
if (!m_TypePopups.TryGetValue(property.managedReferenceFieldTypename,out TypePopupCache result)) {
var state = new AdvancedDropdownState();
// Cache this string. This property internally call Assembly.GetName, which result in a large allocation.
string managedReferenceFieldTypename = property.managedReferenceFieldTypename;
Type baseType = property.GetManagedReferenceFieldType();
if (!m_TypePopups.TryGetValue(managedReferenceFieldTypename,out TypePopupCache result)) {
var state = new AdvancedDropdownState();
Type baseType = ManagedReferenceUtility.GetType(managedReferenceFieldTypename);
var popup = new AdvancedTypePopup(
TypeCache.GetTypesDerivedFrom(baseType).Where(p =>
(p.IsPublic || p.IsNestedPublic) &&
@@ -79,20 +81,23 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
m_TargetProperty.serializedObject.ApplyModifiedProperties();
};
m_TypePopups.Add(property.managedReferenceFieldTypename,new TypePopupCache(popup,state));
m_TypePopups.Add(managedReferenceFieldTypename,new TypePopupCache(popup,state));
}
return result;
}
GUIContent GetTypeName (SerializedProperty property) {
if (string.IsNullOrEmpty(property.managedReferenceFullTypename)) {
// Cache this string.
string managedReferenceFullTypename = property.managedReferenceFullTypename;
if (string.IsNullOrEmpty(managedReferenceFullTypename)) {
return k_NullDisplayName;
}
if (m_TypeNameCaches.TryGetValue(property.managedReferenceFullTypename,out GUIContent cachedTypeName)) {
if (m_TypeNameCaches.TryGetValue(managedReferenceFullTypename,out GUIContent cachedTypeName)) {
return cachedTypeName;
}
Type type = property.GetManagedReferenceType();
Type type = ManagedReferenceUtility.GetType(managedReferenceFullTypename);
string typeName = null;
AddTypeMenuAttribute typeMenu = TypeMenuUtility.GetAttribute(type);
@@ -108,7 +113,7 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
}
GUIContent result = new GUIContent(typeName);
m_TypeNameCaches.Add(property.managedReferenceFullTypename,result);
m_TypeNameCaches.Add(managedReferenceFullTypename,result);
return result;
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9a6c0659b60e6c44f998f2d392bb5af6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -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();
}
}
}
@@ -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",
"displayName": "SerializeReference Extensions",
"version": "1.1.2",
"version": "1.1.3",
"unity": "2019.4",
"description": "Provide popup to specify the type of the field serialized by the [SerializeReference] attribute in the inspector.",
"keywords": [ "SerializeReference", "Editor" ],