任务相关逻辑

This commit is contained in:
huyulong 2024-12-11 20:16:45 +08:00
parent a1787fd70d
commit c7cf4332da
3 changed files with 42 additions and 21 deletions

View File

@ -4,24 +4,51 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public enum TaskStatus
{
NotAccepted, // 未接受
InProgress, // 进行中
Completed, // 已完成
Failed // 失败
}
public class TaskItem : MonoBehaviour
{
public int taskId;
public string taskName;
public TaskStatus status;
public List<int> triggers; // 存储任务触发条件
public JSONReader jr;
public int id;
public Text tasktxt;
// Start is called before the first frame update
void Start()
{
}
//构造函数
public TaskItem(int id, string name)
{
taskId = id;
taskName = name;
status = TaskStatus.NotAccepted;
triggers = new List<int>();
}
// 设置任务状态
public void SetStatus(TaskStatus newStatus)
{
status = newStatus;
}
private void OnClickButton()
{
@ -29,7 +56,7 @@ public class TaskItem : MonoBehaviour
public void SetInfo(int id,JSONReader js)
{
this.id = id;
taskId = id;
jr = js;
UpdateTxt();
}
@ -37,9 +64,9 @@ public class TaskItem : MonoBehaviour
void UpdateTxt()
{
Language info = jr.GetTaskByID(id,jr.LanguageDictionary);
Task_ info = jr.GetTaskByID(taskId);
tasktxt.text = info.Text;
tasktxt.text = info.Name;
}

View File

@ -8,6 +8,10 @@ using System.Threading.Tasks;
public class TaskPanel : Base
{
private List<TaskItem> tasks = new List<TaskItem>();
private Dictionary<int, Task> activeTasks = new Dictionary<int, Task>();
public static TaskPanel instance;
public List<int> taskId = new List<int>();

View File

@ -234,22 +234,12 @@ public class JSONReader : MonoBehaviour
//»ñÈ¡ÈÎÎñ
public Language GetTaskByID(int id,Dictionary<int,Language> dic)
public Task_ GetTaskByID(int id)
{
Language info = null;
if (LanguageDictionary.TryGetValue(id, out info))
Task_ info = null;
if (TaskDictionary.TryGetValue(id.ToString(), out info))
{
// 判断 Note 是否等于 "预定演练"
if (info.Note == "任务")
{
Debug.Log($"Found Language: ID = {info.ID}, Text = {info.Text}, Note = {info.Note}");
//dic.Add(id, info);
return info; // 返回符合条件的 Language 数据
}
else
{
Debug.Log($"Language with ID {id} found, but Note is not '预定演练'.");
}
return info; // 返回符合条件的 Task 数据
}
else
{