private void ProcessNextGameReadyFile(RemoteAssetInfo currentFile, bool reprocess = false)
        {
            RemoteAssetInfo fileToDownload = null;

            if (currentFile == null)
            {
                fileToDownload = currentGameReadyFilesQueue.FirstOrDefault();
            }
            else
            {
                if (reprocess)
                {
                    fileToDownload = currentGameReadyFilesQueue.ElementAtOrDefault(currentGameReadyFilesQueue.IndexOf(currentFile));
                }
                else
                {
                    fileToDownload = currentGameReadyFilesQueue.ElementAtOrDefault(currentGameReadyFilesQueue.IndexOf(currentFile) + 1);
                }
            }

            if (fileToDownload != null)
            {
                isGameReadyQueueRunning = true;
                var downloadInfo = DownloadAsset(fileToDownload);
                downloadInfo.OnStatusUpdate += ProcessOnGameReadyFile_OnStatusUpdate;
            }
            else
            {
                OnGameReadyFilesCompleted();
                GameData.Save();
            }
        }
        public RemoteAssetDownloadInfo DownloadAsset(RemoteAssetInfo asset)
        {
            if (asset == null)
            {
                return(null);
            }
            RemoteAssetDownloadInfo downloadInfo = new RemoteAssetDownloadInfo();

            downloadInfo.Asset = asset;
            ProcessFile(downloadInfo);
            return(downloadInfo);
        }
        private void ReadManifest()
        {
            List <RemoteAssetInfo> allFilesToBeSynced = new List <RemoteAssetInfo>();

            string remoteAssetsPath = Application.persistentDataPath + MetaStateSettings._RemoteAssetsPersistantName;

            if (!Directory.Exists(remoteAssetsPath))
            {
                Directory.CreateDirectory(remoteAssetsPath);
            }


            var allFiles = this.AssetManifest.Files.ToList();

#if UNITY_IOS
            allFiles.Where(y => y.RelativeName.Contains("Android/")).ToList().ForEach(y => this.AssetManifest.Files.Remove(y));
#endif

#if UNITY_ANDROID
            allFiles.Where(y => y.RelativeName.Contains("iOS/")).ToList().ForEach(y => this.AssetManifest.Files.Remove(y));
#endif

            foreach (AssetFileInfo file in this.AssetManifest.Files)
            {
                bool   mustDownloadFile = false;
                string filename         = file.RelativeName;
                int    version          = 1;
                string lastFilePart     = "." + filename.Split('.').ToList().Last();

                if (lastFilePart.Contains(MetaStateSettings._AssetManagerVersionString))
                {
                    version  = Convert.ToInt32(lastFilePart.Replace(MetaStateSettings._AssetManagerVersionString, string.Empty));
                    filename = filename.Replace(lastFilePart, string.Empty);
                    file.LocalRelativeName = filename;
                }

                string fullFilename = remoteAssetsPath + @"/" + filename;
                file.FileName = fullFilename;

                //Will always be false unless it was a versioned file.
                if (version > 1 && version > GetFileVersion(file.LocalRelativeName))
                {
                    mustDownloadFile = true;
                }

                if (!File.Exists(fullFilename))
                {
                    mustDownloadFile = true;
                    //UnityEngine.Debug.Log(" MUST DOWNLOAD FILE " + fullFilename + " DOES NOT EXIST.");
                }
                else
                {
#if !UNITY_EDITOR
                    FileInfo fileInfo = new FileInfo(fullFilename);
                    if (fileInfo.Length != file.Size)
                    {
                        UnityEngine.Debug.Log(" MUST DOWNLOAD FILE " + fullFilename + " " + fileInfo.Length.ToString() + " VS " + file.Size.ToString());
                        mustDownloadFile = true;
                    }
#endif
                }


#if UNITY_EDITOR
                mustDownloadFile = true;
#endif
                var newFileInfo = new RemoteAssetInfo()
                {
                    File = file, RequireDownload = mustDownloadFile, Version = version
                };



                if (file.RelativeName.StartsWith(MetaStateSettings._AssetManagerStartupFolder))
                {
                    StartupFiles.Add(newFileInfo);
                }
                else if (file.RelativeName.StartsWith(MetaStateSettings._AssetManagerOnGameReady))
                {
                    OnGameReadyFiles.Add(newFileInfo);
                }
                else
                {
                    OnDemandFiles.Add(newFileInfo);
                }
            }

            lastManifestVersion = AssetManifest.ManifestVersion;
        }