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); }
public void RegisterItem(PickerItem item) { if (Application.isPlaying) { Transform key = item.transform; if (!m_ChildItemTable.ContainsKey(key)) { m_ChildItemTable[key] = new ItemComponent() { item = item, rectTransform = item.GetComponent <RectTransform>() }; } } }
static public void AddItem(GameObject parent, bool zoom, bool horizontal, int index) { string name = "Item" + index; GameObject item = new GameObject(name); GameObjectUtility.SetParentAndAlign(item, parent); PickerItem pickerItem = !zoom?item.AddComponent <PickerItem>() : item.AddComponent <ZoomPickerItem>(); RectTransform rect = pickerItem.GetComponent <RectTransform>(); if (!horizontal) { rect.sizeDelta = new Vector2(70, 20); } else { rect.sizeDelta = new Vector2(15, 70); } Text itemText = AddTextComponent(item, item.name); if (zoom) { GameObject zoomItem = new GameObject("ZoomItem"); GameObjectUtility.SetParentAndAlign(zoomItem, item); AddTextComponent(zoomItem, item.name); RectTransform zoomTransform = zoomItem.GetComponent <RectTransform>(); zoomTransform.sizeDelta = rect.sizeDelta; zoomTransform.localScale = Vector3.one * 1.2f; itemText.color = Color.gray; ((ZoomPickerItem)pickerItem).zoomItem = zoomTransform; } }