private System.Collections.IEnumerator start() { /* XXX: This must be delayed, otherwise unity ignores the changes to * the UI ¯\_(ツ)_/¯ */ yield return(null); int count = this.lastIdx - this.curIdx; float size = 1.0f / (float)count; this.view = this.gameObject.GetComponentInChildren <View>(); const Axis ax = Axis.Vertical; this.viewWidth = this.view.content.rect.width; this.viewHeight = elementDist + count * (elementHeight + elementDist); this.view.content.SetSizeWithCurrentAnchors(ax, this.viewHeight); this.view.verticalScrollbar.size = size; yield return(this.startLoadLevel()); }
static private GO spawnCopy(GO template, Transform parent, float x, float y, float w, float h) { GO newGo; UiTransform rect; const Axis hor = Axis.Horizontal; const Axis vert = Axis.Vertical; newGo = Obj.Instantiate(template, parent.position, Quat.identity, parent); rect = newGo.AddComponent <UiTransform>(); rect.pivot = new Vec2(0.0f, 1.0f); rect.anchorMin = new Vec2(0.0f, 1.0f); rect.anchorMax = new Vec2(0.0f, 1.0f); rect.anchoredPosition = new Vec2(x, -y); rect.SetSizeWithCurrentAnchors(vert, h); rect.SetSizeWithCurrentAnchors(hor, w); return(newGo); }
private void setupUi() { Transform t; UiTransform parent; GO template; GO thumbTemplate; float rowOffset; int w, h; const Axis vert = Axis.Vertical; parent = this.Content.parent.GetComponent <UiTransform>(); w = (int)this.Content.rect.width; this.numCols = LevelSelectMenu.getNumSlots(w, this.ThumbBorder, this.ThumbSpacing, this.ThumbSize); this.numRows = this.numItems / this.numCols; if (this.numItems % this.numCols != 0) { this.numRows++; } h = this.numRows * (this.ThumbSpacing + this.ThumbSize); h += this.ThumbBorder * 2 - this.ThumbSpacing; this.Content.SetSizeWithCurrentAnchors(vert, h); this.rowSelector = new Image[this.numRows]; template = new GO($"RowSelector"); this.thumbnails = new RawImage[this.numItems]; thumbTemplate = new GO($"Thumbnail"); t = this.RowView.transform; w = (int)(this.RowView.rect.width / 2); h = (int)(this.RowView.rect.height / this.numRows); rowOffset = h * 0.05f; for (int y = 0; y < this.numRows; y++) { GO newGo; Image img; float _x = w * 0.25f; float _y = (float)(y * h) - rowOffset; float _w = w * 0.75f; float _h = h * 0.9f; newGo = LevelSelectMenu.spawnCopy(template, t, _x, _y, _w, _h); img = newGo.AddComponent <Image>(); img.color = this.OtherRowsColor; this.rowSelector[y] = img; for (int x = 0; x < this.numCols; x++) { RawImage rimg; Transform _t = this.Content.transform; int i = x + y * this.numCols; if (i > this.numItems) { break; } _x = this.ThumbBorder + x * (this.ThumbSize + this.ThumbSpacing); _y = this.ThumbBorder + y * (this.ThumbSize + this.ThumbSpacing); _w = this.ThumbSize; _h = this.ThumbSize; newGo = LevelSelectMenu.spawnCopy(thumbTemplate, _t, _x, _y, _w, _h); rimg = newGo.AddComponent <RawImage>(); rimg.texture = LevelSelectMenu.cache[i].tex; rimg.material = LevelSelectMenu.cache[i].mat; this.thumbnails[i] = rimg; } } GO.Destroy(template); GO.Destroy(thumbTemplate); }