コード例 #1
0
    private void OnSpawnPlayers(MatchMessageSpawnShip message)
    {
        Debug.Log("Spawning Player");

        // TODO: more details on setting orientation...can we send a transform?
        // TODO: handle destruction
        // TODO: need to keep track in a list?

        try
        {
            UnityMainThreadDispatcher.Instance().Enqueue(() => {
                Quaternion rot = Quaternion.AngleAxis(message.angle, Vector3.forward);
                Vector3 pos    = new Vector3(message.x, message.y);

                GameObject prefab = message.team ? playerShipPrefabsRed[message.playerIndex] : playerShipPrefabsBlue[message.playerIndex];

                var shipInstance = Instantiate(prefab, pos, rot, transform);
                shipInstance.GetComponent <PlayerController>().SetTeamAndId(message.team, message.elementId);
                playerShips.Add(message.elementId, shipInstance);
            });
        }
        catch (System.Exception e)
        {
            Debug.LogError(e.Message);
        }
    }
コード例 #2
0
    // Spawn Players in sides of the field ##Needs Fixing
    private void SpawnPlayers()
    {
        bool teamAssignment = false;
        int  playerIndex    = 0;

        foreach (var player in MatchMaker.Instance.ReadyPlayers)
        {
            float horizontalPosition = Random.Range(-screenBounds.x, screenBounds.x);
            float verticalPosition   = Random.Range(-screenBounds.y, screenBounds.y);

            MatchMessageSpawnShip element = new MatchMessageSpawnShip(player.UserId, teamAssignment, playerIndex, horizontalPosition,
                                                                      verticalPosition, 0.0f);

            // tell the clients
            MatchCommunicationManager.Instance.SendMatchStateMessage(
                MatchMessageType.PlayerSpawned, element);

            // tell yourself (host)
            MatchCommunicationManager.Instance.SendMatchStateMessageSelf(
                MatchMessageType.PlayerSpawned, element);

            teamAssignment = !teamAssignment;
            playerIndex++;
            playerIndex /= 2;
        }
    }