private void RemoveAllItemBuilders() { int fieldCount = ItemBuilderCount; if (itemFieldBuilders != null && ItemBuilderCount > 0) { for (int i = 0; i < fieldCount; i++) { UIFieldBuilder removedFieldBuilder = itemFieldBuilders[i]; if (removedFieldBuilder == null) { continue; } removedFieldBuilder.onEndEdit.RemoveAllListeners(); removedFieldBuilder.onEdit.RemoveAllListeners(); if (i == 0) { removedFieldBuilder.gameObject.SetActive(false); } else { Destroy(removedFieldBuilder.gameObject); } } itemFieldBuilders.RemoveRange(1, fieldCount - 1); SelectionIndex = -1; UpdateScrollBar(); } }
private void SelectClosestItem() { if (ItemBuilderCount > 0) { UIFieldBuilder anotherFieldBuilder = (SelectionIndex < itemFieldBuilders.Count) ? itemFieldBuilders[SelectionIndex] : itemFieldBuilders[SelectionIndex - 1]; ISelectableField anotherSelectableItem = anotherFieldBuilder != null?anotherFieldBuilder.GetComponentInChildren <ISelectableField>(true) : null; if (anotherSelectableItem != null) { anotherSelectableItem.SelectField(); } } else { SelectionIndex = -1; } }
private void RemoveItemBuilderAt(int builderIndex, bool selectAnother) { if (builderIndex == -1 || itemFieldBuilders == null) { return; } int fieldCount = ItemBuilderCount; if (builderIndex < fieldCount) { UIFieldBuilder builderToRemove = itemFieldBuilders[builderIndex]; if (fieldCount > 1) { itemFieldBuilders.RemoveAt(builderIndex); } if (builderToRemove != null) { builderToRemove.onEndEdit.RemoveAllListeners(); builderToRemove.onEdit.RemoveAllListeners(); if (fieldCount == 1) { builderToRemove.gameObject.SetActive(false); } else { Destroy(builderToRemove.gameObject); } } for (int i = 0, iend = fieldCount - 1; i < iend; i++) { itemFieldBuilders[i].UpdateLabelComponent(); } UpdateScrollBar(); if (selectAnother) { SelectClosestItem(); } } }
private void BuildField(UIField f, out float fieldHeight) { fieldHeight = 0f; if (f == null) { return; } string fieldTypeName = f.GetType().Name; int fieldPrefabIndex = Array.IndexOf(FieldTypeNames, fieldTypeName); UIFieldBuilder prefab = fieldPrefabIndex >= 0 && fieldPrefabIndex < fieldPrefabs.Length ? fieldPrefabs[fieldPrefabIndex] : null; if (prefab == null) { return; } UIFieldBuilder fieldInstance = Instantiate(prefab, fieldInstancesRoot); fieldInstance.CurrentField = f; fieldHeight = prefab.GetComponent <RectTransform>().rect.height; fieldInstances.Add(fieldInstance); }
private void Awake() { if (arrayRoot != null) { arrayContainer = arrayRoot.parent.GetComponent <RectTransform>(); UIFieldBuilder[] initInputs = arrayRoot.GetComponentsInChildren <UIFieldBuilder>(true); if (initInputs.Length > 0) { for (int i = 1, iend = initInputs.Length; i < iend; i++) { Destroy(initInputs[i].gameObject); } UIFieldBuilder inputModel = initInputs[0]; itemFieldBuilders = new List <UIFieldBuilder> { inputModel }; inputModel.gameObject.SetActive(false); fieldHeight = inputModel.GetComponent <RectTransform>().rect.height; } minScrollY = arrayRoot.anchoredPosition.y; } if (removeItemButton != null) { accurateRemoveItemButton = removeItemButton.GetComponent <UIAccurateButton>(); removeItemButton.interactable = false; } if (upButton != null) { accurateUpButton = upButton.GetComponent <UIAccurateButton>(); upButton.interactable = false; } if (downButton != null) { accurateDownButton = downButton.GetComponent <UIAccurateButton>(); downButton.interactable = false; } }