/// <summary> /// Merges data into your object. (no deep copy) /// </summary> /// <param name="incoming"></param> /// <param name="onlyCopyPersistedData"></param> public void MergeDataFrom(GSContext incoming, bool onlyCopyPersistedData = false) { if (incoming == null) { UnityEngine.Debug.LogError("Trying to merge from null! Type: GSContext"); return; } // base.MergeDataFrom(incoming, onlyCopyPersistedData); }
public override IObservable <bool> StartGameState(GameState gamestate, GSContext ctx = null) { var oldGameState = CurrentGameState; CurrentGameState = null; List <IObservable <bool> > startupSequence = new List <IObservable <bool> >(); if (oldGameState != null) { // if there is a gamestate already active, first make sure it's onExit-observable is finished startupSequence.Add(oldGameState.DoOnExit()); } startupSequence.Add(Observable.Return(true).Do(_ => { // make sure the new gamestate is set before OnEnter-calls are executed CurrentGameState = gamestate; })); startupSequence.Add(gamestate.DoOnEnter(ctx)); return(Observable.Concat(startupSequence).Last()); }
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(); }); }
/// <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 })); }
public abstract IObservable <bool> StartGameState(GameState gamestate, GSContext ctx = null);