104 lines
2.6 KiB
C#
104 lines
2.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.Windows;
|
|
|
|
public enum TaskState
|
|
{
|
|
NotStarted, // 未开始
|
|
InProgress, // 进行中
|
|
Completed, // 已完成
|
|
Failed // 失败
|
|
}
|
|
|
|
|
|
|
|
public class TaskItem : MonoBehaviour
|
|
{
|
|
public int taskId; // 任务ID
|
|
public string taskName; // 任务名称
|
|
public TaskState state; // 任务状态
|
|
public Text taskTxt; // 任务描述文本
|
|
public int overseeCond; //区域id
|
|
public int ishow;
|
|
public List<TaskTarget> Targets = new List<TaskTarget>(); // 任务目标1列表
|
|
private JSONReader jsonReader; // JSON 数据读取器
|
|
|
|
List<int> ExtractNumbers(string input)
|
|
{
|
|
// 使用 '|' 分割字符串
|
|
string[] numberStrings = input.Split("");
|
|
|
|
// 创建一个列表存储数字
|
|
List<int> numbers = new List<int>();
|
|
|
|
foreach (string numberString in numberStrings)
|
|
{
|
|
// 尝试将字符串解析为整数
|
|
if (int.TryParse(numberString, out int number))
|
|
{
|
|
numbers.Add(number);
|
|
}
|
|
}
|
|
|
|
return numbers;
|
|
}
|
|
public void SetInfo(int id, JSONReader reader)
|
|
{
|
|
taskId = id;
|
|
jsonReader = reader;
|
|
LoadTaskData();
|
|
}
|
|
|
|
private void LoadTaskData()
|
|
{
|
|
Task_ info = jsonReader.GetTaskByID(taskId);
|
|
taskName = info.Note;
|
|
state = TaskState.NotStarted;
|
|
Debug.Log(info.OverseeCond);
|
|
ishow = int.Parse(info.IsShow);
|
|
Debug.Log(ishow);
|
|
if (ishow == 1)
|
|
{
|
|
overseeCond = int.Parse(info.OverseeCond);
|
|
}
|
|
|
|
|
|
Debug.Log(info.Targets1);
|
|
|
|
UpdateTxt();
|
|
}
|
|
|
|
// 更新任务描述文本
|
|
public void UpdateTxt()
|
|
{
|
|
string progressInfo = "";
|
|
foreach (var target in Targets)
|
|
{
|
|
progressInfo += $"{target.Description}: {target.CurrentProgress}/{target.RequiredProgress}\n";
|
|
}
|
|
Debug.Log(taskName);
|
|
Debug.Log(progressInfo);
|
|
taskTxt.text = $"{taskName}";
|
|
}
|
|
|
|
// 更新任务进度
|
|
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();
|
|
|
|
// 检查是否所有目标已完成
|
|
if (Targets.TrueForAll(t => t.IsCompleted))
|
|
{
|
|
state = TaskState.Completed;
|
|
TaskPanel.instance.RemoveTask(taskId);
|
|
}
|
|
}
|
|
}
|
|
}
|