/// <summary>
        /// Move custom asset pack data from their build location to their App Bundle data location.
        /// </summary>
        /// <param name="buildPlayerContext">Contains data related to the player.</param>
        public static void MoveDataForAppBundleBuild(BuildPlayerContext buildPlayerContext)
        {
            try
            {
                buildPlayerContext.AddAdditionalPathToStreamingAssets(CustomAssetPackUtility.CustomAssetPacksDataEditorPath, CustomAssetPackUtility.kCustomAssetPackDataFilename);

                AssetDatabase.StartAssetEditing();
                if (File.Exists(CustomAssetPackUtility.BuildProcessorDataPath))
                {
                    string contents = File.ReadAllText(CustomAssetPackUtility.BuildProcessorDataPath);
                    var    data     = JsonUtility.FromJson <BuildProcessorData>(contents);

                    foreach (BuildProcessorDataEntry entry in data.Entries)
                    {
                        string assetsFolderPath = Path.Combine(CustomAssetPackUtility.PackContentRootDirectory, entry.AssetsSubfolderPath);
                        if (File.Exists(entry.BundleBuildPath))
                        {
                            string metaFilePath = AssetDatabase.GetTextMetaFilePathFromAssetPath(entry.BundleBuildPath);
                            File.Move(entry.BundleBuildPath, assetsFolderPath);
                            File.Delete(metaFilePath);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogError($"Exception occured when moving data for an app bundle build: {e.Message}.");
            }
            finally
            {
                AssetDatabase.StopAssetEditing();
            }
        }
Example #2
0
    internal static void PrepareForPlayerbuild(AddressableAssetSettings settings, BuildPlayerContext buildPlayerContext, bool buildAddressables)
    {
        if (settings != null && buildAddressables)
        {
            AddressablesPlayerBuildResult result;
            if (BuildAddressablesOverride != null)
            {
                try
                {
                    result = BuildAddressablesOverride.Invoke(settings);
                }
                catch (Exception e)
                {
                    result       = new AddressablesPlayerBuildResult();
                    result.Error = "Exception in BuildAddressablesOverride: " + e;
                }
            }
            else
            {
                AddressableAssetSettings.BuildPlayerContent(out result);
            }

            if (result != null && !string.IsNullOrEmpty(result.Error))
            {
                Debug.LogError($"Failed to build Addressables content, content not included in Player Build. \"{result.Error}\"");
            }
        }

        if (buildPlayerContext != null)
        {
            var streamingAssetValues = GetStreamingAssetPaths();
            foreach (KeyValuePair <string, string> streamingAssetValue in streamingAssetValues)
            {
                buildPlayerContext.AddAdditionalPathToStreamingAssets(streamingAssetValue.Key,
                                                                      streamingAssetValue.Value);
            }
        }

        string buildPath = Addressables.BuildPath + "/AddressablesLink/link.xml";

        if (File.Exists(buildPath))
        {
            string projectPath = GetLinkPath(settings, true);
            File.Copy(buildPath, projectPath, true);
            AssetDatabase.ImportAsset(projectPath, ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.DontDownloadFromCacheServer);
        }
    }