Esempio n. 1
0
        /// <summary>
        /// Called when the gamestate is deactivated. Returns IObservable<bool>. Gamestate is marked 'closing' until this OnExit-Observable emits true.
        /// This gives you time to properly end/stop the GameState before the next gamestate can be activated
        /// </summary>
        /// <returns></returns>
        public virtual IObservable <bool> DoOnExit()
        {
            CurrentState = GSStatus.closing;

            _eventService.Publish(evtBeforeExit);

            // stop tick
            if (tickDisposable != null)
            {
                tickDisposable.Dispose();
                tickDisposable = null;
            }
            // clear the ticklist
            OnTick.Clear();

            AllowedToTick = false;

            // start the OnExit-Process
            return(OnExit.RxExecute().Finally(() => {
                // clear all disposables connected to this gamestate
                gamestateDisposable.Clear();

                _eventService.Publish(evtAfterExit);
            }));
        }
Esempio n. 2
0
    private void OnApplicationQuit()
    {
        SetOnApplicationQuitSettings();

        rxShutDown
        .RxExecute()
        .Take(1)
        .Subscribe(_ => {
            Debug.Log("Shutdown complete!");
        });

        /*if (eventService != null) {
         *  eventService.Publish(new Events.OnApplicationQuit());
         * }  */
    }
Esempio n. 3
0
    protected virtual void Start()
    {
        //Resolve disposableManager
        dManager = Container.Resolve <DisposableManager>();
        //Let the program know, that Kernel has finished loading


        // first start rxStartup-queue
        // if this is finished, start initial gamestate
        rxStartup
        .RxExecute()
        .SelectMany(_ => {
            string initialGameStateName = GetInitialGamestateName();
            Service.GameStateService.GSContext initialGameStateCtx = GetInitialGamestateContext();
            if (initialGameStateName == null)
            {
                Debug.LogWarning("No inital gamestate specified!");
                return(Observable.Return(true));
            }
            else
            {
                Service.GameStateService.IGameStateService gameStateService = Container.Resolve <Service.GameStateService.IGameStateService>();
                Service.GameStateService.GameState initialGameState         = gameStateService.GetGameState(initialGameStateName);
                if (initialGameState == null)
                {
                    Debug.LogWarning("Could not find initial gamestate with name:" + initialGameStateName);
                    return(Observable.Return(true));
                }
                return(gameStateService.StartGameState(initialGameState, initialGameStateCtx).Do(__ => { Debug.Log("Started initial gamestate:" + initialGameStateName); }));
            }
        })
        .Last()
        .Take(1)
        .Subscribe(_ => {
            KernelReady = true;
            Debug.LogWarning("Startup done!");
            OnKernelReady();
        });
    }
Esempio n. 4
0
        /// <summary>
        /// Called when gamestate is activated. Returns IObservable<bool>. Gamestate is marked as 'starting' until the OnEnter-Observable emits a true-element (and then is in running-state)
        /// Override this method with gamestate startup-logic (if needed)
        /// </summary>
        /// <returns></returns>
        public IObservable <bool> DoOnEnter(GSContext ctx = null)
        {
            if (entityManager == null)
            {
                entityManager = Kernel.Instance.Container.Resolve <ECS.IEntityManager>();
            }

            this.currentContext = ctx == null?CreateDefaultContext() : ctx;

            CurrentState = GSStatus.starting;

            // fire hook
            _eventService.Publish(evtBeforeEnter);

            // if not overriden, exit immediately
            return(OnEnter.RxExecute().Finally(() => {
                CurrentState = GSStatus.running;

                // fire hook
                _eventService.Publish(evtAfterEnter);

                AllowedToTick = true;

                // finally the gamestate is started
                tickDisposable = Observable.EveryUpdate()
                                 .Subscribe(_ => {
                    // tell that the we start the tick. last chance to react
                    // TODO: performance? (i guess its ok, but 2 msgs per frame,...should be ok. yes?)
                    _eventService.Publish(evtBeforeTick);

                    ExecuteTickList();

                    // tell that the tick is finished
                    _eventService.Publish(evtAfterTick);
                });

                gamestateDisposable.Add(tickDisposable); // add tick also to gamestate just to be sure the gamestate's tick gets disposed when the gamestate is left
            }));
        }