Esempio n. 1
0
        public IEnumerator ServerCountdownCoroutine()
        {
            //---
            var battleState = BattleState.Create();

            battleServerContext = new BattleServerContext(battleState);
            NetworkServer.Spawn(battleState.gameObject);
            //---

            float remainingTime = prematchCountdown;
            int   floorTime     = Mathf.FloorToInt(remainingTime);

            while (remainingTime > 0)
            {
                yield return(null);

                remainingTime -= Time.deltaTime;
                int newFloorTime = Mathf.FloorToInt(remainingTime);

                if (newFloorTime != floorTime)
                {//to avoid flooding the network of message, we only send a notice to client when the number of plain seconds change.
                    floorTime = newFloorTime;

                    for (int i = 0; i < lobbySlots.Length; ++i)
                    {
                        if (lobbySlots[i] != null)
                        {//there is maxPlayer slots, so some could be == null, need to test it before accessing!
                            (lobbySlots[i] as LobbyPlayer).RpcUpdateCountdown(floorTime);
                        }
                    }
                }
            }

            for (int i = 0; i < lobbySlots.Length; ++i)
            {
                if (lobbySlots[i] != null)
                {
                    (lobbySlots[i] as LobbyPlayer).RpcUpdateCountdown(0);
                }
            }

            ServerChangeScene(playScene);
        }