/// <summary> /// Upload a package, using the specified command line arguments. /// </summary> /// <remarks> /// The Asset Store account password must be provided via the "ASSET_STORE_PASSWORD" environment variable. /// </remarks> public static void UploadAssetStorePackage(params string[] args) { var username = Environment.GetEnvironmentVariable("ASSET_STORE_USERNAME"); var password = Environment.GetEnvironmentVariable("ASSET_STORE_PASSWORD"); var packageName = Environment.GetEnvironmentVariable("ASSET_STORE_PACKAGE_NAME"); var rootPath = Environment.GetEnvironmentVariable("ASSET_STORE_ROOT_PATH"); var loginTimeout = 10; var metadataTimeout = 300; var uploadTimeout = 36000; var skipProjectSettings = false; GuidListPostprocessCallback guidListPostprocessCallback = null; var mainAssets = new List <string>(); var mainAssetsStr = Environment.GetEnvironmentVariable("ASSET_STORE_MAIN_ASSETS"); if (mainAssetsStr != null) { var mainAssetsSplit = mainAssetsStr.Split(':'); for (var i = 0; i < mainAssetsSplit.Length; ++i) { mainAssets.Add(mainAssetsSplit[i]); } } var assets = mainAssets; var opt = new OptionSet { { "asset_store_username="******"The username credential to use for package uploading.", o => username = o }, { "asset_store_password="******"The username credential to use for package uploading.", o => password = o }, { "asset_store_package_name=", "The package name. The package must be set to draft status in the Publisher Administration.", o => packageName = o }, { "asset_store_root_path=", "The root path of the package (relative to Application.dataPath). If not present, use the project Assets folder.", o => rootPath = o }, { "asset_store_main_asset=", "A main asset for the package (relative to Application.dataPath). Multiple options are allowed. If not present, do not upload or change any main assets.", assets.Add }, { "asset_store_login_timeout=", "The maximum amount of time to wait (in seconds) when logging in. Defaults to 10 seconds. Must be within 2 and 36000 seconds. Login is attempted twice.", (int o) => loginTimeout = o }, { "asset_store_metadata_timeout=", "The maximum amount of time to wait (in seconds) when getting metadata. Defaults to 300 seconds. Must be within 2 and 36000 seconds.", (int o) => metadataTimeout = o }, { "asset_store_upload_timeout=", "The maximum amount of time to wait (in seconds) when uploading. Defaults to 36000 seconds. Must be within 2 and 36000 seconds.", (int o) => uploadTimeout = o }, { "skip_project_settings", "If true, always skip project settings export. This only applies to assets in the Complete Projects category.", o => skipProjectSettings = o != null } }; opt.Parse(args); UploadAssetStorePackage(username, password, packageName, rootPath, mainAssets.ToArray(), loginTimeout, metadataTimeout, uploadTimeout, skipProjectSettings, guidListPostprocessCallback); }
/// <summary> /// Upload a package, using the specified options. /// </summary> /// <param name="username">The username credentials to use for package uploading.</param> /// <param name="password">The password credentials to use for package uploading.</param> /// <param name="packageName">The package name. The package must be set to draft status in the Publisher Administration.</param> /// <param name="rootPath">The root path of the package (relative to Application.dataPath). If null, use the project Assets folder.</param> /// <param name="mainAssets">An array of the main assets for the package (relative to Application.dataPath). If null, do not upload or change any main assets.</param> /// <param name="loginTimeout">The maximum amount of time to wait (in seconds) when logging in. Defaults to 90 seconds. Must be within 2 and 36000 seconds. Login is attempted twice.</param> /// <param name="metadataTimeout">The maximum amount of time to wait (in seconds) when getting metadata. Defaults to 600 seconds. Must be within 2 and 36000 seconds.</param> /// <param name="uploadTimeout">The maximum amount of time to wait (in seconds) when uploading. Defaults to 36000 seconds. Must be within 2 and 36000 seconds.</param> public static void UploadAssetStorePackage(string username, string password, string packageName, string rootPath = null, string[] mainAssets = null, GuidListPostprocessCallback guidListPostprocessCallback = null, int loginTimeout = 90, int metadataTimeout = 600, int uploadTimeout = 36000, bool skipProjectSettings = false) { if (string.IsNullOrEmpty(username)) { throw new ArgumentNullException("username"); } if (string.IsNullOrEmpty(password)) { throw new ArgumentNullException("password"); } if (string.IsNullOrEmpty(packageName)) { throw new ArgumentNullException("packageName"); } s_Username = username; s_Password = password; s_PackageName = packageName; s_RootPath = rootPath; s_MainAssets = mainAssets; s_GuidListPostprocessCallback = guidListPostprocessCallback; s_LoginTimeout = Mathf.Clamp(loginTimeout, 2, 36000); s_MetadataTimeout = Mathf.Clamp(metadataTimeout, 2, 36000); s_UploadTimeout = Mathf.Clamp(uploadTimeout, 2, 36000); s_SkipProjectSettings = skipProjectSettings; Finish(); #if !UNITY_5_5_OR_NEWER if (Application.webSecurityEnabled) { Debug.Log("[Asset Store Batch Mode] Switching from Web Player platform..."); EditorUserBuildSettings.SwitchActiveBuildTarget(EditorUserBuildSettings.selectedStandaloneTarget); } #endif Debug.Log("[Asset Store Batch Mode] Logging into the Asset Store..."); AssetStoreClient.LoginWithCredentials(s_Username, s_Password, false, OnLogin); if (!WaitForUpdate(ref s_LoginDone, s_LoginTimeout)) { Finish(); // Try again s_LoginDone = false; AssetStoreClient.LoginWithCredentials(s_Username, s_Password, false, OnLogin); if (!WaitForUpdate(ref s_LoginDone, s_LoginTimeout)) { Finish(); return; } } AssetStoreAPI.GetMetaData(s_PublisherAccount, s_PackageDataSource, OnGetMetadata); Debug.Log("[Asset Store Batch Mode] Getting package metadata..."); if (!WaitForUpdate(ref s_GetMetadataDone, s_MetadataTimeout)) { Finish(); return; } var packages = s_PackageDataSource.GetAllPackages(); var package = packages.FirstOrDefault(p => p.Name == s_PackageName && p.Status == Package.PublishedStatus.Draft); if (package == null) { Debug.LogError("[Asset Store Batch Mode] Draft package: " + s_PackageName + " not found!"); Finish(); return; } // Validate root project folder var projectFolder = Path.Combine(Application.dataPath, s_RootPath ?? string.Empty); // Convert to unix path style projectFolder = projectFolder.Replace("\\", "/"); if (!IsValidProjectFolder(projectFolder)) { Debug.LogError("[Asset Store Batch Mode] Project folder is invalid"); Finish(); return; } // Set root asset path var localRootPath = SetRootPath(package, projectFolder); // Set main assets if (MainAssetsUtil.CanGenerateBundles) { // TODO: Set main assets } // Verify content var checkContent = CheckContent(package, localRootPath); if (!string.IsNullOrEmpty(checkContent)) { Debug.LogError("[Asset Store Batch Mode] " + checkContent); Finish(); return; } var draftAssetsPath = GetDraftAssetsPath(localRootPath); Export(package, localRootPath, draftAssetsPath); // Upload assets AssetStoreAPI.UploadAssets( package, AssetStorePackageController.GetLocalRootGUID(package), localRootPath, Application.dataPath, draftAssetsPath, OnAssetsUploaded, null); Debug.Log("[Asset Store Batch Mode] Uploading asset..."); if (!WaitForUpdate(ref s_AssetsUploadedDone, s_UploadTimeout)) { Finish(); return; } if (MainAssetsUtil.CanGenerateBundles) { // TODO: Upload main assets } Debug.Log("[Asset Store Batch Mode] Asset successfully uploaded"); Finish(); }