Items are now listed directly in the root when there is only one namespace.
This commit is contained in:
parent
a10a5b90e4
commit
f4cfd057cc
@ -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,31 @@ 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 +67,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user