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

145 lines
3.5 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;
2024-12-26 17:37:30 +08:00
using UnityEngine.Windows;
public class TaskPanel : Base
{
public static TaskPanel instance;
public Transform contentTrans; // <20><><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD>
public GameObject taskPrefab; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD>
public JSONReader JSONReader; // JSON <20><><EFBFBD>ݶ<EFBFBD>ȡ<EFBFBD><C8A1>
2024-12-06 16:24:45 +08:00
public RectTransform buttonRect; // <20><>ť RectTransform
public Button hideBtn; // <20><><EFBFBD>ذ<EFBFBD>ť
2024-12-06 16:24:45 +08:00
private bool isHidden = false; // <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>״̬
public float moveDuration = 0.5f;
public float hidePositionX = 125f;
public float showPositionX = -198f;
2024-12-06 16:24:45 +08:00
2024-12-16 11:58:13 +08:00
public List<int> taskIDs = new List<int>();
private List<TaskItem> taskItems = new List<TaskItem>(); // <20><>ǰ<EFBFBD><C7B0>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
void Start()
{
instance = this;
2024-12-06 16:24:45 +08:00
hideBtn.onClick.AddListener(OnClickHideButton);
2024-12-26 17:37:30 +08:00
InitList();
InitTask(taskIDs);
2024-12-06 16:24:45 +08:00
}
2024-12-12 11:04:48 +08:00
2024-12-26 17:37:30 +08:00
public void InitList()
{
foreach (Task_ task in JSONReader.TaskDictionary.Values)
{
if (int.TryParse(task.ID, out int taskId))
{
// ת<><D7AA><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD> taskIDs <20>б<EFBFBD>
taskIDs.Add(taskId);
}
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public void Taskad(int id)
2024-12-16 11:58:13 +08:00
{
taskIDs.Add(id);
InitTask(taskIDs);
2024-12-16 11:58:13 +08:00
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
2024-12-06 16:24:45 +08:00
public void OnClickHideButton()
{
if (isHidden)
{
buttonRect.DOAnchorPosX(showPositionX, moveDuration).SetEase(Ease.InOutCubic);
2024-12-09 09:46:52 +08:00
hideBtn.transform.Rotate(0, 0, 180f);
isHidden = false;
2024-12-06 16:24:45 +08:00
}
else
{
buttonRect.DOAnchorPosX(hidePositionX, moveDuration).SetEase(Ease.InOutCubic);
2024-12-09 09:46:52 +08:00
hideBtn.transform.Rotate(0, 0, 180f);
isHidden = true;
2024-12-06 16:24:45 +08:00
}
2024-12-05 20:21:15 +08:00
}
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
public async void InitTask(List<int> taskIds)
2024-12-05 20:21:15 +08:00
{
await ClearTaskItems();
foreach (int id in taskIds)
2024-12-05 20:21:15 +08:00
{
AddTask(id);
2024-12-11 14:24:06 +08:00
}
}
2024-12-26 17:37:30 +08:00
// <20><>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD>
public void AddTask(int taskId)
2024-12-11 14:24:06 +08:00
{
GameObject go = Instantiate(taskPrefab, contentTrans);
TaskItem taskItem = go.GetComponent<TaskItem>();
taskItem.SetInfo(taskId, JSONReader);
taskItems.Add(taskItem);
2024-12-26 17:37:30 +08:00
go.SetActive(false);
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>UI
public void UpdateTaskUI(TaskItem taskItem)
2024-12-06 11:52:15 +08:00
{
// <20><><EFBFBD>Ҷ<EFBFBD>Ӧ<EFBFBD><D3A6>UI<55><EFBFBD><EEA3AC><EFBFBD>½<EFBFBD><C2BD>Ȼ<EFBFBD>״̬
TaskItem item = taskItems.Find(t => t.taskId == taskItem.taskId);
if (item != null)
2024-12-06 11:52:15 +08:00
{
item.UpdateTxt();
2024-12-06 11:52:15 +08:00
}
}
2024-12-26 17:37:30 +08:00
public void displaytask(int taskId)
{
TaskItem taskItem = taskItems.Find(t => t.overseeCond== taskId);
if (taskItem != null)
{
2024-12-26 22:28:12 +08:00
Debug.Log(1111);
2024-12-26 17:37:30 +08:00
if (taskItem.ishow == 1)
{
2024-12-26 22:28:12 +08:00
Debug.Log(2222);
2024-12-26 17:37:30 +08:00
taskItem.gameObject.SetActive(true);
}
2024-12-27 12:01:08 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ID
2024-12-26 17:37:30 +08:00
}
}
// <20>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD>
2024-12-12 14:50:53 +08:00
public void RemoveTask(int taskId)
{
TaskItem taskItem = taskItems.Find(t => t.taskId == taskId);
if (taskItem != null)
2024-12-12 14:50:53 +08:00
{
taskItems.Remove(taskItem);
Destroy(taskItem.gameObject);
2024-12-12 14:50:53 +08:00
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public async Task ClearTaskItems()
{
foreach (Transform child in contentTrans)
{
Destroy(child.gameObject);
}
taskItems.Clear();
await Task.Delay(10);
}
}