using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System.IO; using LitJson; [SerializeField] public class Task{ public string name; public string detail; public bool state; } public class TaskCenter : MonoBehaviour { public GameObject TaskPanel; static TaskCenter _instance; public Text name; public Text detail; int curTask; Task[] task; private void Awake() { _instance = this; } private void Start() { TextAsset file = Resources.Load("Task"); //string file = File.ReadAllText(Application.streamingAssetsPath+ "/Task.json"); task = JsonMapper.ToObject(file.text); } public static TaskCenter GetInstance() { if (!_instance) { _instance = new TaskCenter(); } return _instance; } public void StartTask() { TaskPanel.SetActive(true); curTask = 0; name.text = task[curTask].name; detail.text = task[curTask].detail; } public void FinishTask(int number) { if (number==task.Length-1) { TaskPanel.SetActive(false); return; } if (number==curTask) { task[curTask].state = true; curTask++; updateTask(curTask); } } void updateTask(int number) { name.text = task[number].name; detail.text = task[number].detail; } }