本帖最后由 martin4500 于 2018-5-9 09:57 编辑 这段时间比较闲,所以抽时间写了游戏中常见的系统,任务系统,可以接受任务啊,然后通过刷怪等条件去触发任务条件,直到完成任务。
这个系统相对来说比较的简单,可以满足小型的游戏任务系统的基本要求吧!
![]() ![]() ![]()
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
public class DataManager : MonoSingletions<DataManager>
{
private Dictionary<string, Task> taskAllDic = new Dictionary<string, Task>();
private TextAsset mTextAsset;
private void Awake()
{
if (mTextAsset == null)
{
mTextAsset = Resources.Load("Txt/Task", typeof(TextAsset)) as TextAsset;
}
taskAllDic = JsonConvert.DeserializeObject<Dictionary<string, Task>>(mTextAsset.text);
// taskAllDic = UnityEngine.JsonUtility.FromJson <Dictionary<string, Task>> (mTextAsset.text);
foreach (var item in taskAllDic)
{
string tempName=item.Value.taskName;
Debug.Log(tempName);
}
}
public Task GetTaskByID(string Id)
{
Task value;
if (taskAllDic.TryGetValue(Id, out value)) return value;
else Debug.LogError("不存在这个字典");
return null;
}
}
这个类主要是来读取Json文本解析数据,也不需要多去解释了
MonoSingletions
是Mono的单例
public class Task
{ public string taskID; public string taskName; public string description; public List<TaskConditions> taskConditions = new List<TaskConditions>(); public TaskRewards[] taskRewards = new TaskRewards[2];//最好是用数组比链表要节省空间 public Task(string _taskId,string _taskName,string _descrip |
Unity 实现任务系统 TaskSystem
最新推荐文章于 2025-03-05 13:21:57 发布