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
|
|
|
|
{
|
2019-09-16 15:34:22 +00:00
|
|
|
|
[Header("WIP")]
|
|
|
|
|
public string address = "127.0.0.1:44444";
|
2019-09-17 15:27:49 +00:00
|
|
|
|
public string playerName = "Steffo";
|
|
|
|
|
|
2019-09-16 15:34:22 +00:00
|
|
|
|
void Start() {
|
2019-09-17 15:27:49 +00:00
|
|
|
|
ConnectToServer(address, playerName);
|
2019-09-16 15:34:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-14 16:30:16 +00:00
|
|
|
|
[Header("Objects")]
|
2019-09-16 15:34:22 +00:00
|
|
|
|
public ActController currentAct = null;
|
2019-09-14 16:30:16 +00:00
|
|
|
|
|
|
|
|
|
[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
|
|
|
|
|
2019-09-17 15:27:49 +00:00
|
|
|
|
public void ConnectToServer(string address, string playerName) {
|
2019-09-16 15:34:22 +00:00
|
|
|
|
NetworkClient.RegisterHandler<NetMessage.Connect.PlayerJoinSuccessful>(OnPlayerJoinSuccessful);
|
|
|
|
|
NetworkClient.RegisterHandler<NetMessage.Game.Settings>(OnGameSettings);
|
|
|
|
|
NetworkClient.RegisterHandler<NetMessage.Game.Start>(OnGameStart);
|
|
|
|
|
NetworkClient.RegisterHandler<NetMessage.Game.End>(OnGameEnd);
|
|
|
|
|
NetworkClient.RegisterHandler<NetMessage.Act.Init>(OnActInit);
|
|
|
|
|
NetworkClient.RegisterHandler<NetMessage.Act.Start>(OnActStart);
|
|
|
|
|
NetworkClient.RegisterHandler<NetMessage.Act.End>(OnActEnd);
|
2019-09-17 15:27:49 +00:00
|
|
|
|
NetworkClient.Connect(address);
|
|
|
|
|
|
|
|
|
|
NetMessage.Connect.PlayerJoin playerJoin = new NetMessage.Connect.PlayerJoin {
|
|
|
|
|
playerName = playerName
|
|
|
|
|
};
|
|
|
|
|
NetworkClient.Send<NetMessage.Connect.PlayerJoin>(playerJoin);
|
2019-09-15 23:07:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-16 15:34:22 +00:00
|
|
|
|
protected void OnPlayerJoinSuccessful(NetworkConnection connection, NetMessage.Connect.PlayerJoinSuccessful message) {}
|
|
|
|
|
|
|
|
|
|
protected void OnGameSettings(NetworkConnection connection, NetMessage.Game.Settings message) {}
|
|
|
|
|
|
|
|
|
|
protected void OnGameStart(NetworkConnection connection, NetMessage.Game.Start message) {}
|
|
|
|
|
|
|
|
|
|
protected void OnGameEnd(NetworkConnection connection, NetMessage.Game.End message) {}
|
|
|
|
|
|
|
|
|
|
protected void OnActInit(NetworkConnection connection, NetMessage.Act.Init message) {
|
2019-09-15 23:07:27 +00:00
|
|
|
|
LoadAct(message.settings);
|
2019-09-16 15:34:22 +00:00
|
|
|
|
currentAct.ActInit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void OnActStart(NetworkConnection connection, NetMessage.Act.Start message) {
|
|
|
|
|
currentAct.ActStart();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void OnActEnd(NetworkConnection connection, NetMessage.Act.End message) {
|
|
|
|
|
currentAct.ActEnd();
|
|
|
|
|
//SEND RESULTS HERE
|
|
|
|
|
|
|
|
|
|
//test this
|
|
|
|
|
Destroy(currentAct);
|
2019-09-15 23:07:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-14 16:30:16 +00:00
|
|
|
|
}
|