yyl
2 天以前 5d3366f2e0f687995eb7ad2107c4379fe7acd4e8
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
//官职和称号:根据用户选择,佩戴称号的情况下优先显示称号
//组件默认参考大小为官职的底图大小
public class OfficialTitleCell : MonoBehaviour
{
    private void Awake()
    {
        //如果有需要按钮点击逻辑,在外层创建,此处不处理点击逻辑
        LoadPrefab();
 
    }
 
 
    Transform m_OfficialRankObj;
    private Transform officialRankObj
    {
        get
        {   
            if (m_OfficialRankObj == null)
            {
                m_OfficialRankObj = this.GetComponent<Transform>("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)
    {
        if (titleID == 0)
        {
            officialRankObj.SetActive(true);
            titleUIFrame.SetActive(false);
            officialRankText.text = RealmConfig.Get(offcialRank).Name;
        }
        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;
            }
        }
    }
    
}