private static void UploadPackage()
        {
            var packages = s_PackageDataSource.GetAllPackages();
            var package  = packages.FirstOrDefault(p => p.Name.ToLowerInvariant() == s_PackageName.ToLowerInvariant() && p.Status == Package.PublishedStatus.Draft);

            if (package == null)
            {
                Debug.LogError("[Asset Store Batch Mode] Draft package: " + s_PackageName + " not found!");
                Finish();
                CurrentState = State.Error;
                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();
                CurrentState = State.Error;
                return;
            }

            // Set root asset path
            var localRootPath = SetRootPath(package, projectFolder);

            // TODO: Set main assets

            // Verify content
            var checkContent = CheckContent(package, localRootPath);

            if (!string.IsNullOrEmpty(checkContent))
            {
                Debug.LogError("[Asset Store Batch Mode] " + checkContent);
                Finish();
                CurrentState = State.Error;
                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...");

            CurrentState = State.WaitingForUpload;
        }
        /// <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>
        /// <param name="guidListPostprocessCallback = null">Callback that takes the array of asset GUIDs and returns a modified one. Useful for filtering out unwanted assets.</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, GuidListPostprocessCallback guidListPostprocessCallback = null)
        {
            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;
            s_GuidListPostprocessCallback = guidListPostprocessCallback;

            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);

            // 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;
            }

            // TODO: Upload main assets

            Debug.Log("[Asset Store Batch Mode] Asset successfully uploaded");

            Finish();
        }