ScrollingDropDown addSublist() { int index = refresh ? refreshOptionIndex - 1 : options.Count - 1; ScrollingDropDown dropDown = null; if (refresh) { if (index < options.Count) { dropDown = subLists[index]; } } if (dropDown == null) { dropDown = Instantiate <ScrollingDropDown>(childListPrefab); dropDown.Parent = this; RectTransform r = dropDown.GetComponent <RectTransform>(); r.SetParent(options[index].transform, false); r.anchorMin = rect.pivot.y * Vector2.up + Vector2.right; r.anchorMax = r.anchorMin + Vector2.right; r.pivot = rect.pivot; r.anchoredPosition = Vector2.zero; r.GetComponent <Canvas>().sortingOrder++; } subLists[index] = dropDown; return(dropDown); }
public void AddOption(string name, IList <string> subOptions, System.Action <int> onSelected, System.Action <int> onDeleted = null) { if (doCache) { cachedData.Add(() => { AddOption(name, subOptions, onSelected, onDeleted); }); return; } DropDownOption option = addOption(name); option.SublistArrow.enabled = true; ScrollingDropDown subList = addSublist(); option.Delete.gameObject.SetActive(false); option.OnHover = () => { if (subList.IsExpanded) { //subList.Contract(); } else { subList.Expand(); } }; if (refresh) { subList.BeginOptions(); } for (int i = 0; i < subOptions.Count; i++) { string subOption = subOptions[i]; int index = i; if (onDeleted == null || subOption[0] == '[') { subList.AddOption(subOption, (x) => { Contract(); onSelected(index); }); } else { subList.AddOption(subOption, (x) => { Contract(); onSelected(index); }, (x) => { onDeleted(index); }); } } if (refresh) { subList.EndOptions(); } }