| using System.Collections.Generic; | 
| using UnityEngine; | 
| using UnityEngine.UI; | 
|   | 
| //官职和称号:根据用户选择,佩戴称号的情况下优先显示称号 | 
| //组件默认参考大小为官职的底图大小 | 
| public class OfficialTitleCell : MonoBehaviour | 
| { | 
|     private void Awake() | 
|     { | 
|         //如果有需要按钮点击逻辑,在外层创建,此处不处理点击逻辑 | 
|         LoadPrefab(); | 
|   | 
|     } | 
|   | 
|   | 
|     Image m_OfficialRankObj; | 
|     private Image officialRankObj | 
|     { | 
|         get | 
|         {    | 
|             if (m_OfficialRankObj == null) | 
|             { | 
|                 m_OfficialRankObj = this.GetComponent<Image>("OfficialTitleCell/offcialRank"); | 
|             } | 
|             return m_OfficialRankObj; | 
|         } | 
|     } | 
|   | 
|   | 
|     Text m_OfficialRankText; | 
|     private Text officialRankText | 
|     { | 
|                 get | 
|         {    | 
|             if (m_OfficialRankText == null) | 
|             { | 
|                 m_OfficialRankText = this.GetComponent<Text>("OfficialTitleCell/offcialRank/text"); | 
|             } | 
|             return m_OfficialRankText; | 
|         } | 
|     } | 
|   | 
|     Image m_TitleImage; | 
|     private Image titleImage | 
|     { | 
|         get | 
|         { | 
|             if (m_TitleImage == null) | 
|             { | 
|                 m_TitleImage = this.GetComponent<Image>("OfficialTitleCell/Img_Title"); | 
|             } | 
|             return m_TitleImage; | 
|         } | 
|     } | 
|   | 
|   | 
|   | 
|     UIFrame m_UIFrame; | 
|     private UIFrame titleUIFrame | 
|     { | 
|         get | 
|         { | 
|             if (m_UIFrame == null) | 
|             { | 
|                 m_UIFrame = this.GetComponent<UIFrame>("OfficialTitleCell/Img_Title"); | 
|             } | 
|             return m_UIFrame; | 
|         } | 
|     } | 
|   | 
|      | 
|     GameObject prefab; | 
|   | 
|   | 
|     protected void LoadPrefab() | 
|     { | 
|         if (prefab != null) | 
|             return; | 
|         var tmp = transform.Find("OfficialTitleCell"); | 
|   | 
|         if (tmp != null) | 
|         { | 
|             prefab = tmp.gameObject; | 
|             return; | 
|         } | 
|         prefab = UIUtility.CreateWidget("OfficialTitleCell", "OfficialTitleCell"); | 
|   | 
|         prefab.transform.SetParentEx(this.transform, Vector3.zero, Quaternion.identity, Vector3.one); | 
|         prefab.transform.SetAsFirstSibling(); | 
|   | 
|     } | 
|   | 
|     public void InitUI(int offcialRank, int titleID) | 
|     { | 
|         LoadPrefab();   //存在被卸载的可能,重新加载 | 
|         if (titleID == 0) | 
|         { | 
|             officialRankObj.SetActive(true); | 
|             var config = RealmConfig.Get(offcialRank); | 
|             officialRankObj.SetSprite("OfficialRank" + config.Quality); | 
|   | 
|             titleUIFrame.SetActive(false); | 
|             officialRankText.text = config.Name; | 
|             officialRankText.color = OfficialRankManager.Instance.GetOfficialRankColor(config.Quality); | 
|         } | 
|         else | 
|         { | 
|             officialRankObj.SetActive(false); | 
|             titleUIFrame.SetActive(true); | 
|             titleUIFrame.enabled = false; | 
|             var titleConfig = DienstgradConfig.Get(titleID); | 
|             string imgStr = titleConfig.Image; | 
|             if (!FrameAnimationConfig.HasKey(imgStr)) | 
|             { | 
|                 titleImage.SetSprite(imgStr); | 
|                 titleImage.SetNativeSize(); | 
|                 return; | 
|             } | 
|   | 
|             if (UIFrameMgr.Inst.ContainsDynamicImage(imgStr)) | 
|             { | 
|                 titleUIFrame.ResetFrame(imgStr); | 
|   | 
|                 List<Sprite> spriteList = UIFrameMgr.Inst.GetDynamicImage(imgStr); | 
|                 if (!spriteList.IsNullOrEmpty()) | 
|                 { | 
|                     titleImage.rectTransform.sizeDelta = new Vector2(spriteList[0].rect.width, spriteList[0].rect.height); | 
|                 } | 
|   | 
|                 titleUIFrame.enabled = true; | 
|             } | 
|         } | 
|     } | 
|      | 
| } |