94 lines
2.8 KiB
C#
94 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace ZC
|
|
{
|
|
[System.Serializable]
|
|
public class TaskListDatas : ScriptableObject
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
} |