Exemplo n.º 1
0
        public override void Destroy()
        {
            base.Destroy();
            _countDownTimer.OnTimeLimitHandler         -= Cmd_OnCountDownTimeout;
            _startIntermissionTimer.OnTimeLimitHandler -= Cmd_OnStartIntermissionTimeout;
            _endIntermissionTimer.OnTimeLimitHandler   -= Cmd_OnRoundEnd;



            //OnIntermissionHandler -=

            //OnCountdownHandler;

            //OnRoundStartHandler;

            //OnRoundEndHandler;

            _instance = null;
        }
Exemplo n.º 2
0
        public static RoundSession Create(
            int countDown,
            float time,
            float countDownTime,
            float intermissionTime,
            int index)
        {
            RoundSession session = NetworkingLibrary.Instance.RoundSession.Create(null);

            session._startIntermissionTime = intermissionTime;
            session._index          = index;
            session._countDown      = countDown;
            session._remainingTime  = time;
            session._countDownTime  = countDownTime;
            session._countDownTimer = new Timer(
                countDownTime,
                start: false,
                repeat: true);

            if (CustomNetworkManager.IsServer)
            {
                session._timerGameObject = ServerTimer.Create(
                    session._remainingTime,
                    start: false).gameObject;
                session.Timer.OnRoundTimeLimitHandler += session.Cmd_OnRoundTimeout;
            }

            session._startIntermissionTimer = new Timer(
                session._startIntermissionTime,
                start: false,
                repeat: false);

            NetworkServer.Spawn(
                session.gameObject,
                NetworkServer.localConnection);

            return(session);
        }
Exemplo n.º 3
0
        protected bool InitState(
            State target,
            params object[] args)
        {
            switch (target)
            {
            case State.Menu:
                OnMenuHandler?.Invoke(true);
                _state = target;
                return(true);

            case State.CharacterSelection:

                GameSession.Instance.SelectedLevelIndex = 0;

                OnCharacterSelectHandler?.Invoke(true);
                _state = target;
                return(true);

            case State.Podium:
                if (RoundSession.Instance != null)
                {
                    RoundSession.Instance.Destroy();
                }
                if (LevelSession.Instance != null)
                {
                    LevelSession.Instance.Destroy();
                }
                Podium.Instance.gameObject.SetActive(true);
                OnPodiumHandler?.Invoke();
                _state = target;
                return(true);

            case State.FinalPodium:
                if (RoundSession.Instance != null)
                {
                    RoundSession.Instance.Destroy();
                }
                if (LevelSession.Instance != null)
                {
                    LevelSession.Instance.Destroy();
                }
                Podium.Instance.gameObject.SetActive(true);
                OnFinalPodiumHandler?.Invoke();
                _state = target;
                return(true);

            case State.LevelSelection:
                if (RoundSession.Instance != null)
                {
                    RoundSession.Instance.Destroy();
                }
                if (LevelSession.Instance != null)
                {
                    LevelSession.Instance.Destroy();
                }

                OnLevelSelectHandler?.Invoke(true);

                GameSession.Instance.SelectedLevelIndex = 0;

                _state = target;

                foreach (Level level in _levels)
                {
                    if (level == null)
                    {
                        continue;
                    }
                    level.gameObject.SetActive(true);
                    level.OnLevelSelect();
                }

                return(true);


            case State.InitRound:

                Podium.Instance.Clear();

                foreach (var player in GameSession.Instance.Players)
                {
                    if (player == null)
                    {
                        continue;
                    }

                    Podium.Instance.Add(
                        player,
                        CharacterLibrary.Instance.Characters[player.CharacterId]);
                }

                Podium.Instance.gameObject.SetActive(false);

                foreach (Level level in _levels)
                {
                    if (level == null)
                    {
                        continue;
                    }
                    level.gameObject.SetActive(false);
                }

                if (CustomNetworkManager.IsServer)
                {
                    //LevelSession.Instance = null;
                    //LevelRoun
                    if (RoundSession.Instance != null)
                    {
                        RoundSession.Instance.Destroy();
                    }
                    if (LevelSession.Instance != null)
                    {
                        LevelSession.Instance.Destroy();
                    }

                    LevelSession.Create();
                    RoundSession.Create(
                        CountDown,
                        Settings.RoundTime.Integer,
                        CountdownTime,
                        IntermissionTime,
                        GameSession.Instance._roundIndex);
                }

                Threading.CoroutineBarrier.Wait(
                    this,
                    () =>
                {
                    OnRoundInitHandler?.Invoke();
                    SetState(State.Round);
                    RoundSession.Instance.StartIntermisison();
                },
                    () => RoundSession.Instance != null && RoundSession.Instance.IsClientStarted,
                    () => LevelSession.Instance != null && LevelSession.Instance.IsClientStarted
                    );

                _state = target;

                return(true);

            case State.Round:

                OnRoundHandler?.Invoke();
                Announcement.Instance.RoundIndex = RoundSession.Instance.Index;

                _state = target;

                return(true);



            case State.Score:

                _state = target;

                return(true);

            default:
                return(false);
            }
        }