protected sealed override async UniTask OnExecute()
        {
            var container = await localContextContainer.LoadAssetTaskAsync(LifeTime);

            container.SetValue(_context);
            LifeTime.AddCleanUpAction(() => container.SetValue(null));
        }
Exemple #2
0
        private void InitializeGraphNodes()
        {
            uniNodes.Clear();
            cancellationNodes.Clear();
            inputs.Clear();
            outputs.Clear();

            for (var i = 0; i < Nodes.Count; i++)
            {
                var node = Nodes[i];

                //register graph ports by nodes
                UpdatePortNode(node);

                //stop graph execution, if cancelation node output triggered
                if (node is IGraphCancelationNode cancelationNode)
                {
                    cancellationNodes.Add(cancelationNode);
                }

                //initialize node
                node.Initialize(this);

                //update ports by attributes & another triggers
                node.UpdateNodePorts();

                if (!(node is IUniNode uniNode))
                {
                    continue;
                }

                LifeTime.AddCleanUpAction(uniNode.Exit);
                uniNodes.Add(uniNode);
            }
        }
Exemple #3
0
        protected sealed override UniTask OnExecute()
        {
            if (!Application.isPlaying)
            {
                return(UniTask.CompletedTask);
            }

            _isStateActive   = false;
            _asyncStateProxy = new AsyncContextStateProxy(this, this, this, this);
            _inputPort       = GetPortValue(nameof(input));

            LifeTime.AddCleanUpAction(async() => await _asyncStateProxy.ExitAsync()
                                      .AttachExternalCancellation(LifeTime.TokenSource));

            LogNodeExecutionState();

            //get all actual stat tokens and try to run state
            _inputPort.Receive <IStateToken>()
            .Where(x => _isStateActive == false)
            .Select(async x => await OwnToken(x))
            .Subscribe()
            .AddTo(LifeTime);

            return(UniTask.CompletedTask);
        }
Exemple #4
0
        public async UniTask <IDisposable> ExecuteAsync(TData source)
        {
            if (Application.isPlaying == false)
            {
                return(Disposable.Empty);
            }

            if (_isActive)
            {
                return(this);
            }

            if (source == null)
            {
                return(this);
            }

            _isActive         = true;
            _observableSource = source;

            LifeTime.AddCleanUpAction(() => _observableSource = null);
            LifeTime.AddCleanUpAction(() => _isActive         = false);

            await OnInitialize(source);

            return(this);
        }
Exemple #5
0
 protected override void OnExecute()
 {
     foreach (var reference in assetReferences)
     {
         LifeTime.AddCleanUpAction(() => reference.UnloadReference());
     }
 }
        protected sealed override UniTask OnExecute()
        {
            if (!Application.isPlaying)
            {
                return(UniTask.CompletedTask);
            }

            _isStateActive = false;
            _state         = new RxStateProxy <IContext>(this, this, this, this);
            _inputPort     = GetPortValue(nameof(input));

            LifeTime.AddCleanUpAction(StopState);

            LogNodeExecutionState();

            //get all actual stat tokens and try to run state
            _inputPort.Receive <IStateToken>()
            .Where(x => !_isStateActive)
            .Select(x => (token: x, owned: OwnToken(x)))
            .Where(x => x.owned)
            .Do(x => OnActivateState(x.token))
            .Subscribe()
            .AddTo(LifeTime);

            return(UniTask.CompletedTask);
        }
Exemple #7
0
        /// <summary>
        /// set state functions
        /// </summary>
        /// <param name="updateFunction">update operation</param>
        /// <param name="onInitialize">initialize action</param>
        /// <param name="onExit">on execution exit operation</param>
        /// <param name="onPostExecute">operation before execution completed</param>
        public void Initialize(Func <IContext, IEnumerator> updateFunction,
                               Action <IContext> onInitialize  = null,
                               Action <IContext> onExit        = null,
                               Action <IContext> onPostExecute = null)
        {
            Release();

            _updateFunction = updateFunction;
            _onInitialize   = onInitialize;
            _onExit         = onExit;
            _onPostExecute  = onPostExecute;

            LifeTime.AddCleanUpAction(CleanUpOperations);
        }
        protected sealed override UniTask OnExecute()
        {
            LifeTime.AddDispose(_graphContext);
            LifeTime.AddCleanUpAction(() => _graphContext = new EntityContext());

            graphProcessor?.ExecuteAsync(this)
            .AttachExternalCancellation(LifeTime.TokenSource)
            .Forget();

            LoadDataSources()
            .AttachExternalCancellation(LifeTime.TokenSource)
            .Forget();

            return(UniTask.CompletedTask);
        }
Exemple #9
0
        protected sealed override void OnInitialize()
        {
            base.OnInitialize();

            InitializeGraphNodes();

#if UNITY_EDITOR
            if (Application.isPlaying == false)
            {
                Validate();
            }
#endif
            if (Application.isPlaying)
            {
                LifeTime.AddCleanUpAction(StopAllNodes);
            }
        }
Exemple #10
0
        public void Execute()
        {
            if (IsActive || _behaviour == null)
            {
                return;
            }

            IsActive = true;

            //activate state
            var routine        = _behaviour.Execute(_entity);
            var disposableItem = routine.RunWithSubRoutines();

            //add lifetime cleanup actions
            LifeTime.AddDispose(disposableItem);
            LifeTime.AddCleanUpAction(_behaviour.Exit);
        }
        protected sealed override async UniTask OnInitialize(IViewModel model)
        {
            await base.OnInitialize(model);

            LifeTime.AddCleanUpAction(() => _viewModel.Value = null);

            var modelData = model as TViewModel;

            _viewModel.Value = modelData;

            //save model as context data
            if (modelData == null)
            {
                GameLog.LogError($"VIEW: {name} wrong model type. Target type {typeof(TViewModel).Name} : model Type {model?.GetType().Name}");
            }

            await OnInitialize(modelData);
        }
        private void InitialSetup()
        {
            _isInitialized.Value = true;
            _status.Value        = ViewStatus.None;

            _viewModelLifeTime.AddTo(LifeTime);
            _progressLifeTime.AddTo(LifeTime);

            LifeTime.AddCleanUpAction(() =>
            {
                _isInitialized.Value = false;
                IsTerminated         = true;
                ViewModel            = null;
                SetStatus(ViewStatus.Closed);
                _status.Release();
                _visibility.Release();
            });
        }
Exemple #13
0
        private IStateToken CreateToken()
        {
            if (_token != null)
            {
                return(_token);
            }

            _token = new FlowStateToken()
                     .AddTo(TokenLifeTime);

            if (connectWithGrphContext)
            {
                _token.Context
                .Connect(this.Context)
                .AddTo(_token.LifeTime);
            }

            LifeTime.AddDispose(_token);
            LifeTime.AddCleanUpAction(() => _token = null);

            return(_token);
        }
        protected override void OnExecute()
        {
            base.OnExecute();

            var graphPrefab = CreateGraph(LifeTime);

            if (!graphPrefab)
            {
                return;
            }

            graphPrefab.Execute();

            foreach (var port in Ports)
            {
                var portName   = port.ItemName;
                var originPort = GetPort(portName);
                var targetPort = graphPrefab.GetPort(portName);
                ConnectToGraphPort(port, targetPort, originPort.Direction);
            }

            LifeTime.AddCleanUpAction(() => graphPrefab?.Exit());
        }
        public async UniTask <IGameViewSystem> LoadSystem()
        {
            if (uiSystemAsset != null)
            {
                return(uiSystemAsset);
            }

            var uiSystem = await uiSystemSource.LoadGameObjectAssetTaskAsync(LifeTime);

            var uiAsset = Instantiate(uiSystem);

            DontDestroyOnLoad(uiAsset.gameObject);

            LifeTime.AddCleanUpAction(() => {
                if (uiAsset)
                {
                    Object.Destroy(uiAsset.gameObject);
                }
            });

            uiSystemAsset = uiAsset.ViewSystem;
            return(uiSystemAsset);
        }
Exemple #16
0
 protected override void OnExecute() => LifeTime.AddCleanUpAction(() => _graphContext.Release());