_xiaofang/xiaofang/Assets/Prefabs/HYLPrefabs/TaskItem.cs

75 lines
1.8 KiB
C#
Raw Normal View History

2024-12-11 14:24:06 +08:00
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public enum TaskState
2024-12-11 20:16:45 +08:00
{
NotStarted, // δ<><CEB4>ʼ
InProgress, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Completed, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Failed // ʧ<><CAA7>
2024-12-11 20:16:45 +08:00
}
public class TaskItem : MonoBehaviour
{
public int taskId; // <20><><EFBFBD><EFBFBD>ID
public string taskName; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public TaskState state; // <20><><EFBFBD><EFBFBD>״̬
public Text taskTxt; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>
public List<TaskTarget> Targets = new List<TaskTarget>(); // <20><><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>1<EFBFBD>б<EFBFBD>
private JSONReader jsonReader; // JSON <20><><EFBFBD>ݶ<EFBFBD>ȡ<EFBFBD><C8A1>
2024-12-11 20:16:45 +08:00
public void SetInfo(int id, JSONReader reader)
2024-12-11 20:16:45 +08:00
{
taskId = id;
jsonReader = reader;
LoadTaskData();
2024-12-11 20:16:45 +08:00
}
private void LoadTaskData()
2024-12-11 14:24:06 +08:00
{
Task_ info = jsonReader.GetTaskByID(taskId);
taskName = info.Note;
state = TaskState.NotStarted;
2024-12-11 14:24:06 +08:00
2024-12-16 15:28:35 +08:00
Debug.Log(info.Targets1);
UpdateTxt();
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>
public void UpdateTxt()
{
string progressInfo = "";
foreach (var target in Targets)
{
progressInfo += $"{target.Description}: {target.CurrentProgress}/{target.RequiredProgress}\n";
}
2024-12-16 15:28:35 +08:00
Debug.Log(taskName);
Debug.Log(progressInfo);
taskTxt.text = $"{taskName}";
2024-12-12 14:50:53 +08:00
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public void UpdateProgress(TargetType targetType, string targetId, int value)
{
TaskTarget target = Targets.Find(t => t.Type == targetType && t.TargetID == targetId);
if (target != null)
{
target.UpdateProgress(value);
UpdateTxt();
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (Targets.TrueForAll(t => t.IsCompleted))
{
state = TaskState.Completed;
TaskPanel.instance.RemoveTask(taskId);
}
}
}
}