void OnLoadCompleted(string data) { _localMd5 = FileUtils.GetMd5(data); FileReader rd = FileReader.CreateReader(SourceBase, SourceMd5FileURL, FileReader.FileType.REMOTE); //DebugConsole.Info("Load SourceMd5FileURL: [" + rd.FullFileName + "] update success!"); rd.OnReadCompleted = (reader) => { if (reader.Success) { _targetMd5 = FileUtils.GetMd5(reader.TextData); if (_localMd5 == _targetMd5) { #if UNITY_EDITOR Debug.Log("Md5File:" + PersistentBase + PersistentMd5File + " Don't need to update!"); #else DebugConsole.Info("Md5File:" + PersistentMd5File + "Don't need to update!"); #endif } GetModifiedFiles(data, reader.TextData); } LoadMd5Success = reader.Success; LoadMd5Completed = true; }; rd.ReadAsync(); }
/// <summary> /// 开始异步更新持久化数据文件 /// </summary> public void UpdatePersistentFilesAsync(string sourcePath) { if (_deletedcount > 0) { //先删除已经丢弃的文件 foreach (var item in _deletedFiles) { if (File.Exists(PersistentBase + item.FullPath)) { File.Delete(PersistentBase + item.FullPath); } } } if (ModifiedFiles > 0) { foreach (var md5filedata in _latestFiles) { DebugConsole.Info("Begin update [" + md5filedata.FullPath + "] !"); FileReader reader = FileReader.CreateReader(sourcePath, md5filedata.FullPath, FileReader.FileType.REMOTE); reader.OnReadCompleted = (rd) => { FileWriter writer = new PersistentFileWriter(rd.ByteData, PersistentBase + rd.FilePath); writer.OnWriteCompleted = OnWirteComplete; writer.WriteAsync(); }; reader.ReadAsync(); } } else { UpdateCompleted = true; } }
public override void DoAsync() { if (!File.Exists(FullFileName)) { DirectoryInfo di = new DirectoryInfo(FullFileName); if (!di.Parent.Exists) { CreateDir(di.Parent); #if UNITY_EDITOR Debug.Log("Create Dir:" + di.Parent.FullName); #else DebugConsole.Info("Create Dir:" + di.Parent.FullName); #endif } FileStream file = File.Create(FullFileName); file.Close(); file.Dispose(); file = null; } WriteStream = File.OpenWrite(FullFileName); WriteStream.SetLength(0); WriteStream.BeginWrite(Content, 0, Content.Length, new AsyncCallback(On_Write_Callback), this); }
public void WriteAsync() { DebugConsole.Info("Begin Wirete [" + FullFileName + "] !"); IsCompleted = false; #if NONE FileUtils.WritePersistentFile(Content, FullFileName); OnCompleted(); IsCompleted = true; #else DoAsync(); #endif }
protected virtual void OnCompleted(string data, byte[] bytes) { IsCompleted = true; TextData = data; ByteData = bytes; Success = true; DebugConsole.Info("Read [" + SourcePath + FilePath + "] success!"); OnReadCompleted.Dispatch(this); if (_loader != null) { _loader.DestroySelf(); } }
/// <summary> /// 开始异步读取 /// </summary> public void ReadAsync() { DebugConsole.Info("Begin read file [" + SourcePath + FilePath + "] !"); IsCompleted = false; #if NONE TextData = FileUtils.ReadFile(SourcePath + FilePath); OnCompleted(TextData); IsCompleted = true; #else GameObject go = new GameObject(FilePath.Replace("/", "")); _loader = go.AddComponent <FileAsyncProcessor>(); _loader.LoadFile(this); #endif }
/// <summary> /// 加载完成时 /// </summary> protected void LoadComplete() { State = LoaderState.complete; if (debug) { DebugConsole.Info("Loader", "加载完成", this.url, CurrentDataSource.ToString()); } OnLoadCompleteHandler(); onLoadComplete.Dispatch(this); onLoadComplete.Clear(); if (CurrentDataSource.source != DownLoadAgent.DataSourceType.Cache) { SaveToLocal(); } }
public override IEnumerator DoAsync() { using (WWW www = new WWW(SourcePath + FilePath)) { yield return(www); if (www.isDone && string.IsNullOrEmpty(www.error)) { DebugConsole.Info("Bytes:" + www.bytesDownloaded); OnCompleted(www.text, www.bytes); } else { OnError(www.error); } } }
void CreateDir(DirectoryInfo dirInfo) { if (!dirInfo.Parent.Exists) { CreateDir(dirInfo.Parent); } else { #if UNITY_EDITOR Debug.Log("Create Dir:" + dirInfo.FullName); #else DebugConsole.Info("Create Dir:" + dirInfo.FullName); #endif //dirInfo.Create(); Directory.CreateDirectory(dirInfo.FullName); } }
/// <summary> /// 加载MD5版本文件 /// </summary> public void LoadMd5VersionFile() { Init(); if (!File.Exists(PersistentBase + PersistentMd5File)) { FileReader rd = FileReader.CreateReader(SourceBase, SourceMd5FileURL, FileReader.FileType.REMOTE); rd.OnReadCompleted = (reader) => { if (reader.Success) { //DebugConsole.Info("Load Remote: [" + rd.FullFileName + "] success!"); GetModifiedFiles("", reader.TextData); } else { DebugConsole.Info("Load PERSISTENT: [" + rd.SourcePath + rd.FilePath + "] update faild!"); } LoadMd5Success = reader.Success; LoadMd5Completed = true; }; rd.ReadAsync(); } else { FileReader rd = FileReader.CreateReader(PersistentBase, PersistentMd5File, FileReader.FileType.PERSISTENT); rd.OnReadCompleted = (reader) => { if (reader.Success) { OnLoadCompleted(reader.TextData); } else { DebugConsole.Info("Load PERSISTENT: [" + rd.SourcePath + rd.FilePath + "] update faild!"); LoadMd5Success = reader.Success; LoadMd5Completed = true; } }; rd.ReadAsync(); } }
void OnWirteComplete(FileWriter writer) { if (writer.IsCompleted) { IncProgress(true); #if UNITY_EDITOR Debug.Log("File [" + writer.FullFileName + "] update success!"); #else DebugConsole.Info("File [" + writer.FullFileName + "] update success!"); #endif } else { #if UNITY_EDITOR Debug.LogError("File [" + writer.FullFileName + "] update faild!"); #else DebugConsole.Error("File [" + writer.FullFileName + "] update faild!"); #endif } }
public static void WritePersistentFile(string content, string persistentFile) { if (!File.Exists(persistentFile)) { DirectoryInfo di = new DirectoryInfo(persistentFile); if (!di.Parent.Exists) { di.Parent.Create(); #if UNITY_EDITOR Debug.Log("Create Dir:" + di.Parent.FullName); #else DebugConsole.Info("Create Dir:" + di.Parent.FullName); #endif } FileStream file = File.Create(persistentFile); file.Close(); file.Dispose(); file = null; } FileStream writer = File.OpenWrite(persistentFile); using (StreamWriter sw = new StreamWriter(writer)) { writer.SetLength(0); sw.Write(content); sw.Flush(); sw.Close(); sw.Dispose(); } writer.Close(); writer.Dispose(); writer = null; }
public virtual void Play() { DebugConsole.Info("动作", "执行", string.IsNullOrEmpty(this.ActionName) ? this.GetType().Name : ActionName); State.SetState(ActionState.Play); }
public void StateDebug(string StateName) { DebugConsole.Info("动作", "PlayState", StateName, PackPlayer.name); }
IEnumerator LoadingSequence() { int i = 0; while (i < config.dataSources.Count) { CurrentDataSource = config.dataSources[i]; if (debug) { DebugConsole.Info("Loader", "加载URl", url, CurrentDataSource.ToString() + id.ToString()); } switch (CurrentDataSource.source) { case DownLoadAgent.DataSourceType.Cache: if (this.HasLocal()) { Coroutine async = this.LoadFromLocal(); if (debug) { DebugConsole.Info("Loader", "本地缓存", (async == null).ToString(), id.ToString()); } //异步加载中 if (async != null) { yield return(async); } if (this.State == LoaderState.complete) { this.LoadComplete(); yield break; } else { i++; continue; } } else { i++; continue; } case DownLoadAgent.DataSourceType.Resource: Coroutine Resasync = this.LoadFromResource(); if (debug) { DebugConsole.Info("Loader", "资源文件", (Resasync == null).ToString(), id.ToString()); } //异步加载中 if (Resasync != null) { yield return(Resasync); } if (this.State == LoaderState.complete) { this.LoadComplete(); yield break; } else { i++; continue; } case DownLoadAgent.DataSourceType.StreamAsset: try { www = new WWW(url); } catch (Exception e) { if (debug) { DebugConsole.Info("Loader", "StreamAsset", "加载失败", id.ToString()); } i++; continue; } yield return(www); if (!String.IsNullOrEmpty(www.error)) //出错 { DebugConsole.Warning("Loader", "Server", this.url, www.error); www = null; //直接释放 i++; continue; } else if (www.isDone) { LoadComplete(); yield break; } i++; continue; case DownLoadAgent.DataSourceType.Server: if (this.HasNewVersion()) { try { www = new WWW(url); } catch (Exception e) { if (debug) { DebugConsole.Info("Loader", "Server", "加载失败", id.ToString()); } i++; continue; } yield return(www); if (!String.IsNullOrEmpty(www.error)) //出错 { DebugConsole.Warning("Loader", "Server", this.url, www.error); www = null; //直接释放 i++; continue; } else if (www.isDone) { LoadComplete(); yield break; } } i++; continue; } } this.LoadError(); }