static void ShowTextCount() { targetObj = Selection.activeGameObject;//得到选中对象 if (targetObj) { bool isok = false; chindernList.Clear(); GetAllTransform(targetObj.transform);//递归得到所有的子对象 for (int i = 0; i < chindernList.Count; i++) { //获取obj,并保存 UILabel _Text = null; if ((_Text = chindernList[i].GetComponent <UILabel>()) && (_Text.bitmapFont) && (_Text.bitmapFont.name == ChangeFont1 || _Text.bitmapFont.name == ChangeFont2)) { waiteForUpdate.Add(chindernList[i].GetComponent <UILabel>()); isok = true; } } if (isok) { if (!targetObj.GetComponent <SetFont>()) { targetObj.AddComponent <SetFont>(); } SetFont set = targetObj.GetComponent <SetFont>();//为对象添加个组件 set.UpdateFont(waiteForUpdate); chindernList.Clear(); waiteForUpdate.Clear(); GameObject.DestroyImmediate(targetObj.GetComponent <SetFont>());//修改完毕移除组件 } } }