protected virtual void OnItemInsert(int position, EZData.Context item) { GameObject itemObject = null; if (_itemTemplate != null && _cache.Count < MaxItemCount) { itemObject = _itemTemplate.Instantiate(item, position, _groupNumber); _cache.Insert(position, itemObject); itemObject.transform.SetParent(transform); itemObject.transform.localScale = Vector3.one; itemObject.transform.localPosition = Vector3.back; //TODO: IMPORTANT // retinaProUtil.sharedInstance.refreshVisible(itemObject); } else { if (position < transform.childCount) { itemObject = transform.GetChild(position).gameObject; var itemData = itemObject.GetComponent <NguiItemDataContext>(); if (itemData != null) { itemData.SetContext(item); itemData.SetIndex(position); } } } if (itemObject != null) { foreach (var dragObject in itemObject.GetComponentsInChildren <UIDragObject>()) { if (dragObject.target == null) { dragObject.target = transform; } } foreach (var dragObject in itemObject.GetComponents <UIDragObject>()) { if (dragObject.target == null) { dragObject.target = transform; } } var parentVisibility = NguiUtils.GetComponentInParentsAs <IVisibilityBinding>(gameObject); foreach (var visibility in NguiUtils.GetComponentsInChildrenAs <IVisibilityBinding>(itemObject)) { visibility.InvalidateParent(); } var visible = parentVisibility == null ? true : parentVisibility.Visible; NguiUtils.SetVisible(itemObject, visible); RepositionContent(); } }
protected virtual void OnItemInsert(int position, EZData.Context item) { GameObject itemObject = null; if (_itemTemplate != null) { itemObject = _itemTemplate.Instantiate(item, position); itemObject.name = string.Format("{0}", position); for (var i = 0; i < transform.childCount; ++i) { var child = transform.GetChild(i).gameObject; int childNumber; if (int.TryParse(child.name, out childNumber) && childNumber >= position) { child.name = string.Format("{0}", childNumber + 1); } } itemObject.transform.parent = gameObject.transform; itemObject.transform.localScale = Vector3.one; itemObject.transform.localPosition = Vector3.back; } else { if (position < transform.childCount) { itemObject = transform.GetChild(position).gameObject; var itemData = itemObject.GetComponent <NguiItemDataContext>(); if (itemData != null) { itemData.SetContext(item); itemData.SetIndex(position); } } } if (itemObject != null) { foreach (var dragObject in itemObject.GetComponentsInChildren <UIDragObject>()) { if (dragObject.target == null) { dragObject.target = gameObject.transform; } } foreach (var dragObject in itemObject.GetComponents <UIDragObject>()) { if (dragObject.target == null) { dragObject.target = gameObject.transform; } } var parentVisibility = NguiUtils.GetComponentInParentsAs <IVisibilityBinding>(gameObject); foreach (var visibility in NguiUtils.GetComponentsInChildrenAs <IVisibilityBinding>(itemObject)) { visibility.InvalidateParent(); } var visible = parentVisibility == null ? true : parentVisibility.Visible; NguiUtils.SetVisible(itemObject, visible); RepositionContent(); } }