Пример #1
0
    private void HandlePlayerConnected(RealmEventBase playerConnectedEventData)
    {
        PlayerConnectedEvent playerConnectedEvent = playerConnectedEventData as PlayerConnectedEvent;

        string playerSessionId = playerConnectedEvent.playerSessionId;
        string playerId        = playerConnectedEvent.playerId;

        Debug.Log("Player Connected {playerId: " + playerId + ", playerSessionId: " + playerSessionId);

        Vector3Int spawnPosition = RealmStateManager.GetRealmState().GetMapState().GetSpawnPosition();
        GameObject playerAvatar  = Instantiate(playerAvatarPrefab, mapGrid.CellToWorld(spawnPosition), Quaternion.identity);

        playerAvatar.GetComponent <Player>().playerId = playerId;

        IReadPlayerState playerState = RealmStateManager.GetRealmState().GetPlayerState(playerId);
        Color            playerColor = new Color();

        if (ColorUtility.TryParseHtmlString(playerState.GetColor(), out playerColor))
        {
            playerAvatar.GetComponent <MeshRenderer>().material.color = playerColor;
        }

        if (playerGameObjects.ContainsKey(playerId))
        {
            Debug.LogError("Player with ID attmempted to connect twice: " + playerId);
        }
        playerGameObjects.Add(playerId, playerAvatar);
    }
Пример #2
0
    private void HandlePlayerMove(RealmEventBase baseEvent)
    {
        PlayerMoveEvent playerMoveEvent = baseEvent as PlayerMoveEvent;
        Vector2Int      playerPosition  = RealmStateManager.GetRealmState().GetPlayerState(playerMoveEvent.playerId).GetPosition();
        IReadHexState   hexState        = RealmStateManager.GetRealmState().GetMapState().GetHexState(playerPosition);

        if (hexState.IsVisible())
        {
            if (hexState.GetTerrain().Equals("GRASS"))
            {
                instance.tilemap.SetTile((Vector3Int)playerPosition, instance.grassTile);
            }
            else
            {
                instance.tilemap.SetTile((Vector3Int)playerPosition, instance.waterTile);
            }
        }
    }