diff --git a/Assets/Networking.asset b/Assets/Networking.asset index 71cdf42..7fb218c 100644 --- a/Assets/Networking.asset +++ b/Assets/Networking.asset @@ -15,3 +15,5 @@ MonoBehaviour: host: cdm.jordanorelli.com path: kloam port: 9001 + soulPrefab: {fileID: 923676258187016684, guid: 80b838e4e488ed64b9ac358ee000f444, + type: 3} diff --git a/Assets/Scripts/Networking.cs b/Assets/Scripts/Networking.cs index 50c13bb..0f3bff7 100644 --- a/Assets/Scripts/Networking.cs +++ b/Assets/Scripts/Networking.cs @@ -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(parts[1]); + GameObject soul = Instantiate(soulPrefab, ss.position, Quaternion.identity); + SoulController sc = soul.GetComponent(); + 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; diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index 093b836..3659869 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -55,15 +55,6 @@ public class PlayerController : MonoBehaviour { void OnDestroy() { Debug.Log("I'm dead"); - // hud.gameObject.SetActive(true); - // HudController c = hud.gameObject.GetComponent(); - // if (c) { - // c.SetDead(true); - // } - if (!quitting) { - GameObject soul = Instantiate(soulPrefab, transform.position + Vector3.up * 0.5f, transform.rotation); - soul.GetComponent().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); } } diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index 98b932a..215c56e 100644 --- a/ProjectSettings/EditorBuildSettings.asset +++ b/ProjectSettings/EditorBuildSettings.asset @@ -1,8 +1,14 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!1045 &1 -EditorBuildSettings: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Scenes: [] - m_configObjects: {} +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1045 &1 +EditorBuildSettings: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Scenes: + - enabled: 1 + path: Assets/Scenes/MainMenu.unity + guid: 103d28e20d0cb60468b5860908d1e310 + - enabled: 1 + path: Assets/Scenes/MainLevel.unity + guid: aa17d21b7ba6c554ba0c36d4aa39bedd + m_configObjects: {}