_xiaofang/xiaofang/Assets/Res/HYLUI/TaskPanel.cs

101 lines
1.8 KiB
C#
Raw Normal View History

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
2024-12-06 11:52:15 +08:00
using System.Threading.Tasks;
public class TaskPanel : Base
{
public static TaskPanel instance;
2024-12-05 20:21:15 +08:00
public List<int> taskId = new List<int>();
public Transform contentTrans;
public GameObject taskPrefab;
public JSONReader JSONReader;
public Dictionary<int, Language> taskDic = new Dictionary<int, Language>();
public Button closeBtn;
private bool isOpen = false;
// Start is called before the first frame update
void Start()
{
instance = this;
closeBtn.onClick.AddListener(CloseBtn);
2024-12-05 20:21:15 +08:00
2024-12-05 20:21:15 +08:00
}
2024-12-06 11:52:15 +08:00
public async void InitTask()
2024-12-05 20:21:15 +08:00
{
2024-12-06 11:52:15 +08:00
await DestroyTaskAsync();
2024-12-05 20:21:15 +08:00
for(int i = 0; i < taskId.Count;i++)
{
GameObject go = GameObject.Instantiate(taskPrefab, contentTrans);
go.transform.name = "Task_" + i;
TaskItem item = go.GetComponent<TaskItem>();
item.SetInfo(taskId[i], JSONReader);
2024-12-05 20:21:15 +08:00
}
}
2024-12-06 11:52:15 +08:00
public async Task DestroyTaskAsync()
{
DeleteAllChildObjects();
await Task.Delay(10);
}
public void DeleteAllChildObjects()
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>岢ɾ<E5B2A2><C9BE>
foreach (Transform child in contentTrans)
{
Destroy(child.gameObject);
}
}
2024-12-05 20:21:15 +08:00
public void SetInfo(int id)
{
2024-12-06 11:52:15 +08:00
taskId.Add(id);
InitTask();
}
public void CloseBtn()
{
if (isOpen)//<2F>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
isOpen = false;
}
else//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
isOpen = true;
}
}
2024-12-05 20:21:15 +08:00
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown(KeyCode.J))
{
SetInfo(11001);
}
}
}