コード例 #1
0
        public override void OnPostprocessBuild(AppConfig appConfig, BuildReport buildReport)
        {
            var uploadToAzureSettings = appConfig.GetSettings <UploadAddressableToAzureSettings>();

            var azureConfig = new AzureStorage.Config
            {
                StorageAccountName = uploadToAzureSettings.storageAccountName,
                StorageAccountKey  = uploadToAzureSettings.storageAccountKey,
                ContainerName      = uploadToAzureSettings.containerName,
            };

            // makding sure the asset bundle path doesn't end with a forward slash
            string assetBundlePath = uploadToAzureSettings.CalculateBuildPath();

            if (Directory.Exists(assetBundlePath) == false)
            {
                if (this.IsBeingUsedByAddressableSystem())
                {
                    Debug.LogErrorFormat("Unable to Upload AssetBundles To Azure.  Directory {0} does not exist.", assetBundlePath);
                }

                return;
            }

            string           blobPrefix    = GetBlobPrefix(uploadToAzureSettings);
            HashSet <string> existingFiles = GetExistingFiles(azureConfig, blobPrefix);

            foreach (var filePath in Directory.GetFiles(assetBundlePath, "*", SearchOption.AllDirectories))
            {
                string relativeFileName = filePath.Substring(assetBundlePath.Length + 1).Replace("\\", "/");
                string blobName         = blobPrefix + "/" + relativeFileName;

                if (existingFiles.Contains(blobName))
                {
                    Debug.LogFormat("Skipping AssetBundle {0}, it already exists", blobName, azureConfig.StorageAccountName);
                    continue;
                }

                Debug.LogFormat("Uploading AssetBundle {0}", blobName, azureConfig.StorageAccountName);

                try
                {
                    AzureStorage.UploadFile(azureConfig, blobName, File.ReadAllBytes(filePath));
                }
                catch (Exception exception)
                {
                    Debug.LogErrorFormat("Error uploading AssetBundle {0} To Azure.", blobName);
                    Debug.LogException(exception);

                    #if UNITY_CLOUD_BUILD
                    EditorApplication.Exit(1);
                    #endif

                    return;
                }
            }
        }
コード例 #2
0
        private static HashSet <string> GetExistingFiles(AzureStorage.Config azureConfig, string blobPrefix)
        {
            HashSet <string> result = new HashSet <string>();

            if (blobPrefix.EndsWith("/") == false)
            {
                blobPrefix += "/";
            }

            foreach (string file in AzureStorage.ListFiles(azureConfig, blobPrefix))
            {
                result.Add(file);
            }

            return(result);
        }