Esempio n. 1
0
    void Update()
    {
        if (_lockFlag)
        {
            return;
        }
        if (Input.GetKeyDown(KeyCode.Return) && JoinObjects.Count > 0)
        {
            GoToGame();
        }

        int i = 0;

        while (i < playersConnected)
        {
            TeamUtility.IO.PlayerID playerId = (TeamUtility.IO.PlayerID)System.Enum.GetValues(typeof(TeamUtility.IO.PlayerID)).GetValue(i);
            if (InputMng.GetButtonDown("Button A", playerId))
            {
                PlayerInfo info = _holder.playersInfos.Find(infs => infs.playerNumber == i);
                if (info != null)
                {
                    _holder.RemovePlayerInfo(info);
                    GameObject hideGO = JoinObjects.Find(objs => objs.name == joinKeysPrefixes[i]);
                    if (hideGO)
                    {
                        hideGO.SetActive(false);
                    }
                }
                else
                {
                    //Color col = UnityEngine.Random.ColorHSV(0, 1, 1, 1, 1, 1);
                    Color col = PlayerColors[i];
                    _holder.AddPlayerInfo(new PlayerInfo(col, i));
                    GameObject showGO = JoinObjects.Find(objs => objs.activeSelf == false);
                    if (showGO)
                    {
                        showGO.SetActive(true);
                        showGO.name = joinKeysPrefixes[i];
                        ColorSetter.UpdateModelColor(showGO, col);
                    }
                }
                PlayMenuClick();
            }
            i++;
        }
        foreach (var player in _holder.playersInfos)
        {
            TeamUtility.IO.PlayerID playerId = (TeamUtility.IO.PlayerID)System.Enum.GetValues(typeof(TeamUtility.IO.PlayerID))
                                               .GetValue(player.playerNumber);
            if (InputMng.GetButtonDown("Start", playerId))
            {
                player.ready = !player.ready;
                GameObject readyGOParent = JoinObjects.Find(objs => objs.name == joinKeysPrefixes[player.playerNumber]);
                readyGOParent.transform.Find("ReadyFlag").gameObject.SetActive(player.ready);
                PlayMenuClick();
            }
        }

        bool _allReady = true;

        if (_holder.playersInfos.Count > 1)
        {
            foreach (var player in _holder.playersInfos)
            {
                if (!player.ready)
                {
                    _allReady = false;
                }
            }
        }
        else
        {
            _allReady = false;
        }

        if (_allReady)
        {
            _lockFlag = true;
            Invoke("GoToGame", 0.5f);
        }
    }