Beispiel #1
0
        /// <summary>
        /// 判断目标存不存在.
        /// </summary>
        /// <returns><c>true</c>, 存在, <c>false</c> 不存在.</returns>
        /// <param name="iBundleId">BundleID.</param>
        /// <param name="iFileType">文件类型.</param>
        /// <param name="iTarget">下载目标信息.</param>
        public bool isTargetExist(string iBundleId,
                                  TUploadFileType iFileType, out DownloadTargetInfo iTarget)
        {
            iTarget = null;
            if (string.IsNullOrEmpty(iBundleId) == true)
            {
                return(false);
            }

            DownloadTargetInfo[] targets = this.Targets
                                           .Where(o => (
                                                      (iBundleId.Equals(o.ID) == true) &&
                                                      (iFileType == o.FileType)))
                                           .OrderByDescending(o => o.No)
                                           .ToArray();
            if ((targets == null) || (targets.Length <= 0))
            {
                return(false);
            }
            if (1 != targets.Length)
            {
                UtilsLog.Warning("isTargetExist", "There is duplicate id exist in download list!!!(Bundle ID:{0} FileType:{1})",
                                 iBundleId, iFileType);
            }
            iTarget = targets [0];
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// 加载数据(旧版本).
        /// </summary>
        /// <returns>加载队形.</returns>
        /// <param name="path">路径.</param>
        public static Object LoadData(string path)
        {
            Object objRet = Load <Object>(path);

            if (null == objRet)
            {
                UtilsLog.Warning("DataLoadController",
                                 "LoadData():Load Failed!!(path:{0})", path);
            }
            return(objRet);
        }
Beispiel #3
0
        public static Object LoadFromResource(string path)
        {
            Object objRet = ResourcesLoad.Load(path) as Object;

            if (null == objRet)
            {
                UtilsLog.Warning("DataLoadController",
                                 "LoadFromResource():Load Failed!!(path:{0})", path);
            }
            return(objRet);
        }
        /// <summary>
        /// 取得拷贝目的文件目录.
        /// </summary>
        /// <returns>取得拷贝目的文件目录.</returns>
        public string GetAndroidCopyToDir()
        {
            string dir = string.Format("{0}/Plugins/Android", Application.dataPath);

            if (false == Directory.Exists(dir))
            {
                UtilsLog.Warning("GetAndroidCopyToDir", "The directory is not exist!!(Dir:{0})", dir);
                Directory.CreateDirectory(dir);
            }

            return(dir);
        }
Beispiel #5
0
        /// <summary>
        /// 加载场景.
        /// </summary>
        /// <param name="iSceneName">I scene name.</param>
        public static void LoadScene(string iSceneName)
        {
            if (false == AssetBundlesManager.Instance.LoadScene(iSceneName))
            {
                UtilsLog.Warning("DataLoadController",
                                 "LoadScene():There is no scene({0}) in asset bundles manager!!",
                                 iSceneName);

                // 加载场景
                SceneManager.LoadScene(iSceneName);
            }
        }
Beispiel #6
0
        /// <summary>
        /// 添加对象.
        /// </summary>
        /// <param name="iTarget">对象.</param>
        /// <param name="iFileType">上传文件类型.</param>
        /// <param name="iHashCode">HashCode(Unity3d打包生成).</param>
        public void AddTarget(
            BundleMap iTarget, TUploadFileType iFileType, string iHashCode = null)
        {
            if (iTarget == null)
            {
                return;
            }
            UploadItem _item    = null;
            string     filePath = GetLocalBundleFilePath(
                iTarget.ID, iFileType, (TBundleType.Scene == iTarget.Type));
            string checkCode = null;

            string dataSize = null;

            if ((false == string.IsNullOrEmpty(filePath)) &&
                (true == File.Exists(filePath)))
            {
                if (TCheckMode.Unity3d_Hash128 == this.CheckMode)
                {
                    checkCode = iHashCode;
                }
                else
                {
                    checkCode = GetFileMD5(filePath);
                }
                FileInfo fileInfo = new FileInfo(filePath);
                dataSize = fileInfo.Length.ToString();
            }
            else
            {
                UtilsLog.Warning("AddTarget", "Target File is not exist!!!(target:{0})", filePath);
            }

            bool _exist = this.isTargetExist(iTarget.ID, iFileType, out _item);

            if (false == _exist)
            {
                _item           = this.CreateUploadItem(iTarget.ID, iTarget.Type, iFileType);
                _item.CheckCode = checkCode;
                _item.DataSize  = dataSize;
            }
            else
            {
                if ((false == string.IsNullOrEmpty(checkCode)) &&
                    (false == checkCode.Equals(_item.CheckCode)))
                {
                    _item.CheckCode = checkCode;
                    _item.DataSize  = dataSize;
                    _item.Uploaded  = false;
                }
            }
            UtilsAsset.SetAssetDirty(this);
        }
Beispiel #7
0
        /// <summary>
        /// 初始化上传队列.
        /// </summary>
        private IEnumerator InitUploadQueue()
        {
            this._isCompleted = false;

            // 初始化上传信息队列
            List <UploadItem> targets = UploadList.GetInstance().Targets;

            if (this.UploadQueue != null)
            {
                UploadItem[] uploadTargets = targets.
                                             Where(o => (
                                                       (false == o.Uploaded) &&
                                                       (false == o.Scraped)))
                                             .OrderBy(o => o.No)
                                             .ToArray();
                if ((uploadTargets == null) || (uploadTargets.Length <= 0))
                {
                    this._State = TRunState.NoUploadTarget;
                    UtilsLog.Warning("InitUploadQueue", "There is no target to upload!!!");
                }
                yield return(new WaitForEndOfFrame());

                if (TRunState.OK == this._State)
                {
                    this.UploaderCount = 0;
                    int targetsCount = uploadTargets.Length;
                    int maxCount     = ServersConf.GetInstance().ThreadMaxCount;
                    this.UploaderMaxCount = (targetsCount > maxCount) ? maxCount : targetsCount;

                    foreach (UploadItem loop in uploadTargets)
                    {
                        if (loop == null)
                        {
                            continue;
                        }
                        Uploader uploader = Uploader.Create(loop,
                                                            this.OnUploadStart,
                                                            this.OnUploadFailed,
                                                            this.OnUploadSuccessed);
                        if (uploader != null)
                        {
                            this.UploadQueue.Enqueue(uploader);
                        }
                    }
                    yield return(new WaitForEndOfFrame());
                }
            }
            yield return(null);
        }
        /// <summary>
        /// 取得拷贝源文件目录.
        /// </summary>
        /// <returns>取得拷贝源文件目录.</returns>
        public string GetAndroidCopyFromDir()
        {
            string dir = string.Format("{0}/../AndroidPlatform", Application.dataPath);

            if (false == Directory.Exists(dir))
            {
                UtilsLog.Warning("GetAndroidCopyFromDir", "The directory is not exist!!(Dir:{0})", dir);
                Directory.CreateDirectory(dir);
            }

            dir = string.Format("{0}/{1}", dir, this.PlatformType.ToString());
            if (false == Directory.Exists(dir))
            {
                UtilsLog.Warning("GetAndroidCopyFromDir", "The directory is not exist!!(Dir:{0})", dir);
                Directory.CreateDirectory(dir);
            }

            return(dir);
        }
Beispiel #9
0
        private void Log(string message, TLogType iType = TLogType.kInfo)
        {
            System.Console.WriteLine(message);
            if (BuildParameters.IsBuildInCI == false)
            {
                switch (iType)
                {
                case TLogType.kInfo:
                {
                    UtilsLog.Info("ConsoleBuildLogger",
                                  message);
                }
                break;

                case TLogType.kWarning:
                {
                    UtilsLog.Warning("ConsoleBuildLogger",
                                     message);
                }
                break;

                case TLogType.kError:
                {
                    UtilsLog.Error("ConsoleBuildLogger",
                                   message);
                }
                break;

                case TLogType.kException:
                {
                    UtilsLog.Exception("ConsoleBuildLogger",
                                       message);
                }
                break;

                default:
                    break;
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// 判断目标是否存在.
        /// </summary>
        /// <returns><c>true</c>,存在, <c>false</c> 不存在.</returns>
        /// <param name="iTargetID">目标ID.</param>
        /// <param name="iFileType">文件类型.</param>
        /// <param name="iTarget">目标信息.</param>
        private bool isTargetExist(string iTargetID, TUploadFileType iFileType, out UploadItem iTarget)
        {
            iTarget = null;

            UploadItem[] targets = this.Targets
                                   .Where(o => (
                                              (true == iTargetID.Equals(o.ID)) &&
                                              (iFileType == o.FileType)))
                                   .OrderBy(o => o.No)
                                   .ToArray();
            if ((targets == null) || (targets.Length <= 0))
            {
                return(false);
            }
            if (1 != targets.Length)
            {
                UtilsLog.Warning("isTargetExist",
                                 "There is duplicate id exist in upload list!!!(Bundle ID:{0})", iTargetID);
            }
            iTarget = targets [0];
            return(true);
        }
        /// <summary>
        /// 初始化下载队列.
        /// </summary>
        private IEnumerator initDownloadQueue()
        {
            // 初始化清空
            this.DownloadQueue.Clear();

            List <DownloadTargetInfo> targets = DownloadList.GetInstance().Targets;

            DownloadTargetInfo[] downloadTargets = targets
                                                   .Where(o => (false == o.Downloaded))
                                                   .ToArray();
            if ((downloadTargets == null) || (downloadTargets.Length <= 0))
            {
                this._State = TRunState.NoDownloadTarget;
                UtilsLog.Warning("initDownloadQueue", "There is no target to download!!!");
            }
            yield return(new WaitForEndOfFrame());

            if (TRunState.OK == this._State)
            {
                this.DownloaderCount = 0;
                int targetsCount = downloadTargets.Length;
                int maxCount     = ServersConf.GetInstance().ThreadMaxCount;
                this.DownloaderMaxCount = (targetsCount > maxCount) ? maxCount : targetsCount;
                // 遍历下载列表,并压进下载队列
                foreach (DownloadTargetInfo loop in downloadTargets)
                {
                    if (loop == null)
                    {
                        continue;
                    }

                    DownloaderBase downloader = CreateDownloader(loop);
                    if (downloader != null)
                    {
                        this.DownloadQueue.Enqueue(downloader);
                    }
                }
            }
        }