项目为了做图文混排,只好自己慢慢分析UILabel的代码,找到核心代码,再进行分析。
得到下面的代码,真正的核心代码是在 NGUIText 类里面。继续剥离代码!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
using UnityEngine; using System.Collections.Generic; using System; [ExecuteInEditMode] [AddComponentMenu("NGUI/UI/NGUI Chat Label")] public class ChatLabel : UIWidget { //Bitmap UIFont public UIFont mFont; //Bitmap Material public override Material material { get { return mFont.material; } } //Bitmap UIFont public UIFont bitmapFont { get { return mFont; } } //显示的内容 public string processedText { get { Debug.Log("ProcessedText..!"); NGUIText.bitmapFont = mFont; NGUIText.alignment = TextAlignment.Right; NGUIText.lineWidth = 260; NGUIText.lineHeight = 76; return "ProcessedText..!!.!111"; } } public override void OnFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols) { Debug.Log("OnFill...."); //颜色设置 NGUIText.tint = Color.green; NGUIText.Print(processedText, verts, uvs, cols); } } |