92 lines
2.4 KiB
C#
92 lines
2.4 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
public class Player : MonoBehaviour
|
||
{
|
||
|
||
public static Player CSZS;
|
||
public JSONReader jSONReader;
|
||
|
||
public Dictionary<string, List<string>> PlayerID = new Dictionary<string, List<string>>()
|
||
{
|
||
{ "8000", new List<string>() },
|
||
{ "8001", new List<string>() },
|
||
{ "8002", new List<string>() },
|
||
{ "8003", new List<string>() },
|
||
{ "8004", new List<string>() },
|
||
{ "8005", new List<string>() },
|
||
{ "8006", new List<string>() },
|
||
{ "8007", new List<string>() },
|
||
{ "8008", new List<string>() },
|
||
{ "8009", new List<string>() },
|
||
{ "8010", new List<string>() },
|
||
{ "8011", new List<string>() }
|
||
};
|
||
|
||
private void Awake()
|
||
{
|
||
CSZS = this;
|
||
}
|
||
/// <summary>
|
||
/// 接收玩家接受的任务
|
||
/// </summary>
|
||
public void SetPlayerID(string TaskID)
|
||
{
|
||
var a=ParseString(jSONReader.GetOcpID(int.Parse(TaskID)));
|
||
for (int i=0;i<a.Count;i++)
|
||
{
|
||
PlayerID[a[i]].Add(TaskID);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 返回一个职业接取的任务
|
||
/// </summary>
|
||
public List<string> GetPlayerID(string ID)
|
||
{
|
||
if (PlayerID.TryGetValue(ID, out List<string> value))
|
||
{
|
||
return value; // 返回对应的 List<string>
|
||
}
|
||
else
|
||
{
|
||
Debug.Log("颠仔找不到");
|
||
return new List<string>(); // 返回空列表
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 解析以 "|" 分隔的字符串并返回一个 List
|
||
/// </summary>
|
||
/// <param name="input">输入的字符串</param>
|
||
/// <returns>解析后的 List,如果输入为空则返回空列表</returns>
|
||
public static List<string> ParseString(string input)
|
||
{
|
||
// 如果输入为空或 null,返回空列表
|
||
if (string.IsNullOrEmpty(input))
|
||
{
|
||
return new List<string>();
|
||
}
|
||
|
||
// 按 "|" 分割字符串,并返回结果列表
|
||
return new List<string>(input.Split('|'));
|
||
}
|
||
|
||
public void Start()
|
||
{
|
||
SetPlayerID("11007");
|
||
////遍历字典
|
||
//foreach (KeyValuePair<string, List<string>> kvp in PlayerID)
|
||
//{
|
||
// Debug.Log($"职业: {kvp.Key}");
|
||
|
||
// // 遍历值(List<string>)
|
||
// foreach (string task in kvp.Value)
|
||
// {
|
||
// Debug.Log($"任务: {task}");
|
||
// }
|
||
//}
|
||
|
||
}
|
||
}
|