protected ViewerChangeButton SpawnAndPlaceViewerChangeButton(ViewerScreen associatedScreen, int numberBegin, int numberEnd, int offsetMplier) { ViewerChangeButton vcb = (Instantiate(_viewerChangeButtonPrefab.gameObject)).GetComponent <ViewerChangeButton>(); vcb.Screen = associatedScreen; vcb.ViewerRef = this; vcb.GetComponent <RectTransform>().SetParent(GetComponent <Transform>(), false); float offset = offsetMplier * vcb.GetComponent <RectTransform>().sizeDelta.x; Vector3 currentPos = vcb.GetComponent <RectTransform>().anchoredPosition; currentPos.x -= offset; vcb.GetComponent <RectTransform>().anchoredPosition = currentPos; Text txt = vcb.GetComponentInChildren <Text>(); txt.text = string.Format("{0} - {1}", numberBegin, numberEnd); vcb.AllButtons = _changeButtons; return(vcb); }
// Use this for initialization void Start() { _fullscreenImage.Initialize(_resources); _fullscreenImage.gameObject.SetActive(false); int maxImagesPerScreen = ViewerScreen.MAX_BUTTONS_PER_LINE * ViewerScreen.MAX_BUTTON_LINES; ViewerScreen vs = SpawnAndPlaceViewerScreen(); int totalImgsCount = 0; int wideImgCounter = 0; List <ImageMiniaturePair> tempImages = new List <ImageMiniaturePair>(); for (int i = 0; i < _resources.Count; ++i) { tempImages.Add(_resources[i]); ++totalImgsCount; if (_resources[i].IsWide) { // it is wide miniature ++wideImgCounter; } if (wideImgCounter >= 2) { wideImgCounter = 0; ++totalImgsCount; } if (totalImgsCount >= maxImagesPerScreen) { wideImgCounter = 0; totalImgsCount = 0; vs.Initialize(tempImages, _fullscreenImage); tempImages.Clear(); _viewerScreens.Add(vs); vs = SpawnAndPlaceViewerScreen(); } } if (totalImgsCount <= maxImagesPerScreen) { _viewerScreens.Add(vs); vs.Initialize(tempImages, _fullscreenImage); } if (_viewerScreens.Count > 1) { for (int i = 1; i < _viewerScreens.Count; ++i) { _viewerScreens[i].gameObject.SetActive(false); } } // create button for each viewer screen for (int i = 0; i < _viewerScreens.Count; ++i) { int offset = _viewerScreens.Count - i - 1; int numberFirst = 0, numberLast = 0; if (i > 0) { for (int j = i - 1; j >= 0; --j) { numberFirst += _viewerScreens[j].GetButtonCount(); } ++numberFirst; } else { numberFirst = 1; } numberLast = numberFirst + _viewerScreens[i].GetButtonCount() - 1; ViewerChangeButton vcb = SpawnAndPlaceViewerChangeButton(_viewerScreens[i], numberFirst, numberLast, offset); vcb.ColorCurrent = _color; _changeButtons.Add(vcb); } _changeButtons[0].MakeCurrent(); }