コード例 #1
0
        /// <inheritdoc />
        protected override IEnumerator OnExecute(JobContext context)
        {
            AssetDirectoryPath = PathHelpers.FixSlashes(AssetDirectoryPath);


            _assetStoreApi = new AssetStoreAPI();

            yield return(null);

            _assetStoreApi.Login(Username, Password);

            while (_assetStoreApi.IsLogging())
            {
                yield return(null);
            }

            IsSuccess = _assetStoreApi.IsConnected;

            if (!IsSuccess)
            {
                RockLog.WriteLine(this, LogTier.Error, _assetStoreApi.LastError);
                yield break;
            }

            _assetStoreApi.FetchPackages();

            while (_assetStoreApi.IsFetchingPackages())
            {
                yield return(null);
            }

            IsSuccess = _assetStoreApi.HasPackages;

            if (!IsSuccess)
            {
                RockLog.WriteLine(this, LogTier.Error, _assetStoreApi.LastError);
                yield break;
            }

            // fetch required package
            var package = _assetStoreApi.EachPackage.FirstOrDefault(x => x.packageId == PackageId);

            if (package == null)
            {
                RockLog.WriteLine(this, LogTier.Error, string.Format("Package of id \"{0}\" not found.", PackageId));
                IsSuccess = false;
                yield break;
            }

            yield return(null);

            var packageFilePath = GeneratePackage();

            yield return(null);

            HttpWebResponse uploadWebResponse = null;

            var rootPath = AssetDirectoryPath;

            if (!rootPath.StartsWith("/"))
            {
                rootPath = '/' + AssetDirectoryPath;
            }

            // upload package to the asset store dashboard
            _assetStoreApi.Upload(
                package.id,
                packageFilePath,
                rootPath,
                Application.dataPath,
                Application.unityVersion,
                (response, s) =>
            {
                uploadWebResponse = response;
            }
                );

            while (uploadWebResponse == null)
            {
                yield return(null);
            }

            IsSuccess = uploadWebResponse.StatusCode == HttpStatusCode.OK;
        }