public void AddItem() { string name = "Item" + (itemIndexCount++); GameObject item = new GameObject(name); Picker.PickerItem pickerItem = item.AddComponent <Picker.PickerItem>(); RectTransform rect = pickerItem.GetComponent <RectTransform>(); rect.sizeDelta = scrollRect.layout == RectTransform.Axis.Vertical ? verticalItemSize : horizontalItemSize; Text text = item.AddComponent <Text>(); text.font = itemTextFont; text.fontSize = 18; text.resizeTextForBestFit = true; text.color = Color.black; text.fontStyle = FontStyle.Bold; text.alignment = TextAnchor.MiddleCenter; text.text = name; item.transform.SetParent(layoutGroup.gameObject.transform); item.transform.localPosition = Vector3.zero; item.transform.localRotation = Quaternion.identity; item.transform.localScale = Vector3.one; scrollRect.UpdateLayout(); scrollRect.ScrollTo(scrollRect.lastItemPosition, true); }
protected void ScrollToSelf() { PickerLayoutGroup layout = GetComponentInParent <PickerLayoutGroup>(); if (layout == null) { return; } PickerScrollRect psr = layout.scrollRect; if (psr == null) { return; } psr.ScrollTo(this); }