You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.5 KiB

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<TextAsset>("Task");
//string file = File.ReadAllText(Application.streamingAssetsPath+ "/Task.json");
task = JsonMapper.ToObject<Task[]>(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;
}
}