private void SpawnGamepads()
    {
        if (m_UIGamepadPrefab == null)
        {
            return;
        }

        if (m_ControllersGrid == null)
        {
            return;
        }

        if (m_ControllersRoot == null)
        {
            return;
        }

        List <int> playersKeys = tnGameData.GetPlayersKeysMain();

        if (playersKeys == null)
        {
            return;
        }

        int playersCount = InputSystem.numPlayersMain;
        int max          = Mathf.Min(playersCount, playersKeys.Count);

        for (int index = 0; index < max; ++index)
        {
            ControllerAnchor anchor = m_ControllersGrid.GetAnchorByIndex(index);
            if (anchor != null)
            {
                int          playerId   = playersKeys[index];
                tnPlayerData playerData = tnGameData.GetPlayerDataMain(playerId);
                if (playerData != null)
                {
                    tnUIGamepad gamepad = GameObject.Instantiate <tnUIGamepad>(m_UIGamepadPrefab);
                    gamepad.transform.SetParent(m_ControllersRoot, false);

                    gamepad.SetPlayerId(playerId);
                    gamepad.SetPlayerName(playerData.playerInputName);

                    gamepad.SetDefaultAnchor(anchor);

                    gamepad.gameObject.name = playerData.name + "_Pad";
                    Color color = playerData.color;
                    gamepad.SetColor(color, true);

                    gamepad.SetTeamsManagers(m_TeamA, m_TeamB);

                    gamepad.hasFocus = false;

                    m_Gamepads.Add(gamepad);
                }
            }
        }
    }
    private void MoveRight()
    {
        if (m_CurrentState == DeviceState.Right || m_CurrentState == DeviceState.Disabled)
        {
            return;
        }

        if (m_CurrentState == DeviceState.Center)
        {
            GridEntry gridEntry = GetTeamBFirstAvailableEntry();
            if (gridEntry != null)
            {
                ControllerAnchor controllerAnchor = gridEntry.controllerAnchor;

                if (controllerAnchor == null)
                {
                    return;
                }

                RectTransform targetTransform = controllerAnchor.rectTransform;
                if (targetTransform != null)
                {
                    m_GridEntry = gridEntry;

                    gridEntry.device = this;
                    m_CurrentState   = DeviceState.Right;

                    m_TargetPosition = targetTransform.position;
                    m_StartPosition  = rectTransform.position;

                    m_Timer = 0f;

                    m_IsInTransition = true;
                }
            }
        }
        else
        {
            if (m_CurrentState == DeviceState.Left)
            {
                m_GridEntry.device = null;
                m_GridEntry        = null;

                m_CurrentState = DeviceState.Center;

                m_TargetPosition = defaultPosition;
                m_StartPosition  = rectTransform.position;

                m_Timer = 0f;

                m_IsInTransition = true;
            }
        }
    }
Exemple #3
0
    private void InternalCreateGrid()
    {
        if (m_GridPivotPrefab == null)
        {
            return;
        }

        CreateBotsPool();

        CheckLayoutConfig();

        m_GridEntries = new List <GridEntry>();
        m_Bots        = new List <tnUIBot>();

        RectTransform rectTransform = (RectTransform)transform;

        float totalWidth  = rectTransform.sizeDelta.x - m_Layout.distanceFromLeft - m_Layout.distanceFromRight;
        float totalHeigth = rectTransform.sizeDelta.y - m_Layout.distanceFromTop - m_Layout.distanceFromBot;

        int rows = m_EntriesCount / m_Layout.controllersPerRow;

        rows += (m_EntriesCount % m_Layout.controllersPerRow != 0) ? 1 : 0;
        int columns = m_Layout.controllersPerRow;

        float slotDistanceX = (totalWidth / columns);
        float slotDistanceY = (totalHeigth / rows);

        float firstX = slotDistanceX / 2f;
        float firstY = slotDistanceY / 2f;

        for (int index = 0; index < m_EntriesCount; ++index)
        {
            int row    = index / columns;
            int column = index % columns;

            RectTransform rt = GameObject.Instantiate(m_GridPivotPrefab);
            rt.gameObject.name = "Anchor_" + index;
            rt.SetParent(rectTransform);

            float x = m_Layout.distanceFromLeft + firstX + column * slotDistanceX;
            float y = -m_Layout.distanceFromTop - firstY - row * slotDistanceY;

            rt.anchoredPosition = new Vector2(x, y);

            ControllerAnchor controllerAnchor = new ControllerAnchor(rt);
            controllerAnchor.SetWidth(slotDistanceX);
            controllerAnchor.SetHeight(slotDistanceY);

            GridEntry gridEntry = new GridEntry(controllerAnchor);
            m_GridEntries.Add(gridEntry);
        }
    }
    private void SpawnPhonesAnchors()
    {
        if (m_GridPivotPrefab == null || m_Root == null || m_Anchors == null)
        {
            return;
        }

        int playersCount = WiFiInputSystem.playersCountMain;

        float width  = m_Root.sizeDelta.x - m_Layout.phoneDistanceFromLeft - m_Layout.phoneDistanceFromRight;
        float height = m_Root.sizeDelta.y - m_Layout.padDistanceFromTop - m_Layout.padPanelHeight - m_Layout.distancePadsPhones - m_Layout.phoneDistanceFromBot;

        float startY = -m_Layout.padDistanceFromTop - m_Layout.padPanelHeight - m_Layout.distancePadsPhones;

        int rows = playersCount / m_Layout.phonesPerRow;

        rows += (playersCount % m_Layout.phonesPerRow != 0) ? 1 : 0;
        int columns = m_Layout.phonesPerRow;

        float phoneWidth  = (width - (m_Layout.phoneXSpacing * (columns + 1))) / columns;
        float phoneHeight = (height - (m_Layout.phoneYSpacing * (rows + 1))) / rows;

        for (int playerIndex = 0; playerIndex < playersCount; ++playerIndex)
        {
            int row    = playerIndex / columns;
            int column = playerIndex % columns;

            RectTransform pivot = GameObject.Instantiate(m_GridPivotPrefab);
            pivot.gameObject.name = "Anchor_" + playerIndex;
            pivot.SetParent(m_Root);

            float x = m_Layout.phoneDistanceFromLeft + ((column + 1) * m_Layout.phoneXSpacing) + (column * phoneWidth) + (phoneWidth / 2f);
            float y = startY - ((row + 1) * m_Layout.phoneYSpacing) - (row * phoneHeight) - (phoneHeight / 2f);

            pivot.anchoredPosition = new Vector2(x, y);

            ControllerAnchor anchor = new ControllerAnchor(pivot);
            anchor.SetWidth(phoneWidth);
            anchor.SetHeight(phoneHeight);

            m_Anchors.Add(anchor);
        }
    }
    private void SpawnPhones()
    {
        if (m_UIPhonePrefab == null)
        {
            return;
        }

        if (m_ControllersGrid == null)
        {
            return;
        }

        if (m_ControllersRoot == null)
        {
            return;
        }

        List <int> playersKeys = tnGameData.GetPlayersKeysMain();

        if (playersKeys == null)
        {
            return;
        }

        int playersCount = WiFiInputSystem.playersCountMain;
        int max          = Mathf.Min(playersCount, playersKeys.Count);

        for (int index = 0; index < max; ++index)
        {
            ControllerAnchor anchor = m_ControllersGrid.GetAnchorByIndex(index + m_Gamepads.Count);
            if (anchor != null)
            {
                int playerIndex = index + m_Gamepads.Count;

                if (playerIndex >= playersKeys.Count)
                {
                    continue;
                }

                int          playerId   = playersKeys[playerIndex];
                tnPlayerData playerData = tnGameData.GetPlayerDataMain(playerId);
                if (playerData != null)
                {
                    tnUIPhone phone = GameObject.Instantiate <tnUIPhone>(m_UIPhonePrefab);
                    phone.transform.SetParent(m_ControllersRoot, false);

                    phone.SetPlayerId(playerId);
                    phone.SetPlayerName(playerData.wifiPlayerInputName);

                    phone.SetDefaultAnchor(anchor);

                    phone.gameObject.name = playerData.name + "_Phone";
                    Color color = playerData.color;
                    phone.SetColor(color, true);

                    phone.SetTeamsManagers(m_TeamA, m_TeamB);

                    phone.hasFocus = false;

                    m_Phones.Add(phone);
                }
            }
        }
    }
Exemple #6
0
    // CTOR

    public GridEntry(ControllerAnchor i_ControllerAnchor)
    {
        m_ControllerAnchor = i_ControllerAnchor;
    }
    public void SetDefaultAnchor(ControllerAnchor i_Anchor)
    {
        m_DefaultAnchor = i_Anchor;

        ResetPosition();
    }