| | |
| | | using System;
|
| | | using Cysharp.Threading.Tasks;
|
| | | using UnityEngine;
|
| | | using UnityEngine.Events;
|
| | |
|
| | |
| | | GameObject prefab;
|
| | | AvatarModel avatarModel;
|
| | | PhantasmPavilionManager manager { get { return PhantasmPavilionManager.Instance; } }
|
| | | bool isLoaded { get { return prefab != null; } }
|
| | | Action onLoaded = null;
|
| | |
|
| | | private void Awake()
|
| | | {
|
| | | LoadPrefab();
|
| | | }
|
| | |
|
| | | public void SetOnLoaded(Action _onloaded)
|
| | | {
|
| | | if (isLoaded)
|
| | | {
|
| | | _onloaded?.Invoke();
|
| | | }
|
| | | else
|
| | | {
|
| | | onLoaded += _onloaded;
|
| | | }
|
| | | }
|
| | |
|
| | | void OnEnable()
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | protected void LoadPrefab()
|
| | | protected async UniTask LoadPrefab()
|
| | | {
|
| | | if (prefab != null)
|
| | | return;
|
| | |
| | | prefab = tmp.gameObject;
|
| | | return;
|
| | | }
|
| | | prefab = UIUtility.CreateWidget("AvatarCell", "AvatarCell");
|
| | | prefab = await UIUtility.CreateWidget("AvatarCell", "AvatarCell");
|
| | |
|
| | | if (this == null)
|
| | | {
|
| | | if (prefab != null)
|
| | | {
|
| | | GameObject.DestroyImmediate(prefab);
|
| | | return;
|
| | | }
|
| | | }
|
| | |
|
| | | prefab.transform.SetParentEx(this.transform, Vector3.zero, Quaternion.identity, Vector3.one);
|
| | | prefab.transform.SetAsFirstSibling();
|
| | |
| | | prefabRect.anchorMax = new Vector2(0.5f, 0.5f);
|
| | | prefabRect.sizeDelta = new Vector2(parentRect.rect.width, parentRect.rect.height);
|
| | | }
|
| | |
|
| | | onLoaded?.Invoke();
|
| | | onLoaded = null;
|
| | |
|
| | | }
|
| | | public void InitUI(AvatarModel model)
|
| | | public async void InitUI(AvatarModel model)
|
| | | {
|
| | | if (model == null)
|
| | | return;
|
| | | avatarModel = model;
|
| | | LoadPrefab(); //存在被卸载的可能,重新加载
|
| | | await LoadPrefab(); //存在被卸载的可能,重新加载
|
| | |
|
| | | if (this == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | |
|
| | | int faceID = model.faceID;
|
| | | int facePicID = model.facePicID;
|
| | | manager.ShowFace(faceImage, faceSpine, faceUIFrame, faceMask, faceID);
|
| | | manager.ShowFace(faceImage, faceSpine, faceUIFrame, faceMask, faceID).Forget();
|
| | |
|
| | | string str = AvatarHelper.GetAvatarBgColorStr(faceID);
|
| | | faceBGImage.SetSprite(str);
|