0.2.0: Added drag and drop between entries in list and fixed some bugs

This commit is contained in:
Anders Ejlersen 2021-02-14 13:01:59 +01:00
parent dea60c6e4a
commit 1e1736f94a
8 changed files with 150 additions and 38 deletions

View file

@ -59,6 +59,14 @@ namespace Game.NavigationTool.Editor
}
}
}
for (var i = 0; i < entries.Count; i++)
{
Entry e = entries[i];
if (e.indentLevel != 0 && e.parent == null)
e.indentLevel = 0;
}
}
public void Add(string guid, Entry toParent = null)
@ -82,6 +90,9 @@ namespace Game.NavigationTool.Editor
entries.Add(e);
if (toParent != null && toParent.isAsset)
toParent = toParent.parent;
if (toParent != null)
{
e.parent = toParent;
@ -137,7 +148,7 @@ namespace Game.NavigationTool.Editor
if (!e.isAsset)
{
for (var i = 0; i < e.children.Count; i++)
for (int i = e.children.Count - 1; i >= 0; i--)
{
InternalRemove(e.children[i].entry);
}
@ -191,9 +202,23 @@ namespace Game.NavigationTool.Editor
string path = AssetDatabase.GUIDToAssetPath(entry.assetGuid);
return AssetDatabase.LoadMainAssetAtPath(path);
}
private void Sort()
{
entries.Sort((e0, e1) =>
{
int compare = e0.isAsset.CompareTo(e1.isAsset);
if (compare == 0)
compare = string.Compare(e0.lowerName, e1.lowerName, StringComparison.Ordinal);
return compare;
});
}
public void Save()
{
Sort();
string json = EditorJsonUtility.ToJson(this, false);
EditorPrefs.SetString(PREF_ID, json);
}
@ -254,7 +279,7 @@ namespace Game.NavigationTool.Editor
string path = AssetDatabase.GUIDToAssetPath(assetGuid);
name = Path.GetFileNameWithoutExtension(path);
lowerName = name.ToLower();
valid = !string.IsNullOrEmpty(path);
valid = AssetDatabase.LoadMainAssetAtPath(path) != null;
content = new GUIContent(name, FavoritesGUIUtility.GetIcon(path), path);
}
else
@ -267,6 +292,15 @@ namespace Game.NavigationTool.Editor
public void AddChild(Entry entry)
{
children.Add(new Child(entry));
children.Sort((c0, c1) =>
{
int compare = c0.entry.isAsset.CompareTo(c1.entry.isAsset);
if (compare == 0)
compare = string.Compare(c0.entry.lowerName, c1.entry.lowerName, StringComparison.Ordinal);
return compare;
});
}
public void RemoveChild(Entry entry)