public void PrepareAddressableBuildForPlayerBuild_LinkXML_CopiedCorrectly()
    {
        string buildPath = Addressables.BuildPath + "/AddressablesLink/link.xml";

        Directory.CreateDirectory(Addressables.BuildPath + "/AddressablesLink");
        bool preexistingFile = File.Exists(buildPath);

        if (!preexistingFile)
        {
            var textStream = File.CreateText(buildPath);
            textStream.Write("link test file");
            textStream.Close();
        }

        // do the test
        string projectPath = Path.Combine(m_Settings.ConfigFolder, "link.xml");

        try
        {
            AddressablesPlayerBuildProcessor.PrepareForPlayerbuild(m_Settings, null, false);
            Assert.IsTrue(File.Exists(projectPath), "Link.xml file not found at project path when preparing for build");
        }
        // clean up
        finally
        {
            AddressablesPlayerBuildProcessor.RemovePlayerBuildLinkXML(m_Settings);
            if (!preexistingFile)
            {
                File.Delete(buildPath);
            }
            Assert.IsFalse(File.Exists(projectPath), "Link.xml file remains at the ProjectPath, link.xml expected to be deleted");
        }
    }
            public void CopiedStreamingAssetAreCorrectlyDeleted_DirectoriesWithoutImport()
            {
                var context = new AddressablesDataBuilderInput(Settings);

                int builderCount = 0;

                for (int i = 0; i < Settings.DataBuilders.Count; i++)
                {
                    var builder = Settings.DataBuilders[i] as IDataBuilder;
                    if (builder.CanBuildData <AddressablesPlayerBuildResult>())
                    {
                        builderCount++;

                        // confirm that StreamingAssets does not exists before the test
                        Assert.IsFalse(Directory.Exists("Assets/StreamingAssets"));
                        builder.BuildData <AddressablesPlayerBuildResult>(context);

                        Assert.IsTrue(Directory.Exists(Addressables.BuildPath));
                        AddressablesPlayerBuildProcessor.CopyTemporaryPlayerBuildData();
                        builder.ClearCachedData();

                        Assert.IsTrue(Directory.Exists(Addressables.PlayerBuildDataPath));
                        AddressablesPlayerBuildProcessor.CleanTemporaryPlayerBuildData();
                        Assert.IsFalse(Directory.Exists(Addressables.PlayerBuildDataPath));
                        Assert.IsFalse(Directory.Exists("Assets/StreamingAssets"));
                    }
                }

                Assert.IsTrue(builderCount > 0);
            }
Exemple #3
0
        public void CopiedStreamingAssetAreCorrectlyDeleted_MetaFilesWithImport()
        {
            var context = new AddressablesDataBuilderInput(Settings);

            int builderCount = 0;

            for (int i = 0; i < Settings.DataBuilders.Count; i++)
            {
                var builder = Settings.DataBuilders[i] as IDataBuilder;
                if (builder.CanBuildData <AddressablesPlayerBuildResult>())
                {
                    builderCount++;

                    // confirm that StreamingAssets does not exists before the test
                    Assert.IsFalse(Directory.Exists("Assets/StreamingAssets"));
                    builder.BuildData <AddressablesPlayerBuildResult>(context);

                    Assert.IsTrue(Directory.Exists(Addressables.BuildPath));
                    AddressablesPlayerBuildProcessor.CopyTemporaryPlayerBuildData();
                    builder.ClearCachedData();

                    // confirm that PlayerBuildDataPath is imported to AssetDatabase
                    AssetDatabase.Refresh();
                    Assert.IsTrue(Directory.Exists(Addressables.PlayerBuildDataPath));
                    Assert.IsTrue(File.Exists(Addressables.PlayerBuildDataPath + ".meta"));
                    string relativePath = Addressables.PlayerBuildDataPath.Replace(Application.dataPath, "Assets");
                    Assert.IsTrue(AssetDatabase.IsValidFolder(relativePath), "Copied StreamingAssets folder was not importer as expected");

                    AddressablesPlayerBuildProcessor.CleanTemporaryPlayerBuildData();
                    Assert.IsFalse(Directory.Exists(Addressables.PlayerBuildDataPath));
                    Assert.IsFalse(Directory.Exists("Assets/StreamingAssets"));
                }
            }
            Assert.IsTrue(builderCount > 0);
        }
            public void AddressablesBuildPlayerProcessor_DoesntIncludeAdditionalStreamingAssetsWhenDontExist()
            {
                if (Directory.Exists(Addressables.BuildPath))
                {
                    DirectoryUtility.DeleteDirectory(Addressables.BuildPath, false);
                }
                var paths = AddressablesPlayerBuildProcessor.GetStreamingAssetPaths();

                Assert.AreEqual(0, paths.Count, "StreamingAssets paths are expected to be empty");

                // cleanup
            }
            public void AddressablesBuildPlayerProcessor_IncludeAdditionalStreamingAssetsWhenExist()
            {
                string path = Addressables.BuildPath;

                Directory.CreateDirectory(path);
                var paths = AddressablesPlayerBuildProcessor.GetStreamingAssetPaths();

                Assert.AreEqual(1, paths.Count, "StreamingAssets paths expected to include Addressables.BuildPath");

                // cleanup
                Directory.Delete(path);
            }
    public void PrepareAddressableBuildForPlayerBuild_ShouldBuildAddressables_CorrectForSettings(int settingValue, bool preferencesValue)
    {
        // Setup
        m_Settings.BuildAddressablesWithPlayerBuild = (AddressableAssetSettings.PlayerBuildOption)settingValue;
        bool deleteKey         = !EditorPrefs.HasKey(AddressablesPreferences.kBuildAddressablesWithPlayerBuildKey);
        bool previousPrefValue = EditorPrefs.GetBool(AddressablesPreferences.kBuildAddressablesWithPlayerBuildKey, true);

        EditorPrefs.SetBool(AddressablesPreferences.kBuildAddressablesWithPlayerBuildKey, preferencesValue);

        try
        {
            bool result = AddressablesPlayerBuildProcessor.ShouldBuildAddressablesForPlayerBuild(m_Settings);
            if (m_Settings.BuildAddressablesWithPlayerBuild == AddressableAssetSettings.PlayerBuildOption.BuildWithPlayer)
            {
                Assert.IsTrue(result, "Addressables build was expected to set to build when preparing a Player Build");
            }
            else if (m_Settings.BuildAddressablesWithPlayerBuild == AddressableAssetSettings.PlayerBuildOption.DoNotBuildWithPlayer)
            {
                Assert.IsFalse(result, "Addressables build is not expected to set be build when preparing a Player Build");
            }
            else if (m_Settings.BuildAddressablesWithPlayerBuild == AddressableAssetSettings.PlayerBuildOption.DoNotBuildWithPlayer)
            {
                if (preferencesValue)
                {
                    Assert.IsTrue(result, "Addressables build was expected to set to build when preparing a Player Build");
                }
                else
                {
                    Assert.IsFalse(result, "Addressables build is not expected to set be build when preparing a Player Build");
                }
            }
        }
        catch (Exception e)
        {
            Assert.Fail("Unhandled Exception in Preparing for Addressables - With Exception: " + e);
        }
        finally
        {
            if (deleteKey)
            {
                EditorPrefs.DeleteKey(AddressablesPreferences.kBuildAddressablesWithPlayerBuildKey);
            }
            else
            {
                EditorPrefs.SetBool(AddressablesPreferences.kBuildAddressablesWithPlayerBuildKey, previousPrefValue);
            }
        }
    }
            public void CopiedStreamingAssetAreCorrectlyDeleted_WithExistingFiles()
            {
                var context = new AddressablesDataBuilderInput(Settings);

                int builderCount = 0;

                for (int i = 0; i < Settings.DataBuilders.Count; i++)
                {
                    var builder = Settings.DataBuilders[i] as IDataBuilder;
                    if (builder.CanBuildData <AddressablesPlayerBuildResult>())
                    {
                        builderCount++;

                        // confirm that StreamingAssets does not exists before the test
                        DirectoryUtility.DeleteDirectory(Application.streamingAssetsPath, recursiveDelete: true);
                        Assert.IsFalse(Directory.Exists("Assets/StreamingAssets"));

                        // create StreamingAssets and an extra folder as existing content
                        AssetDatabase.CreateFolder("Assets", "StreamingAssets");
                        AssetDatabase.CreateFolder("Assets/StreamingAssets", "extraFolder");

                        builder.BuildData <AddressablesPlayerBuildResult>(context);

                        Assert.IsTrue(Directory.Exists(Addressables.BuildPath));
                        AddressablesPlayerBuildProcessor.CopyTemporaryPlayerBuildData();
                        builder.ClearCachedData();

                        Assert.IsTrue(Directory.Exists(Addressables.PlayerBuildDataPath));
                        AddressablesPlayerBuildProcessor.CleanTemporaryPlayerBuildData();
                        Assert.IsFalse(Directory.Exists(Addressables.PlayerBuildDataPath));
                        Assert.IsTrue(Directory.Exists("Assets/StreamingAssets"));
                        Assert.IsTrue(Directory.Exists("Assets/StreamingAssets/extraFolder"));

                        AssetDatabase.DeleteAsset("Assets/StreamingAssets");
                    }
                }

                Assert.IsTrue(builderCount > 0);
            }