Example #1
0
    private void onSoulCollected(CollectSoul collected)
    {
        Debug.LogFormat("a soul was collected: {0}", collected);
        string objName = "Souls/" + collected.playerName;

        if (collected.playerName == "")
        {
            objName = "Souls/F**K";
        }
        GameObject soul = GameObject.Find(objName);

        Destroy(soul);

        if (collected.playerName == loginInfo.playerName)
        {
            GameObject currentPlayer = GameObject.Find("Player");
            if (currentPlayer == null)
            {
                GameObject       player = Instantiate(playerPrefab, loginInfo.startPosition, Quaternion.identity);
                Camera           cam    = Camera.main;
                CameraController cc     = cam.GetComponent <CameraController>();
                cc.player = player.transform;
            }
        }
    }
Example #2
0
    private void parseMessage(string msg)
    {
        string[] parts = msg.Split(new char[] { ' ' }, 2);
        if (parts.Length != 2)
        {
            Debug.LogFormat("dunno how to handle this msg: {0}", msg);
            return;
        }
        switch (parts[0])
        {
        case "spawn-soul":
            SpawnSoul spawned = JsonUtility.FromJson <SpawnSoul>(parts[1]);
            onSpawnSoul(spawned);
            break;

        case "soul-collected":
            CollectSoul collected = JsonUtility.FromJson <CollectSoul>(parts[1]);
            onSoulCollected(collected);
            break;

        case "login-result":
            Debug.LogFormat("received message: {0}", msg);
            LoginResult login = JsonUtility.FromJson <LoginResult>(parts[1]);
            onLoginResult(login);
            break;

        case "tick":
            break;

        default:
            Debug.LogFormat("also can't handle this one: {0} {1}", parts[0], parts[1]);
            break;
        }
    }