public void Initialize(UIWrapGridContent wrapGrid, GameObject childPrefab, int itemCount) { _wasShutdown = false; _itemMapping.Clear(); _wrapGrid = wrapGrid; _wrapGrid.onWrapGridInitialized = WrapGridIntialized; _wrapGrid.onContentRepositionComplete = WrapGridContentPositioned; _wrapGrid.onInitializeItem = InitializeItem; _wrapGrid.ItemCount = itemCount; _wrapGrid.ScrollView.disableDragIfFits = true; _wrapGrid.ScrollView.ResetPosition(); _wrapGrid.onPanelSizeChanged = PanelSizeChanged; _childPrefab = childPrefab; HandleLayout(); }
public void Shutdown() { _wasShutdown = true; if (_wrapGrid != null) { _wrapGrid.onInitializeItem -= InitializeItem; // reset scroll position before clearing everything // this is to ensure the next time this scroll list is used we're back in a good starting state // otherwise the scroll bars might be offset incorrectly _wrapGrid.Scroll(0); List <IScrollListProviderItem> scrollListItems = new List <IScrollListProviderItem>(); // destroy all items we created dynamically for (int i = 0; i < _createdObjects.Count; ++i) { // check to see if this gameobject had a tile prefab presentation on it before calling destroy // so that we can release instantiated bits to the resource cache first _createdObjects[i].GetComponentsInChildren <IScrollListProviderItem>(includeInactive: true, results: scrollListItems); foreach (IScrollListProviderItem listItem in scrollListItems) { listItem.Shutdown(); } scrollListItems.Clear(); NGUITools.Destroy(_createdObjects[i]); } _createdObjects.Clear(); // reset the wrap grid since the children have now changed _wrapGrid.ResetChildren(); _wrapGrid.onPanelSizeChanged -= PanelSizeChanged; _wrapGrid = null; } _childPrefab = null; }