コード例 #1
0
    private void Update()
    {
        // Should disable
        bool shouldDisable = !IsEveryoneReady();

        if (startButton.isDisabled != shouldDisable)
        {
            SetDisabled(shouldDisable);
        }
        // Get child
        if (playerTable.childCount > 0)
        {
            Transform  child = playerTable.GetChild(0);
            PlayerCell cell  = child.GetComponent <PlayerCell>();
            if (_btnType != cell.inputButton)
            {
                _btnType = cell.inputButton;
                homeButton.SetInputPlayer(_btnType == PlayerCell.PlayerInputButton.Home ? 0 : -1);
                startButton.SetInputPlayer(_btnType == PlayerCell.PlayerInputButton.Start ? 0 : -1);
            }
        }
    }
コード例 #2
0
    // Load table
    private void ReloadTable()
    {
        // Unload all cells
        for (int c = 0; c < playerTable.childCount; c++)
        {
            Transform child = playerTable.GetChild(c);
            child.gameObject.SetActive(false);
        }

        // Get player count
        int players = GameManager.instance.players.Count;
        int cells   = players + (players != GameManager.instance.gameData.maxPlayers ? 1 : 0);

        // Get rows & columns
        int rows    = Mathf.CeilToInt((float)cells / (float)playersPerRow);
        int columns = Mathf.Min(playersPerRow, cells);

        // Get cell size
        float cellHeight = (playerTable.rect.height - (rows > 1 ? (rows - 1) * rowMargin : 0f)) / rows;
        float cellWidth  = (playerTable.rect.width - (columns > 1 ? (columns - 1) * columnMargin : 0f)) / columns;

        // Final row offset
        float header = 0f;
        int   open   = (cells % columns);

        if (cells > columns && open > 0)
        {
            header = open * cellWidth + (open > 1 ? (open - 1) * columnMargin : 0f);
            header = (playerTable.rect.width - header) / 2f;
        }

        // Load a cell for each player
        int column = 0; int row = 0;

        for (int p = 0; p < players; p++)
        {
            // Get child transform
            RectTransform child = p < playerTable.childCount ? playerTable.GetChild(p).GetComponent <RectTransform>() : null;
            if (child == null)
            {
                child = Instantiate <GameObject>(playerCell.gameObject).GetComponent <RectTransform>();
                child.SetParent(playerTable);
                child.localPosition = Vector3.zero;
                child.localRotation = Quaternion.identity;
                child.localScale    = Vector3.one;
            }
            child.gameObject.SetActive(true);

            // Adjust position & size
            child.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, (row == rows - 1 ? header : 0f) + column * (cellWidth + columnMargin), cellWidth);
            child.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, row * (cellHeight + rowMargin), cellHeight);
            column++;
            if (column >= columns)
            {
                column = 0;
                row++;
            }

            // Setup cell
            ReloadCell(p);
        }

        // Adjust cta
        if (cta != null)
        {
            // Hit max players
            if (players == GameManager.instance.gameData.maxPlayers)
            {
                cta.gameObject.SetActive(false);
            }
            // Use cta
            else
            {
                // Enable
                cta.gameObject.SetActive(true);

                // Same as cells
                cta.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, (row == rows - 1 ? header : 0f) + column * (cellWidth + columnMargin), cellWidth);
                cta.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, row * (cellHeight + rowMargin), cellHeight);
            }
        }

        // Set disabled
        _btnType = (PlayerCell.PlayerInputButton)(-1);
        SetDisabled(true);
    }