private static bool alignCenter = true; //中心对齐 private static RTSpriteBoard UF_GetSpriteBoard(UILabel label) { RTSpriteBoard spriteBoard = null; var tarnsboard = label.transform.Find("RTSpriteBoard"); if (tarnsboard == null) { GameObject goRTSprite = new GameObject("RTSpriteBoard"); goRTSprite.hideFlags = HideFlags.HideAndDontSave; spriteBoard = goRTSprite.AddComponent <RTSpriteBoard> (); spriteBoard.rectTransform.SetAsFirstSibling(); spriteBoard.rectTransform.SetParent(label.transform); spriteBoard.rectTransform.localPosition = Vector3.zero; spriteBoard.rectTransform.localScale = Vector3.one; spriteBoard.rectTransform.offsetMin = Vector3.zero; spriteBoard.rectTransform.offsetMax = Vector3.zero; spriteBoard.rectTransform.anchorMax = new Vector2(1, 1); spriteBoard.rectTransform.anchorMin = new Vector2(0, 0); spriteBoard.rectTransform.anchoredPosition = Vector2.zero; spriteBoard.rectTransform.pivot = label.rectTransform.pivot; } else { spriteBoard = tarnsboard.GetComponent <RTSpriteBoard> (); spriteBoard.rectTransform.pivot = label.rectTransform.pivot; } return(spriteBoard); }
public static void UF_OnPopulateMesh(UILabel label, List <TextToken> tokens, List <UIVertex> uivertexs, int startIndex = 0) { List <SpriteData> listSpriteDatas = ListCache <SpriteData> .Acquire(); RTSpriteBoard spriteBoard = UF_GetSpriteBoard(label); UF_HandleToken(tokens, listSpriteDatas, label.fontSize); UF_HandleMesh(uivertexs, listSpriteDatas, spriteBoard, startIndex); ListCache <SpriteData> .Release(listSpriteDatas); }
private static void UF_HandleMesh(List <UIVertex> uivertexs, List <SpriteData> listSpriteDatas, RTSpriteBoard spriteBoard, int startIndex) { if (spriteBoard == null) { return; } if (listSpriteDatas.Count > 0) { spriteBoard.UF_ClearVertexData(); if (uivertexs.Count > 0) { for (int k = 0; k < listSpriteDatas.Count; k++) { int idx = listSpriteDatas [k].idx * 6; if (idx + 6 >= uivertexs.Count) { break; } if (alignCenter) { UF_modifySpriteCenter(uivertexs, idx); } else { UF_modifySpriteNormal(uivertexs, idx); } spriteBoard.UF_OnPopulateVertex( uivertexs, idx, listSpriteDatas [k].offset, listSpriteDatas [k].name ); } spriteBoard.UF_UpdateSprite(); } } else { spriteBoard.Reset(); spriteBoard.UF_UpdateSprite(); } }