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

52 lines
1.9 KiB
C#
Raw Normal View History

2019-09-14 16:30:16 +00:00
using System;
using UnityEngine;
2019-09-15 23:07:27 +00:00
using Mirror;
2019-09-14 16:30:16 +00:00
2019-09-14 19:42:44 +00:00
public class PlayerMainController : MonoBehaviour
2019-09-14 16:30:16 +00:00
{
[Header("Objects")]
public ActController currentAct;
[Header("Prefabs")]
public GameObject drawingControllerPrefab;
public GameObject typingControllerPrefab;
[Serializable]
2019-09-15 23:07:27 +00:00
public class InvalidActTypeException : Exception {
public readonly string actType;
2019-09-14 16:30:16 +00:00
2019-09-15 23:07:27 +00:00
public InvalidActTypeException(string actType) {
this.actType = actType;
2019-09-14 16:30:16 +00:00
}
};
2019-09-15 23:07:27 +00:00
public void LoadAct(ActSettings settings) {
if(settings.type == "Drawing") {
2019-09-14 16:30:16 +00:00
currentAct = Instantiate(drawingControllerPrefab, transform).GetComponent<DrawingController>();
}
2019-09-15 23:07:27 +00:00
else if (settings.type == "Typing") {
2019-09-14 16:30:16 +00:00
currentAct = Instantiate(typingControllerPrefab, transform).GetComponent<TypingController>();
}
2019-09-15 23:07:27 +00:00
else throw new InvalidActTypeException(settings.type);
currentAct.settings = settings;
2019-09-14 16:30:16 +00:00
}
2019-09-15 23:07:27 +00:00
public void ConnectToServer(string address) {
NetworkClient.Connect(address);
NetworkClient.RegisterHandler<NetMessages.ConnectionSuccessfulResponse>(OnConnectionSuccessful);
NetworkClient.RegisterHandler<NetMessages.GameStartMessage>(OnGameStart);
NetworkClient.RegisterHandler<NetMessages.ActSettingsMessage>(OnActSettings);
NetworkClient.RegisterHandler<NetMessages.ActEndNotification>(OnActEnd);
}
public void OnConnectionSuccessful(NetworkConnection connection, NetMessages.ConnectionSuccessfulResponse message) {}
public void OnGameStart(NetworkConnection connection, NetMessages.GameStartMessage message) {}
public void OnActEnd(NetworkConnection connection, NetMessages.ActEndNotification message) {}
public void OnActSettings(NetworkConnection connection, NetMessages.ActSettingsMessage message) {
LoadAct(message.settings);
}
2019-09-14 16:30:16 +00:00
}