1
Fork 0
mirror of https://github.com/Steffo99/better-tee.git synced 2024-11-22 07:14:19 +00:00
better-tee/Assets/Code/PlayerMainController.cs

47 lines
1.4 KiB
C#
Raw Normal View History

2019-09-14 16:30:16 +00:00
using System;
using UnityEngine;
2019-09-14 19:42:44 +00:00
public class PlayerMainController : MonoBehaviour
2019-09-14 16:30:16 +00:00
{
[Header("TEST")]
public string jsonData = "";
protected void Start() {
Debug.Log("Testing ActInit with public jsonData...");
LoadAct(jsonData);
}
[Header("Objects")]
public ActController currentAct;
[Header("Prefabs")]
public GameObject drawingControllerPrefab;
public GameObject typingControllerPrefab;
[Serializable]
public class InvalidJsonDataException : Exception {
public readonly string jsonData;
public InvalidJsonDataException(string jsonData) {
this.jsonData = jsonData;
}
};
public void LoadAct(string jsonData) {
2019-09-15 22:28:36 +00:00
ActSettings unknownSettings = JsonUtility.FromJson<ActSettings>(jsonData);
2019-09-14 16:30:16 +00:00
if(unknownSettings.type == "Drawing") {
currentAct = Instantiate(drawingControllerPrefab, transform).GetComponent<DrawingController>();
2019-09-15 22:28:36 +00:00
currentAct.settings = JsonUtility.FromJson<DrawingSettings>(jsonData);
2019-09-14 16:30:16 +00:00
}
else if (unknownSettings.type == "Typing") {
currentAct = Instantiate(typingControllerPrefab, transform).GetComponent<TypingController>();
2019-09-15 22:28:36 +00:00
currentAct.settings = JsonUtility.FromJson<TypingSettings>(jsonData);
2019-09-14 16:30:16 +00:00
}
else {
throw new InvalidJsonDataException(jsonData);
}
}
}