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:
commit
315cf4df85
@ -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,11 +66,13 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
|
||||
AdvancedDropdownItem parent = root;
|
||||
|
||||
// Add namespace items.
|
||||
if (!isSingleNamespace) {
|
||||
for (int k = 0;(splittedTypePath.Length - 1) > k;k++) {
|
||||
AdvancedDropdownItem foundItem = GetItem(parent,splittedTypePath[k]);
|
||||
if (foundItem != null) {
|
||||
parent = foundItem;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
var newItem = new AdvancedDropdownItem(splittedTypePath[k]) {
|
||||
id = itemCount++,
|
||||
};
|
||||
@ -54,6 +80,7 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
|
||||
parent = newItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add type item.
|
||||
var item = new AdvancedTypePopupItem(type,ObjectNames.NicifyVariableName(splittedTypePath[splittedTypePath.Length - 1])) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user