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>
|
/// </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,31 @@ 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 +67,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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user