spawn soul objects

master
Jordan Orelli 5 years ago
parent ca4015a4d4
commit a59076aefd

@ -15,3 +15,5 @@ MonoBehaviour:
host: cdm.jordanorelli.com
path: kloam
port: 9001
soulPrefab: {fileID: 923676258187016684, guid: 80b838e4e488ed64b9ac358ee000f444,
type: 3}

@ -15,6 +15,7 @@ public class Networking : ScriptableObject {
public string host;
public string path;
public int port;
public GameObject soulPrefab;
private ClientWebSocket sock;
private Task writeTask;
@ -83,22 +84,30 @@ public class Networking : ScriptableObject {
if (readTask != null) {
return;
}
Debug.Log("checking for messages");
readTask = sock.ReceiveAsync(readBuffer, CancellationToken.None);
WebSocketReceiveResult result = await readTask;
readTask = null;
Debug.LogFormat("received message: {0}", result);
Debug.LogFormat("Readbuffer count: {0} offset: {1}", readBuffer.Count, readBuffer.Offset);
string msg = Encoding.UTF8.GetString(readBuffer.Array, 0, result.Count);
string[] parts = msg.Split(new char[]{' '}, 2);
if (parts.Length != 2) {
Debug.LogFormat("dunno how to handle this msg: {0}", msg);
return;
}
Debug.LogFormat("first: {0} second: {1}", parts[0], parts[1]);
switch (parts[0]) {
case "spawn-soul":
Debug.LogFormat("spawn a soul: {0}", parts[1]);
SpawnSoul ss = JsonUtility.FromJson<SpawnSoul>(parts[1]);
GameObject soul = Instantiate(soulPrefab, ss.position, Quaternion.identity);
SoulController sc = soul.GetComponent<SoulController>();
sc.playerName = ss.playerName;
break;
case "tick":
break;
default:
Debug.LogFormat("also can't handle this one: {0} {1}", parts[0], parts[1]);
break;
}
}
@ -128,6 +137,11 @@ public class Networking : ScriptableObject {
public Vector3 position;
}
private struct SpawnSoul {
public string playerName;
public Vector3 position;
}
private struct Login {
public int seq;
public string cmd;

@ -55,15 +55,6 @@ public class PlayerController : MonoBehaviour {
void OnDestroy() {
Debug.Log("I'm dead");
// hud.gameObject.SetActive(true);
// HudController c = hud.gameObject.GetComponent<HudController>();
// if (c) {
// c.SetDead(true);
// }
if (!quitting) {
GameObject soul = Instantiate(soulPrefab, transform.position + Vector3.up * 0.5f, transform.rotation);
soul.GetComponent<SoulController>().playerName = "fartface";
}
}
void OnCollisionEnter(Collision other) {
@ -78,7 +69,7 @@ public class PlayerController : MonoBehaviour {
Destroy(other.gameObject);
}
if (other.CompareTag("Fatal")) {
networking.SendDeath(transform.position);
networking.SendDeath(transform.position + Vector3.up * 0.5f);
Destroy(gameObject);
}
}

@ -4,5 +4,11 @@
EditorBuildSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Scenes: []
m_Scenes:
- enabled: 1
path: Assets/Scenes/MainMenu.unity
guid: 103d28e20d0cb60468b5860908d1e310
- enabled: 1
path: Assets/Scenes/MainLevel.unity
guid: aa17d21b7ba6c554ba0c36d4aa39bedd
m_configObjects: {}

Loading…
Cancel
Save