public void SortGroups() { for (int i = list.Length - 1; i >= 0; i--) { Generator grp = list[i]; if (!(grp is Group)) { continue; } for (int g = 0; g < list.Length; g++) { Generator grp2 = list[g]; if (!(grp2 is Group)) { continue; } if (grp2.layout.field.Contains(grp.layout.field)) { ArrayTools.Switch(list, grp, grp2); } } } }
static public PopupMenu DrawPopup(MenuItem[] items, Vector2 pos, bool closeAllOther = false, bool sort = true) { //sorting items according to their priority if (sort) { for (int i = 0; i < items.Length; i++) { for (int j = 0; j < items.Length; j++) { if (items[i].priority < items[j].priority) { ArrayTools.Switch(items, items[i], items[j]); } } } for (int i = 0; i < items.Length; i++) { items[i].SortItems(); } } PopupMenu popupWindow = new PopupMenu(); popupWindow.items = items; PopupWindow.Show(new Rect(pos.x, pos.y, 0, 0), popupWindow); return(popupWindow); }
public void SortItems() { if (subItems == null) { return; } for (int i = 0; i < subItems.Length; i++) { for (int j = 0; j < subItems.Length; j++) { if (subItems[i].priority < subItems[j].priority) { ArrayTools.Switch(subItems, subItems[i], subItems[j]); } } } for (int i = 0; i < subItems.Length; i++) { subItems[i].SortItems(); } }
public void SortItems() { if (subItems == null) { return; } for (int i = 0; i < subItems.Length; i++) { for (int j = 0; j < subItems.Length; j++) { if (subItems[i].priority == subItems[j].priority) //sorting by name if priority equal { for (int c = 0; c < Mathf.Min(subItems[i].name.Length, subItems[j].name.Length); c++) { if ((int)(subItems[i].name[c]) != (int)(subItems[j].name[c])) { if ((int)(subItems[i].name[c]) < (int)(subItems[j].name[c])) { ArrayTools.Switch(subItems, subItems[i], subItems[j]); } break; } } } if (subItems[i].priority < subItems[j].priority) { ArrayTools.Switch(subItems, subItems[i], subItems[j]); } } } for (int i = 0; i < subItems.Length; i++) { subItems[i].SortItems(); } }