public void Init( IDraggablePanelAdapter adapter, int nNumGridItem, int nRealGridItem ) { if( gridItemPrefab == null || adapter == null ) { Debug.LogError( "UIGridEx::Init() - Can't initialize UIGridEx because gridItemPrefab or panelAdapter is not set" ); return; } currentPos = prevPos = 0; numGridItem = nNumGridItem; realNumGridItem = nRealGridItem; panelAdapter = adapter; startSlotID = 0; endSlotID = realNumGridItem - 1; int nCurrNumChildItem = gridItemList.Count; int nNumWould = nRealGridItem - nCurrNumChildItem; // no create or delete if( nNumWould == 0 ) { // fill slot map int nCnt = 0; gridItemSlotMap.Clear(); foreach( GameObject gridItemObj in gridItemList ) { gridItemSlotMap.Add( nCnt, gridItemObj ); panelAdapter.OnNotifyFill( nCnt++, gridItemObj ); } Reposition(); return; } // create else if( nNumWould > 0 ) { for( int i=0; i<nNumWould; i++ ) { GameObject obj = Instantiate( gridItemPrefab ) as GameObject; if( obj == null ) { Debug.LogError( "UIGridEx::Init() - Can't initialize UIGridEx because gridItemPrefab is not instantiated" ); return; } obj.transform.parent = gameObject.transform; obj.layer = gameObject.layer; obj.transform.localPosition = Vector3.zero; obj.transform.localScale = Vector3.one; obj.transform.rotation = Quaternion.identity; // 이름 초기화 이거 같은게 있으면 트랜스폼의 GetChild()가 안먹는다??? 확인!!!! obj.name = (nCurrNumChildItem + i).ToString( "0000" ); gridItemList.Add( obj ); } // fill slot map int nCnt = 0; gridItemSlotMap.Clear(); foreach( GameObject gridItemObj in gridItemList ) { gridItemSlotMap.Add( nCnt, gridItemObj ); panelAdapter.OnNotifyFill( nCnt++, gridItemObj ); } } // delete else { List<GameObject> removeObjList = new List<GameObject>(); for( int i=0; i<-nNumWould; i++ ) { GameObject currentObj = gridItemList[ nCurrNumChildItem - 1 - i ]; removeObjList.Add( currentObj ); } foreach( GameObject obj in removeObjList ) { gridItemList.Remove( obj ); GameObject.Destroy( obj ); } // fill slot map int nCnt = 0; gridItemSlotMap.Clear(); foreach( GameObject gridItemObj in gridItemList ) { gridItemSlotMap.Add( nCnt, gridItemObj ); panelAdapter.OnNotifyFill( nCnt++, gridItemObj ); } } Reposition(); isFilled = true; }
// addition to ngui for uniform draggable scroll panel /// <summary> /// init cs draggable panel /// </summary> public void Init( IDraggablePanelAdapter adapter, int nNumScrollItem, int nRealNumScrollItem ) { if( adapter == null || mPanel == null || mGrid == null ) { Debug.LogError( "UIDraggablePanelEx::Init() - Invalid Parameter or not initialized" ); return; } //dragPanelAdapter = adapter; numScrollItem = nNumScrollItem; realNumScrollItem = nRealNumScrollItem; if( numScrollItem <= realNumScrollItem ) { realNumScrollItem = numScrollItem; bNeedRearrange = false; } mGrid.Init( adapter, numScrollItem, realNumScrollItem ); // scroll to origin ResetPosition(); // dummy calc float fDummy = bounds.min.x; horizontalMinX = mRealBounds.min.x; verticalMaxY = mRealBounds.max.y; }