public IEnumerator InitializationObjects_CompletesWhenObjectsPresent()
    {
        InitalizationObjectsOperation op = new InitalizationObjectsOperation();

        op.Completed += obj =>
        {
            Assert.AreEqual(AsyncOperationStatus.Succeeded, obj.Status);
            Assert.IsTrue(obj.Result);
        };
        var runtimeDataLocation = new ResourceLocationBase("RuntimeData", m_RuntimeSettingsPath, typeof(JsonAssetProvider).FullName, typeof(ResourceManagerRuntimeData));
        var rtdOp = m_Addressables.ResourceManager.ProvideResource <ResourceManagerRuntimeData>(runtimeDataLocation);

        rtdOp.Completed += obj =>
        {
            ObjectInitializationData opData = ObjectInitializationData.CreateSerializedInitializationData <FakeInitializationObject>("fake", "fake");
            obj.Result.InitializationObjects.Add(opData);
        };
        yield return(rtdOp);

        op.Init(rtdOp, m_Addressables);

        var handle = m_Addressables.ResourceManager.StartOperation(op, rtdOp);

        yield return(handle);
    }
    public IEnumerator InitializationObjects_CompletesWhenObjectsPresent()
    {
        if (m_RuntimeSettingsPath.StartsWith("GUID:"))
        {
            Debug.Log($"{nameof(InitializationObjects_CompletesWhenObjectsPresent)} skipped due to not having a runtime settings asset (Fast mode does not create this).");
            yield break;
        }
        InitalizationObjectsOperation op = new InitalizationObjectsOperation();

        op.Completed += obj =>
        {
            Assert.AreEqual(AsyncOperationStatus.Succeeded, obj.Status);
            Assert.IsTrue(obj.Result);
        };
        var runtimeDataLocation = new ResourceLocationBase("RuntimeData", m_RuntimeSettingsPath, typeof(JsonAssetProvider).FullName, typeof(ResourceManagerRuntimeData));
        var rtdOp = m_Addressables.ResourceManager.ProvideResource <ResourceManagerRuntimeData>(runtimeDataLocation);

        rtdOp.Completed += obj =>
        {
            ObjectInitializationData opData = ObjectInitializationData.CreateSerializedInitializationData <FakeInitializationObject>("fake", "fake");
            obj.Result.InitializationObjects.Add(opData);
        };
        yield return(rtdOp);

        op.Init(rtdOp, m_Addressables);

        var handle = m_Addressables.ResourceManager.StartOperation(op, rtdOp);

        yield return(handle);
    }
    public IEnumerator InitializationObjectsOperation_DoesNotThrow_WhenRuntimeDataOpFails()
    {
        var initObjectsOp = new InitalizationObjectsOperation();

        initObjectsOp.Init(new AsyncOperationHandle <ResourceManagerRuntimeData>()
        {
            m_InternalOp = new ProviderOperation <ResourceManagerRuntimeData>()
            {
                Result = null
            }
        }, m_Addressables);
        LogAssert.Expect(LogType.Error, "RuntimeData is null.  Please ensure you have built the correct Player Content.");
        var handle = m_Addressables.ResourceManager.StartOperation(initObjectsOp, default);

        yield return(handle);

        Assert.AreEqual(AsyncOperationStatus.Succeeded, handle.Status);
    }
    public void InitializationObjects_OperationRegistersForCallbacks()
    {
        //We're checking to make sure we've created a new ResourceManagerCallbacks object.  If this isn't null
        //then we won't create a new one.  This would never be needed in a legitimate scenario.
        m_Addressables.ResourceManager.m_CallbackHooks = null;
        int startCount = Resources.FindObjectsOfTypeAll <MonoBehaviourCallbackHooks>().Length;

        InitalizationObjectsOperation op = new InitalizationObjectsOperation();
        var runtimeDataLocation          = new ResourceLocationBase("RuntimeData", m_RuntimeSettingsPath, typeof(JsonAssetProvider).FullName, typeof(ResourceManagerRuntimeData));
        var rtdOp = m_Addressables.ResourceManager.ProvideResource <ResourceManagerRuntimeData>(runtimeDataLocation);

        //Test
        op.Init(rtdOp, m_Addressables);
        int endCount = Resources.FindObjectsOfTypeAll <MonoBehaviourCallbackHooks>().Length;

        //Assert
        Assert.AreEqual(startCount + 1, endCount);
    }
    public void InitializationObjects_OperationRegistersForCallbacks()
    {
        if (m_RuntimeSettingsPath.StartsWith("GUID:"))
        {
            Debug.Log($"{nameof(InitializationObjects_OperationRegistersForCallbacks)} skipped due to not having a runtime settings asset (Fast mode does not create this).");
            return;
        }
        //We're checking to make sure we've created a new ResourceManagerCallbacks object.  If this isn't null
        //then we won't create a new one.  This would never be needed in a legitimate scenario.
        MonoBehaviourCallbackHooks.DestroySingleton();
        int startCount = Resources.FindObjectsOfTypeAll <MonoBehaviourCallbackHooks>().Length;

        InitalizationObjectsOperation op = new InitalizationObjectsOperation();
        var runtimeDataLocation          = new ResourceLocationBase("RuntimeData", m_RuntimeSettingsPath, typeof(JsonAssetProvider).FullName, typeof(ResourceManagerRuntimeData));
        var rtdOp = m_Addressables.ResourceManager.ProvideResource <ResourceManagerRuntimeData>(runtimeDataLocation);

        //Test
        op.Init(rtdOp, m_Addressables);
        int endCount = Resources.FindObjectsOfTypeAll <MonoBehaviourCallbackHooks>().Length;

        //Assert
        Assert.AreEqual(startCount, endCount);
    }
    public void InitializationObjects_CompletesSyncWhenNoObjectsPresent()
    {
        if (m_RuntimeSettingsPath.StartsWith("GUID:"))
        {
            Assert.Ignore($"{nameof(InitializationObjects_CompletesWhenNoObjectsPresent)} skipped due to not having a runtime settings asset (Fast mode does not create this).");
        }
        InitalizationObjectsOperation op = new InitalizationObjectsOperation();

        op.Completed += obj =>
        {
            Assert.AreEqual(AsyncOperationStatus.Succeeded, obj.Status);
            Assert.IsTrue(obj.Result);
        };
        var runtimeDataLocation = new ResourceLocationBase("RuntimeData", m_RuntimeSettingsPath, typeof(JsonAssetProvider).FullName, typeof(ResourceManagerRuntimeData));
        var rtdOp = m_Addressables.ResourceManager.ProvideResource <ResourceManagerRuntimeData>(runtimeDataLocation);

        op.Init(rtdOp, m_Addressables);

        var handle = m_Addressables.ResourceManager.StartOperation(op, rtdOp);

        handle.WaitForCompletion();
        Assert.IsTrue(handle.IsDone);
    }
    public IEnumerator InitializationAsync_HandlesEmptyData()
    {
        InitalizationObjectsOperation op = new InitalizationObjectsOperation();

        op.Completed += obj =>
        {
            Assert.AreEqual(AsyncOperationStatus.Succeeded, obj.Status);
            Assert.IsTrue(obj.Result);
        };
        var runtimeDataLocation = new ResourceLocationBase("RuntimeData", m_RuntimeSettingsPath, typeof(JsonAssetProvider).FullName, typeof(ResourceManagerRuntimeData));
        var rtdOp = m_Addressables.ResourceManager.ProvideResource <ResourceManagerRuntimeData>(runtimeDataLocation);

        rtdOp.Completed += obj =>
        {
            obj.Result.InitializationObjects.Add(default(ObjectInitializationData));
        };
        yield return(rtdOp);

        op.Init(rtdOp, m_Addressables);

        var handle = m_Addressables.ResourceManager.StartOperation(op, rtdOp);

        yield return(handle);
    }