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
This commit is contained in:
Makihiro 2022-03-05 11:51:21 +09:00 committed by GitHub
commit 315cf4df85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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,16 +66,19 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
AdvancedDropdownItem parent = root; AdvancedDropdownItem parent = root;
// Add namespace items. // Add namespace items.
for (int k = 0;(splittedTypePath.Length - 1) > k;k++) { if (!isSingleNamespace) {
AdvancedDropdownItem foundItem = GetItem(parent,splittedTypePath[k]); for (int k = 0;(splittedTypePath.Length - 1) > k;k++) {
if (foundItem != null) { AdvancedDropdownItem foundItem = GetItem(parent,splittedTypePath[k]);
parent = foundItem; if (foundItem != null) {
} else { parent = foundItem;
var newItem = new AdvancedDropdownItem(splittedTypePath[k]) { }
id = itemCount++, else {
}; var newItem = new AdvancedDropdownItem(splittedTypePath[k]) {
parent.AddChild(newItem); id = itemCount++,
parent = newItem; };
parent.AddChild(newItem);
parent = newItem;
}
} }
} }