using System.Collections.Generic; using System.IO; using System.Linq; #if UNITY_EDITOR && UNITY_ANDROID && UNITY_2021_2_OR_NEWER using Unity.Android.Types; #endif using UnityEditor; using UnityEngine; namespace Ubisoft.Hotel.Addressables.Core { public class AssetDeliveryUtility { public static readonly string AssetPackCatalogFilename = "AssetPackCatalog.json"; public static readonly string AssetPackCatalogFolderName = Application.streamingAssetsPath; public static readonly string AssetPackCatalogRuntimePath = Path.Combine(AssetPackCatalogFolderName, AssetPackCatalogFilename); #if UNITY_EDITOR public static readonly string BuildRootDirectory = AssetDeliveryConfiguration.AssetDeliveryRootDirectory; public static readonly string BuildProcessorDataFilename = "BuildProcessorData.json"; public static readonly string BuildProcessorDataPath = Path.Combine(BuildRootDirectory, BuildProcessorDataFilename); private static readonly string AssetPackContentFolderName = "AssetPackContent"; public static readonly string AssetPackContentRootDirectory = $"{BuildRootDirectory}/{AssetPackContentFolderName}"; public static readonly string AssetPackCatalogEditorPath = Path.Combine(BuildRootDirectory, AssetPackCatalogFilename); #if UNITY_ANDROID && UNITY_2021_2_OR_NEWER static readonly Dictionary AssetDeliveryTypeToGradleStringCatalog = new Dictionary() { { EDeliveryType.InstallTime, AndroidAssetPackDeliveryType.InstallTime }, { EDeliveryType.FastFollow, AndroidAssetPackDeliveryType.FastFollow }, { EDeliveryType.OnDemand, AndroidAssetPackDeliveryType.OnDemand }, }; public static string AssetDeliveryTypeToGradleString(EDeliveryType deliveryType) { return AssetDeliveryTypeToGradleStringCatalog[deliveryType].Name; } #else private static readonly Dictionary AssetDeliveryTypeToGradleStringCatalog = new Dictionary() { { EDeliveryType.InstallTime, "install-time" }, { EDeliveryType.FastFollow, "fast-follow" }, { EDeliveryType.OnDemand, "on-demand" }, }; public static string AssetDeliveryTypeToGradleString(EDeliveryType deliveryType) { return AssetDeliveryTypeToGradleStringCatalog[deliveryType]; } #endif public static void DeleteDirectory(string directoryPath, bool onlyIfEmpty) { bool isEmpty = !Directory.EnumerateFiles(directoryPath, "*", SearchOption.AllDirectories).Any() && !Directory.EnumerateDirectories(directoryPath, "*", SearchOption.AllDirectories).Any(); if (!onlyIfEmpty || isEmpty) { // check if the folder is valid in the AssetDatabase before deleting through standard file system string relativePath = directoryPath.Replace("\\", "/").Replace(Application.dataPath, "Assets"); if (AssetDatabase.IsValidFolder(relativePath)) { _ = AssetDatabase.DeleteAsset(relativePath); } else { Directory.Delete(directoryPath, true); } } } #endif } }