| | |
| | | using UnityEngine; |
| | | using Cysharp.Threading.Tasks; |
| | | |
| | | public class TimingGiftCell : MonoBehaviour |
| | | { |
| | | private void Awake() |
| | | { |
| | | //如果有需要按钮点击逻辑,在外层创建,此处不处理点击逻辑 |
| | | LoadPrefab(); |
| | | InitAsync().Forget(); |
| | | } |
| | | |
| | | private async UniTask InitAsync() |
| | | { |
| | | //如果有需要按鈕点击逻辑,在外层创建,此处不处理点击逻辑 |
| | | await LoadPrefab(); |
| | | if (this == null) return; |
| | | button.SetListener(() => |
| | | { |
| | | UIManager.Instance.OpenWindow<TimingGiftWin>(type); |
| | | UIManager.Instance.OpenWindowAsync<TimingGiftWin>(type).Forget(); |
| | | }); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | protected void LoadPrefab() |
| | | protected async UniTask LoadPrefab() |
| | | { |
| | | if (prefab != null) |
| | | return; |
| | |
| | | prefab = tmp.gameObject; |
| | | return; |
| | | } |
| | | prefab = UIUtility.CreateWidget("TimingGiftCell", "TimingGiftCell"); |
| | | |
| | | prefab = await UIUtility.CreateWidget("TimingGiftCell", "TimingGiftCell"); |
| | | |
| | | if (this == null) |
| | | { |
| | | if (null != prefab) DestroyImmediate(prefab); |
| | | return; |
| | | } |
| | | |
| | | prefab.transform.SetParentEx(this.transform, Vector3.zero, Quaternion.identity, Vector3.one); |
| | | prefab.transform.SetAsFirstSibling(); |
| | | |
| | | } |
| | | |
| | | public void InitUI() |
| | | public async UniTask InitUI() |
| | | { |
| | | LoadPrefab(); //存在被卸载的可能,重新加载 |
| | | await LoadPrefab(); //存在被卸载的可能,重新加载 |
| | | if (this == null) return; |
| | | Display(); |
| | | } |
| | | |