Esempio n. 1
0
    public IEnumerator TestAssetReferenceTMethod()
    {
        yield return(ValidateTestDependency());

        PreInstall();

        Container.BindAsync <GameObject>()
        .FromAssetReferenceT(addressablePrefabReference)
        .AsCached();
        PostInstall();

        AddressableInject <GameObject> asyncPrefab = Container.Resolve <AddressableInject <GameObject> >();

        int frameCounter = 0;

        while (!asyncPrefab.HasResult && !asyncPrefab.IsFaulted)
        {
            frameCounter++;
            if (frameCounter > 10000)
            {
                Assert.Fail();
            }
            yield return(null);
        }

        Addressables.Release(asyncPrefab.AssetReferenceHandle);
        Assert.Pass();
    }
        public void GetAllInstancesWithInjectSplit(InjectContext context, List <TypeValuePair> args, out Action injectAction, List <object> buffer)
        {
            Assert.IsEmpty(args);
            Assert.IsNotNull(context);

            injectAction = null;

            Func <CancellationToken, Task <AsyncOperationHandle <TConcrete> > > addressableLoadDelegate = async(_) =>
            {
                AsyncOperationHandle <TConcrete> loadHandle = Addressables.LoadAssetAsync <TConcrete>(assetReference);
                await loadHandle.Task;

                if (loadHandle.Status == AsyncOperationStatus.Failed)
                {
                    throw new Exception("Async operation failed", loadHandle.OperationException);
                }

                return(loadHandle);
            };

            var asyncInject = new AddressableInject <TConcrete>(context, addressableLoadDelegate);

            buffer.Add(asyncInject);
        }