diff --git a/xiaofang/Assets/Res/HYLUI/TaskPanel.cs b/xiaofang/Assets/Res/HYLUI/TaskPanel.cs index ee7388f2..012e41c9 100644 --- a/xiaofang/Assets/Res/HYLUI/TaskPanel.cs +++ b/xiaofang/Assets/Res/HYLUI/TaskPanel.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using DG.Tweening; +using System.Threading.Tasks; public class TaskPanel : Base { @@ -33,8 +34,9 @@ public class TaskPanel : Base } - public void InitTask() + public async void InitTask() { + await DestroyTaskAsync(); for(int i = 0; i < taskId.Count;i++) { GameObject go = GameObject.Instantiate(taskPrefab, contentTrans); @@ -44,9 +46,24 @@ public class TaskPanel : Base } } + public async Task DestroyTaskAsync() + { + DeleteAllChildObjects(); + await Task.Delay(10); + } + public void DeleteAllChildObjects() + { + // 遍历所有子物体并删除 + foreach (Transform child in contentTrans) + { + Destroy(child.gameObject); + } + } public void SetInfo(int id) { + + taskId.Add(id); InitTask(); }