Ejemplo n.º 1
0
        public async UniTask <IView> Create(
            Type viewType,
            string skinTag         = "",
            Transform parent       = null,
            string viewName        = "",
            bool stayWorldPosition = false)
        {
            await _readyStatus;

            var viewLifeTime = LifeTime.Create();
            var result       = await resourceProvider.LoadViewAsync <Component>(viewType, viewLifeTime, skinTag, viewName : viewName);

            //create view instance
            var view = Create(result, parent, stayWorldPosition);

            //if loading failed release resource immediately
            if (view == null)
            {
                viewLifeTime.Despawn();
                GameLog.LogError($"Factory {this.GetType().Name} View of Type {viewType?.Name} not loaded");
                return(null);
            }

            view.LifeTime.AddCleanUpAction(() => viewLifeTime.Despawn());

            return(view);
        }
Ejemplo n.º 2
0
        public IEnumerator UpdateDisposeRoutineTest()
        {
            //arrange
            var counter = new List <int>()
            {
                0
            };
            var count      = 3;
            var itemsCount = 20;
            var disposable = new List <IDisposable>();

            //act
            for (var i = 0; i < itemsCount; i++)
            {
                var routineDisposable = this.OnUpdate(x => {
                    counter[0]++;
                    return(true);
                }).ExecuteRoutine();
                disposable.Add(routineDisposable);
            }

            yield return(null);

            yield return(null);

            var postDisposable = LifeTime.Create();

            for (int i = 10; i < disposable.Count; i++)
            {
                var itemDisposable = disposable[i];
                itemDisposable.Dispose();
                this.OnUpdate(
                    x => {
                    counter[0]++;
                    return(true);
                }).ExecuteRoutine().AddTo(postDisposable);
            }

            yield return(null);

            postDisposable.Release();
            //assert
            Assert.That(counter[0] == (itemsCount * 3));
        }