Exemplo n.º 1
0
    public void UpdateGrid(string player_id, GridState state)
    {
        bool      isMe       = (player_id == myID);
        bool      isWatching = GameManager.GetInstance().isWatching;
        Transform spawnPosition;

        if (isMe)
        {
            spawnPosition = grid1SpawnPos;
        }
        else
        {
            if (isWatching && grid1SpawnPos.childCount <= grid2SpawnPos.childCount)
            {
                spawnPosition = grid1SpawnPos;
            }
            else
            {
                spawnPosition = grid2SpawnPos;
            }
        }

        GridBase target = null;

        grids.TryGetValue(player_id, out target);
        if (target == null)
        {
            string player_nick = state.player_nick;
            target = Instantiate(gridPrefab, spawnPosition.position, Quaternion.identity, spawnPosition);
            target.gameObject.name = player_nick;
            if (isMe)
            {
                target.transform.tag = Constants.PLACEABLE_TAG;
                GameManager.GetInstance().myColor = colors[grids.Count];
            }
            SpriteRenderer render = target.GetComponent <SpriteRenderer>();

            target.color          = colors[grids.Count];
            grids[player_id]      = target;
            nickToID[player_nick] = player_id;
            if (!isMe)
            {
                ActiveGrid(player_nick);
            }
        }
        if (isWatching)
        {
            grids[player_id].UpdateStateFirstTime(state);
        }
        else
        {
            grids[player_id].UpdateState(state);
        }
    }