/// <summary> /// Changes the depth of a single child within the list /// </summary> /// <param name="depthList"></param> /// <param name="child"></param> /// <param name="depth"></param> /// <param name="makeRoom"></param> private static void SetDepth(List<DisplayListMember> depthList, DisplayListMember child, int depth, bool makeRoom) { //Debug.Log("Setting depth: " + depth + " [" + child + "]"); child.Depth = depth; // remove depthList.Remove(child); var index = depthList.FindIndex(delegate(DisplayListMember displayListMember) { return displayListMember.Depth >= depth; }); if (index == -1) // not found, meaning all depths are lower than the supplied one index = depthList.Count; // insert at index depthList.Insert(index, child); var len = depthList.Count; // fix other depths // say depth = 1 // and that we have depths [0, 0, 1, 1, 1, 2, 6, 7] and inserting into the 3rd place (between 0 and 1) // ... [0, 0, *1, 1, 1, 1, 2, 6, 7] ... // we have to get [0, 0, *1, 2, 2, 2, 3, 6, 7] - note that some values are shifted up, but the values of 6, 7 are not because there's no need to //_prevDepth = depth; if (makeRoom) { // needs room? if (depthList.Count == index + 1 || depthList[index + 1].Depth > depth) return; // this is the last item or the next item has a greater depth for (int i = index + 1; i < len; i++) // from 3rd place to the end { depthList[index].Depth += 1; //var item2 = depthList[index]; // 2 //if (item2.Depth != _prevDepth) // _prevDepth = item2.Depth; // _prevDepth = 1 //if (item2.Depth == _prevDepth) // 1 == 1 //{ // item2.Depth = _prevDepth + 1; // item2.Depth = 2 //} } } }