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

104 lines
2.6 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;
2024-12-26 17:37:30 +08:00
using UnityEngine.Windows;
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>
2024-12-26 17:37:30 +08:00
public int overseeCond; //<2F><><EFBFBD><EFBFBD>id
public int ishow;
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-26 17:37:30 +08:00
List<int> ExtractNumbers(string input)
{
// ʹ<><CAB9> '|' <20>ָ<EFBFBD><D6B8>ַ<EFBFBD><D6B7><EFBFBD>
string[] numberStrings = input.Split("");
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>б<EFBFBD><D0B1><EFBFBD><E6B4A2><EFBFBD><EFBFBD>
List<int> numbers = new List<int>();
foreach (string numberString in numberStrings)
{
// <20><><EFBFBD>Խ<EFBFBD><D4BD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
if (int.TryParse(numberString, out int number))
{
numbers.Add(number);
}
}
2024-12-11 20:16:45 +08:00
2024-12-26 17:37:30 +08:00
return numbers;
}
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-26 17:37:30 +08:00
Debug.Log(info.OverseeCond);
ishow = int.Parse(info.IsShow);
Debug.Log(ishow);
if (ishow == 1)
{
overseeCond = int.Parse(info.OverseeCond);
}
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);
}
}
}
}