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
|
|||
|
{
|
|||
|
δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
|
|||
|
<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
|
|||
|
}
|
|||
|
|
|||
|
[System.Serializable]
|
|||
|
public class TaskListData
|
|||
|
{
|
|||
|
public string Title;
|
|||
|
[LabelText("<22><><EFBFBD><EFBFBD>")] public TaskListType Type;
|
|||
|
[LabelText("<22><><EFBFBD>ڵ<EFBFBD>")] 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.δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
|
|||
|
trueData.Type = TaskListType.δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
|||
|
break;
|
|||
|
case TaskListType.<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
|
|||
|
for (var i = 0; i < listDatas.Count; i++)
|
|||
|
{
|
|||
|
if (i == listDatas.Count - 1)
|
|||
|
listDatas[i].Type = TaskListType.<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
|||
|
else
|
|||
|
listDatas[i].Type = TaskListType.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
|||
|
}
|
|||
|
break;
|
|||
|
case TaskListType.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
|
|||
|
trueData.Type = TaskListType.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
|||
|
break;
|
|||
|
case TaskListType.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
|
|||
|
for (var i = 0; i < listDatas.Count; i++)
|
|||
|
{
|
|||
|
listDatas[i].Type = TaskListType.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
|||
|
}
|
|||
|
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);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|