111 lines
3.2 KiB
C#
111 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
|
|
namespace ZC
|
|
{
|
|
[System.Serializable]
|
|
public enum TaskListType
|
|
{
|
|
未完成,
|
|
当前任务,
|
|
进行中,
|
|
已完成,
|
|
}
|
|
|
|
[System.Serializable]
|
|
public class TaskListData
|
|
{
|
|
public string Title;
|
|
[LabelText("类型")] public TaskListType Type;
|
|
[LabelText("父节点")] public TaskListData parent;
|
|
public List<TaskListData> ChildData = new List<TaskListData>();
|
|
}
|
|
|
|
[System.Serializable]
|
|
public class TaskListDatas
|
|
{
|
|
public List<TaskListData> ChildData = new List<TaskListData>();
|
|
|
|
// public Action<List<TaskListData>> callback;
|
|
|
|
public void Init()
|
|
{
|
|
SetParent(ChildData);
|
|
}
|
|
|
|
void SetParent(List<TaskListData> data, TaskListData parent = null)
|
|
{
|
|
for (var i = 0; i < data.Count; i++)
|
|
{
|
|
data[i].parent = parent;
|
|
if (data[i].ChildData.Count > 0)
|
|
{
|
|
SetParent(data[i].ChildData, data[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetState(string title, TaskListType type)
|
|
{
|
|
TaskListData trueData = null;
|
|
Check(ChildData, title, ref trueData);
|
|
List<TaskListData> listDatas = new List<TaskListData>();
|
|
ReData(trueData, ref listDatas);
|
|
listDatas.Reverse();
|
|
|
|
switch (type)
|
|
{
|
|
case TaskListType.未完成:
|
|
trueData.Type = TaskListType.未完成;
|
|
break;
|
|
case TaskListType.当前任务:
|
|
for (var i = 0; i < listDatas.Count; i++)
|
|
{
|
|
if (i == listDatas.Count - 1)
|
|
listDatas[i].Type = TaskListType.当前任务;
|
|
else
|
|
listDatas[i].Type = TaskListType.进行中;
|
|
}
|
|
break;
|
|
case TaskListType.进行中:
|
|
trueData.Type = TaskListType.进行中;
|
|
break;
|
|
case TaskListType.已完成:
|
|
for (var i = 0; i < listDatas.Count; i++)
|
|
{
|
|
listDatas[i].Type = TaskListType.已完成;
|
|
}
|
|
break;
|
|
default:
|
|
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
|
}
|
|
// callback?.Invoke(listDatas);
|
|
}
|
|
|
|
private void Check(List<TaskListData> data, string title, ref TaskListData trueData)
|
|
{
|
|
for (var i = 0; i < data.Count; i++)
|
|
{
|
|
if (data[i].Title == title)
|
|
{
|
|
trueData = data[i];
|
|
return;
|
|
}
|
|
|
|
if (data[i].ChildData.Count > 0)
|
|
Check(data[i].ChildData, title, ref trueData);
|
|
}
|
|
}
|
|
|
|
private void ReData(TaskListData data, ref List<TaskListData> datas)
|
|
{
|
|
datas.Add(data);
|
|
if (data.parent != null)
|
|
{
|
|
ReData(data.parent, ref datas);
|
|
}
|
|
}
|
|
}
|
|
} |