Пример #1
0
 private void UploadPackage()
 {
     DebugUtils.Log("UploadPackage");
     this.m_AssetsState = AssetStorePackageController.AssetsState.UploadingPackage;
     if (string.IsNullOrEmpty(this.m_DraftAssetsPath))
     {
         DebugUtils.LogError("No assets to upload has been selected");
         this.m_AssetsState = AssetStorePackageController.AssetsState.None;
         return;
     }
     AssetStoreAPI.UploadAssets(this.m_Package, this.m_LocalRootGUID, this.m_LocalRootPath, this.m_LocalProjectPath, this.m_DraftAssetsPath, new AssetStoreAPI.DoneCallback(this.OnAssetsUploaded), new AssetStoreClient.ProgressCallback(this.OnAssetsUploading));
 }
Пример #2
0
    /// <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, int loginTimeout = 90, int metadataTimeout = 600, int uploadTimeout = 36000, bool skipProjectSettings = false, bool actuallyUpload = false, string outputPath = "")
    {
        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_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, outputPath);

        if (actuallyUpload)
        {
            // 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();
    }