yyl
2026-05-11 51b0f6ed9f4e1d3bb6f8144470b46908c7699a96
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
using System;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.Events;
 
//澶村儚妯″潡
public class AvatarCell : MonoBehaviour
{
    ButtonEx m_button;
    public ButtonEx button
    {
        get
        {
            if (m_button == null)
            {
                m_button = this.GetComponent<ButtonEx>("AvatarCell/Img_FaceBG");
            }
            return m_button;
        }
    }
 
    ImageEx m_FaceBGImage;
    public ImageEx faceBGImage
    {
        get
        {
            if (m_FaceBGImage == null)
            {
                m_FaceBGImage = this.GetComponent<ImageEx>("AvatarCell/Img_FaceBG");
            }
            return m_FaceBGImage;
        }
    }
 
    EllipseMask m_FaceMask;
    public EllipseMask faceMask
    {
        get
        {
            if (m_FaceMask == null)
            {
                m_FaceMask = this.GetComponent<EllipseMask>("AvatarCell/Img_FaceBG/Mask_Face");
            }
            return m_FaceMask;
        }
    }
 
    UIFrame m_FaceUIFrame;
    public UIFrame faceUIFrame
    {
        get
        {
            if (m_FaceUIFrame == null)
            {
                m_FaceUIFrame = this.GetComponent<UIFrame>("AvatarCell/Img_FaceBG/Mask_Face/Img_Face");
            }
            return m_FaceUIFrame;
        }
    }
 
    ImageEx m_FaceImage;
    public ImageEx faceImage
    {
        get
        {
            if (m_FaceImage == null)
            {
                m_FaceImage = this.GetComponent<ImageEx>("AvatarCell/Img_FaceBG/Mask_Face/Img_Face");
            }
            return m_FaceImage;
        }
    }
 
    UIEffectPlayer m_faceSpine;
    public UIEffectPlayer faceSpine
    {
        get
        {
            if (m_faceSpine == null)
            {
                m_faceSpine = this.GetComponent<UIEffectPlayer>("AvatarCell/Img_FaceBG/Mask_Face/Img_Face/Spine_Face");
            }
            return m_faceSpine;
        }
    }
 
 
    ImageEx m_FacePicImage;
    public ImageEx facePicImage
    {
        get
        {
            if (m_FacePicImage == null)
            {
                m_FacePicImage = this.GetComponent<ImageEx>("AvatarCell/Img_FaceBG/Img_FacePic");
            }
            return m_FacePicImage;
        }
    }
 
    UIFrame m_FacePicUIFrame;
    public UIFrame facePicUIFrame
    {
        get
        {
            if (m_FacePicUIFrame == null)
            {
                m_FacePicUIFrame = this.GetComponent<UIFrame>("AvatarCell/Img_FaceBG/Img_FacePic");
            }
            return m_FacePicUIFrame;
        }
    }
 
    UIEffectPlayer m_facePicSpine;
    public UIEffectPlayer facePicSpine
    {
        get
        {
            if (m_facePicSpine == null)
            {
                m_facePicSpine = this.GetComponent<UIEffectPlayer>("AvatarCell/Img_FaceBG/Img_FacePic/Spine_FacePic");
            }
            return m_facePicSpine;
        }
    }
 
    RedpointBehaviour m_redpoint;
    public RedpointBehaviour redpoint
    {
        get
        {
            if (m_redpoint == null)
            {
                m_redpoint = this.GetComponent<RedpointBehaviour>("AvatarCell/Img_FaceBG/RedPoint");
            }
            return m_redpoint;
        }
    }
    GameObject prefab;
    AvatarModel avatarModel;
    PhantasmPavilionManager manager { get { return PhantasmPavilionManager.Instance; } }
    bool isLoaded { get { return prefab != null; } }
    Action onLoaded = null;
 
    private void Awake()
    {
        LoadPrefab().Forget();
    }
 
    public void SetOnLoaded(Action _onloaded)
    {
        if (isLoaded)
        {
            _onloaded?.Invoke();
        }
        else
        {
            onLoaded += _onloaded;
        }
    }
 
    void OnEnable()
    {
        PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefresh;
    }
 
    void OnDisable()
    {
        PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefresh;
    }
 
    private void PlayerDataRefresh(PlayerDataType type)
    {
        if (type == PlayerDataType.Face || type == PlayerDataType.FacePic)
        {
            if (avatarModel == null || avatarModel.playerID != PlayerDatas.Instance.baseData.PlayerID)
                return;
            InitUI(AvatarHelper.GetAvatarModel((int)PlayerDatas.Instance.baseData.PlayerID,
                                                                PlayerDatas.Instance.baseData.face,
                                                                PlayerDatas.Instance.baseData.facePic)).Forget();
        }
    }
 
    protected async UniTask LoadPrefab()
    {
        if (prefab != null)
            return;
        var tmp = transform.Find("AvatarCell");
 
        if (tmp != null)
        {
            prefab = tmp.gameObject;
            return;
        }
        var inst = await UIUtility.CreateWidget("AvatarCell", "AvatarCell");
 
        if (this == null)
        {
            if (inst != null) GameObject.DestroyImmediate(inst);
            return;
        }
 
        if (prefab != null)
        {
            GameObject.DestroyImmediate(inst);
            return;
        }
        prefab = inst;
 
        prefab.transform.SetParentEx(this.transform, Vector3.zero, Quaternion.identity, Vector3.one);
        prefab.transform.SetAsFirstSibling();
 
        RectTransform prefabRect = prefab.GetComponent<RectTransform>();
        RectTransform parentRect = GetComponent<RectTransform>();
        if (prefabRect != null && parentRect != null)
        {
            prefabRect.anchorMin = new Vector2(0.5f, 0.5f);
            prefabRect.anchorMax = new Vector2(0.5f, 0.5f);
            prefabRect.sizeDelta = new Vector2(parentRect.rect.width, parentRect.rect.height);
        }
 
        onLoaded?.Invoke();
        onLoaded = null;
 
    }
    public async UniTask InitUI(AvatarModel model)
    {
        if (model == null)
        {
            Debug.LogError("[AvatarCell] model is null");
            return;
        }
        avatarModel = model;
        await LoadPrefab();   //瀛樺湪琚嵏杞界殑鍙兘锛岄噸鏂板姞杞?
 
        if (this == null)
        {
            return;
        }
 
        int faceID = model.faceID;
        int facePicID = model.facePicID;
 
        // 璇婃柇锛氭鏌?Mask_Face 鑺傜偣鍙婂叾瀛愬璞?
        var maskTf = prefab?.transform.Find("Img_FaceBG/Mask_Face");
        if (maskTf != null)
        {
            for (int i = 0; i < maskTf.childCount; i++)
            {
                var child = maskTf.GetChild(i);
                var img = child.GetComponent<UnityEngine.UI.Graphic>();
            }
        }
 
        // 璇婃柇锛氭鏌?Img_FacePic 鑺傜偣
        var facePicTf = prefab?.transform.Find("Img_FaceBG/Img_FacePic");
        if (facePicTf != null)
        {
            var fpImg = facePicTf.GetComponent<UnityEngine.UI.Graphic>();
        }
 
        await manager.ShowFace(faceImage, faceSpine, faceUIFrame, faceMask, faceID);
 
        if (this == null) return;
 
        string str = AvatarHelper.GetAvatarBgColorStr(faceID);
        faceBGImage.SetSprite(str);
 
        int resourceType = manager.GetResourceType(PhantasmPavilionType.FacePic, facePicID);
        string resourceValue = manager.GetResourceValue(PhantasmPavilionType.FacePic, facePicID);
        manager.Show(PhantasmPavilionType.FacePic, facePicImage, facePicSpine, facePicUIFrame, resourceType, resourceValue);
 
        BindButtonClick(model);
    }
    // 娣诲姞鏍囧織浣嶏細鏄惁宸茶缃嚜瀹氫箟鐩戝惉鍣?
    private bool hasCustomListener = false;
    public void SetListener(UnityAction action)
    {
        hasCustomListener = true;  // 鏍囪宸茶缃嚜瀹氫箟鐩戝惉
        button.SetListener(action);
    }
    public void AddListener(UnityAction action)
    {
        hasCustomListener = true;  // 鏍囪宸茶缃嚜瀹氫箟鐩戝惉
        button.SetListener(action);
    }
    private void BindButtonClick(AvatarModel model)
    {
        // 濡傛灉宸茬粡璁剧疆浜嗚嚜瀹氫箟鐩戝惉鍣紝涓嶈鐩?
        if (hasCustomListener)
            return;
 
        button.SetListener(() =>
        {
            if (avatarModel == null)
            {
                return;
            }
            AvatarHelper.TryViewOtherPlayerInfo(avatarModel.playerID);
        });
    }
 
}
 
public class AvatarModel
{
    public int playerID { get; private set; }
    public int faceID { get; private set; }
    public int facePicID { get; private set; }
 
    public AvatarModel(int playerID, int faceID, int facePicID)
    {
        this.playerID = playerID;
        this.faceID = faceID;
        this.facePicID = facePicID;
    }
}