protected override void UpdateView() { Transform spritesContainer = null; if (transform.childCount == 0) { NGUITools.AddChild(gameObject); } spritesContainer = transform.GetChild(0); spritesContainer.name = "SpritesContainer"; // default left align int currentHorDock = 0; int currentTotalWidth = 0; int spriteHeight = 0; int spriteAddIdx = 0; for (int i = 0; i < content.Length; i++) { if (_charSpriteDic.ContainsKey(content[i])) { UI2DSprite uiSprite = AddSprite(spritesContainer, _charSpriteDic[content[i]], currentHorDock, spriteAddIdx++); spriteHeight = Math.Max(spriteHeight, uiSprite.height); currentHorDock += (uiSprite.width + padding); } } if (Application.isPlaying) { FUtil.RemoveAllChildren(spritesContainer.gameObject, false, spriteAddIdx); } else { FUtil.RemoveAllChildren(spritesContainer.gameObject, true, spriteAddIdx); } currentTotalWidth = currentHorDock - padding; float scaleFact = 1; int calWidth = 0; if (fontHeight > 0 && spriteHeight > 0) { scaleFact = fontHeight / (float)spriteHeight; calWidth = (int)(scaleFact * currentTotalWidth); } else { scaleFact = 1.0f; calWidth = currentTotalWidth; } if (maxWidth > 0 && calWidth > maxWidth) { scaleFact = (float)maxWidth / (float)currentTotalWidth; } spritesContainer.localScale = new Vector3(scaleFact, scaleFact, scaleFact); // text alignment if (textAlign == TextAlign.RIGHT) { spritesContainer.localPosition = new Vector3(-currentTotalWidth * scaleFact, 0, 0); } else if (textAlign == TextAlign.CENTER) { spritesContainer.localPosition = new Vector3(-currentTotalWidth / 2 * scaleFact, 0, 0); } else if (textAlign == TextAlign.LEFT) { spritesContainer.localPosition = new Vector3(0, 0, 0); } }