/// <summary> /// 设置字体 /// </summary> /// <param name="textComponent">Text组件</param> /// <param name="text">要显示的文本的键</param> public void SetFont(Text textComponent, string text) { if (textComponent == null || string.IsNullOrEmpty(text)) { GuLog.Error(string.Format("----AnimationUtils.SetText.SetFont----textComponent is null: {0}, text is null or empty: {1}", textComponent == null, string.IsNullOrEmpty(text))); return; } string language = this.PlayerDataManager.GetLanguage(); TextElement textElement = this.I18NConfig.GetTextElement(text); if (textElement != null && this.FontConfig.IsValid(textElement.FontShortName)) {//使用配置文件中的字体设置 string fontFullName = this.FontConfig.GetFontFullName(textElement.FontShortName); GuLog.Debug(string.Format("----AnimationUtils.SetText----Font: {0}, Language: {1}", fontFullName, language)); textComponent.font = Resources.Load <Font>(string.Format("Font/{0}", fontFullName)); } else {//使用默认字体设置 string fontFullName = Gululu.Config.FontConfig.DEFAULT_FONT; GuLog.Debug(string.Format("----AnimationUtils.SetText----Font: {0}, Language: {1}", fontFullName, language)); textComponent.font = Font.CreateDynamicFontFromOSFont(fontFullName, textComponent.fontSize); } }
public void InitialSilenceTimeSection(List <SilenceTimeSectionFromServer> listSilenceTimeSectionFromServer, bool needSave = true) { DumpSilenceTimeData(listSilenceTimeSectionFromServer); SaveSilenceTimeSection(listSilenceTimeSectionFromServer); List <SilenceTimeSection> listSilenceTimeSection = new List <SilenceTimeSection>(); foreach (var section in listSilenceTimeSectionFromServer) { listSilenceTimeSection.Add(new SilenceTimeSection(section)); } InitialSilenceTimeSection(listSilenceTimeSection); FillClocksItemList(); if (listClocksItemSection.Count > 0) { GuLog.Debug("<><SilenceTimeDataManager>listClocksItemSection[0] hour:" + listClocksItemSection[0].clock_hour + "minute:" + listClocksItemSection[0].clock_min); DumpClocksItemSection(); } mCupClockManager.setOtherClock(mLocalChildInfoAgent.getChildSN(), listClocksItemSection, () => { GuLog.Info("<><SilenceTimeDataManager>set other alrm success !"); }, () => { GuLog.Error("<SilenceTimeDataManager><>set other alrm error !"); }); }
/// <summary> /// 从网络或缓存中获取Manifest文件 /// </summary> /// <param name="assetBundlePath">AssetBundle包相对路径</param> /// <param name="success">成功时的回调</param> /// <param name="failure">失败时的回调</param> /// <param name="forcedDownload">是否强制下载(即使本地存在文件也下载并覆盖)</param> /// <returns></returns> public IEnumerator LoadManifest(string assetBundlePath, Action <AssetBundleManifest> success = null, Action <FailureInfo> failure = null, bool forcedDownload = false) { if (string.IsNullOrEmpty(assetBundlePath)) {//AB包文件路径异常,退出下载 GuLog.Error("<><ResourceUtils.LoadManifest>assetBundlePath is null"); if (failure != null) { failure(new FailureInfo() { Interrupt = false, Message = "assetBundlePath is null" }); } yield break; } string fileName = string.Format("{0}/{1}", Application.persistentDataPath, assetBundlePath); Debug.LogFormat("<><ResourceUtils.LoadManifest>local file name: {0}", fileName); if (!this.CheckFolderExist(Path.GetDirectoryName(fileName))) {//逐级检查检查本地是否存在指定的目录,没有则创建 Debug.LogErrorFormat("<><ResourceUtils.LoadManifest>Folder Not Exist: {0}", Path.GetDirectoryName(fileName)); if (failure != null) { failure(new FailureInfo() { Interrupt = false, Message = string.Format("Folder Not Exist: {0}", Path.GetDirectoryName(fileName)) }); } yield break; } bool fileExisted = File.Exists(fileName) && !forcedDownload;//文件不存在或指定强制下载,都视为文件不存在 if (!fileExisted) { //如果manifest文件不存在则下载,否则啥也不做,继续AB包的下载 fileName = string.Format("{0}/{1}", this.serverPath, assetBundlePath); //拼接文件网络获取路径 Debug.LogFormat("<><ResourceUtils.LoadManifest>{0} file name: {1}", fileExisted ? "cache" : "server", fileName); WWW www = new WWW(fileName); yield return(www); if (string.IsNullOrEmpty(www.error)) {//如果文件原本不存在,则写文件到本地指定目录 fileName = string.Format("{0}/{1}", Application.persistentDataPath, assetBundlePath); Debug.LogFormat("<><ResourceUtils.LoadManifest>write file name: {0}", fileName); File.WriteAllBytes(fileName, www.bytes); } www.Dispose(); www = null; } }
public void SaveLanguage(string languageShortName) { if (this.LanConfig.IsValid(languageShortName)) { this.Language = languageShortName; this.saveObject <string>("Language", languageShortName); Debug.LogFormat("----PlayerDataManager.SaveLanguage----Languange: {0}", languageShortName); } else { GuLog.Error(string.Format("----PlayerDataManager.SaveVoicePercent----Save error, language: {0}", languageShortName)); } }
private void Update() { while (this.actions.Count > 0) { try { this.actions.Dequeue()(); } catch (Exception ex) { GuLog.Error(string.Format("执行回主线程的异步action发生错误:{0}", ex.Message)); } } }
private string CheckPetName(string operate, string petName) { if (petName.EndsWith("2")) { GuLog.Error(string.Format("----LocalPetInfoAgent.{0}----Petname ends with '2': {1}", operate, petName)); petName = petName.Replace("2", ""); GuLog.Error(string.Format("----LocalPetInfoAgent.{0}----Petname removed '2' {1}", operate, petName)); } else { GuLog.Debug(string.Format("----LocalPetInfoAgent.{0}----Petname is correct: {1}", operate, petName)); } return(petName); }
/// <summary> /// 根据语言设置文本和字体 /// </summary> /// <param name="textComponent">Text组件</param> /// <param name="text">要显示的文本的键</param> /// <param name="setFont">是否设置字体</param> public void SetText(Text textComponent, string text, bool setFont = false) { if (textComponent == null || string.IsNullOrEmpty(text)) { GuLog.Error(string.Format("----AnimationUtils.SetText.Parameters----textComponent is null: {0}, text is null or empty: {1}", textComponent == null, string.IsNullOrEmpty(text))); return; } textComponent.text = this.I18NConfig.GetText(text); if (setFont) { this.SetFont(textComponent, text); } }
/// <summary> /// 从网络或缓存中获取资源文件(音频、图片、模型等) /// </summary> /// <param name="filePath">资源文件相对路径</param> /// <param name="success">成功时的回调</param> /// <param name="failure">失败时的回调</param> /// <param name="forcedDownload">是否强制下载(即使本地存在文件也下载并覆盖)</param> /// <returns></returns> public IEnumerator LoadAsset(string filePath, Action <object> success = null, Action <FailureInfo> failure = null, bool forcedDownload = false) { if (string.IsNullOrEmpty(filePath)) {//音频文件路径异常,退出下载 GuLog.Error("<><ResourceUtils.LoadAsset>filePath is null"); if (failure != null) { failure(new FailureInfo() { Interrupt = false, Message = "filePath is null" }); } yield break; } if (FileTypes.IsAudio(filePath)) { yield return(this.LoadAudio(filePath, (audioClip) => { if (success != null) { success(audioClip); } }, failure, forcedDownload)); } else if (FileTypes.IsTexture(filePath)) { yield return(this.LoadTexture(filePath, (texture) => { if (success != null) { success(texture); } }, failure, forcedDownload)); } else if (FileTypes.IsAssetBundle(filePath)) { yield return(this.LoadAssetBundle(filePath, (assetBundle) => { if (success != null) { success(assetBundle); } }, failure, forcedDownload)); } else if (FileTypes.IsManifest(filePath)) { yield return(this.LoadManifest(filePath, (manifest) => { if (success != null) { success(manifest); } }, failure, forcedDownload)); } }
public void replaceAlarmList(string alarmInfo, Action success, Action error) { if (string.IsNullOrEmpty(alarmInfo)) { GuLog.Error("----AlarmManager.replaceAlarmList----parameter[string: alarmInfo] is null or empty"); return; } ClocksInfo clocksInfo = this.JsonUtils.String2Json <ClocksInfo>(alarmInfo); if (clocksInfo == null || clocksInfo.clocks == null) { GuLog.Error("----AlarmManager.replaceAlarmList----parameter[string: alarmInfo] can't convert to the type[ClocksInfo]"); return; } List <ClocksItem> deleteItems = new List <ClocksItem>(); clocksInfo.clocks.ForEach((clocksItem) => { if (clocksItem != null && clocksItem.clock_enable == 0) { deleteItems.Add(clocksItem); } }); if (deleteItems.Count > 0) { deleteItems.ForEach((clocksItem) => { clocksInfo.clocks.Remove(clocksItem); }); } alarmInfo = this.JsonUtils.Json2String(clocksInfo); GuLog.Debug(string.Format("----AlarmManager.replaceAlarmList----formatted alarmInfo: {0}", alarmInfo)); SetAlarmCallback callback = new SetAlarmCallback(); callback.setCallback(success, error); GuLog.Debug("<><AlarmManager> replaceAlarmList:" + alarmInfo); getAlarmManagerWrap().CallStatic("replaceAlarmList", alarmInfo, callback); }
/// <summary> /// 根据语言设置动画 /// </summary> /// <param name="spine">Spine动画组件</param> /// <param name="animationName">原来的动画名称</param> /// <param name="defaultAnimation">默认的动画名称(如果根据键值,也就是参数animationName找不到对应语言的动画,则播放默认名称的动画)</param> /// <param name="loop">是否循环</param> public void SetAnimation(SkeletonGraphic spine, string animationName, string defaultAnimation, bool loop = true) { if (spine == null || string.IsNullOrEmpty(animationName)) { GuLog.Error(string.Format("----AnimationUtils.SetAnimation.Parameters----spine is null: {0}, animationName is null or empty: {1}", spine == null, string.IsNullOrEmpty(animationName))); return; } string newAnimationName = this.I18NConfig.GetAnimationName(animationName); GuLog.Debug(string.Format("----AnimationUtils.SetAnimation----AnimationName: {0}, NewAnimationName: {1}", animationName, newAnimationName)); if (spine.AnimationState.Data.SkeletonData.Animations.Exists(t => t.Name == newAnimationName)) { GuLog.Debug(string.Format("----AnimationUtils.SetAnimation----Play: {0}", newAnimationName)); spine.AnimationState.SetAnimation(0, newAnimationName, loop); } else if (spine.AnimationState.Data.SkeletonData.Animations.Exists(t => t.Name == defaultAnimation)) { GuLog.Debug(string.Format("----AnimationUtils.SetAnimation----Play: {0}", defaultAnimation)); spine.AnimationState.SetAnimation(0, defaultAnimation, loop); } }
//数据转型(将网络下发的防打扰数据的格式转为本地格式) private ClocksInfo SilenceDatas2ClockInfos(string childsn, AllSilenceTimeSectionFromServer silenceDatas) { if (silenceDatas != null && silenceDatas.configs != null && silenceDatas.configs.Count > 0) { int id = 1; ClocksInfo clocksInfo = new ClocksInfo(); foreach (SilenceTimeSectionFromServer silenceData in silenceDatas.configs) { clocksInfo.clocks.Add(new ClocksItem() {//起始时间 id = id++, x_child_sn = childsn, clock_type = this.GetClockType(silenceData.type, "_begin"), clock_enable = silenceData.enable, clock_hour = silenceData.start_hour, clock_min = silenceData.start_min, clock_weekdays = silenceData.weekdays }); clocksInfo.clocks.Add(new ClocksItem() {//结束时间 id = id++, x_child_sn = childsn, clock_type = this.GetClockType(silenceData.type, "_end"), clock_enable = silenceData.enable, clock_hour = silenceData.end_hour, clock_min = silenceData.end_min, clock_weekdays = silenceData.weekdays }); } return(clocksInfo); } else { GuLog.Error("----CupClockManager.SilenceDatas2ClockInfos---->silenceDatas is null"); return(null); } }
/// <summary> /// 根据语言设置文本和字体 /// </summary> /// <param name="textComponent">Text组件</param> /// <param name="text">要显示的文本的键</param> /// <param name="setFont">是否设置字体</param> /// <param name="param">文本占位符对应的内容</param> public void SetText(Text textComponent, string text, bool setFont = false, params object[] param) { if (textComponent == null || string.IsNullOrEmpty(text) || param == null) { GuLog.Error(string.Format("----AnimationUtils.SetText.Parameters----textComponent is null: {0}, text is null or empty: {1}, param is null: {2}", textComponent == null, string.IsNullOrEmpty(text), param == null)); return; } try { string newText = this.I18NConfig.GetText(text); textComponent.text = string.Format(newText, param); if (setFont) { this.SetFont(textComponent, text); } } catch (Exception ex) { GuLog.Error(string.Format("----AnimationUtils.SetText.Parameters----Error: {0}", ex.Message)); } }
/// <summary> /// 从网络或缓存中获取图片 /// </summary> /// <param name="imagePath">图片相对路径</param> /// <param name="success">成功时的回调</param> /// <param name="failure">失败时的回调</param> /// <param name="forcedDownload">是否强制下载(即使本地存在文件也下载并覆盖)</param> /// <returns></returns> public IEnumerator LoadTexture(string imagePath, Action <Sprite> success = null, Action <FailureInfo> failure = null, bool forcedDownload = false) { if (string.IsNullOrEmpty(imagePath)) {//图片文件路径异常,退出下载 GuLog.Error("<><ResourceUtils.LoadTexture>imagePath is null"); if (failure != null) { failure(new FailureInfo() { Interrupt = false, Message = "imagePath is null" }); } yield break; } string fileName = string.Format("{0}/{1}", Application.persistentDataPath, imagePath); Debug.LogFormat("<><ResourceUtils.LoadTexture>local file name: {0}", fileName); if (!this.CheckFolderExist(Path.GetDirectoryName(fileName))) {//逐级检查检查本地是否存在指定的目录,没有则创建 Debug.LogErrorFormat("<><ResourceUtils.LoadTexture>Folder Not Exist: {0}", Path.GetDirectoryName(fileName)); if (failure != null) { failure(new FailureInfo() { Interrupt = false, Message = string.Format("Folder Not Exist: {0}", Path.GetDirectoryName(fileName)) }); } yield break; } bool fileExisted = File.Exists(fileName) && !forcedDownload; //文件不存在或指定强制下载,都视为文件不存在 fileName = string.Format("{0}/{1}", fileExisted ? this.localPath : this.serverPath, imagePath); //根据本地是否存在指定文件,拼接文件获取路径(本地或网络) Debug.LogFormat("<><ResourceUtils.LoadTexture>{0} file name: {1}", fileExisted ? "cache" : "server", fileName); WWW www = new WWW(fileName); yield return(www); if (!string.IsNullOrEmpty(www.error)) {//下载过程中遇到错误,退出下载 Debug.LogErrorFormat("<><ResourceUtils.LoadTexture>Download error: {0}({1})", www.error, fileName); string errorText = www.error; www.Dispose(); www = null; if (failure != null) { failure(new FailureInfo() { Interrupt = !this.IgnoreFileNotExisted, Message = string.Format("Download error: {0}({1})", errorText, fileName) }); } yield break; } else { if (!fileExisted) {//如果文件原本不存在,则写文件到本地指定目录 fileName = string.Format("{0}/{1}", Application.persistentDataPath, imagePath); Debug.LogFormat("<><ResourceUtils.LoadTexture>write file name: {0}", fileName); File.WriteAllBytes(fileName, www.bytes); } if (www.texture != null && success != null) { Sprite sprite = Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), Vector2.one * 0.5f); Debug.LogFormat("<><ResourceUtils.LoadTexture>Path: {0}, Rect: {1}", imagePath, sprite.rect); success(sprite); } www.Dispose(); www = null; } }
public override void DoAction() { bool error = true; string errorText = ""; GuLog.Debug(string.Format("<><DeleteAction.DoAction>todoid: {0}, content: {1}", this.data.todoid, this.data.content)); if (!string.IsNullOrEmpty(data.content)) { string[] parts = data.content.Split('='); if (parts != null && parts.Length == 2 && !string.IsNullOrEmpty(parts[0]) && !string.IsNullOrEmpty(parts[1])) { GuLog.Debug(string.Format("<><DeleteAction.DoAction>Type: {0}, Path: {1}", parts[0], parts[1])); try { switch (parts[0].ToUpper()) { case "FILE": { this.ResourceUtils.DeleteFile(parts[1], (result) => { error = false; }, (resultError) => { errorText = string.Format("<><DeleteAction.DoAction><delete file>Result error: {0}", resultError); }); } break; case "FOLDER": { this.ResourceUtils.DeleteFolder(parts[1], (result) => { error = false; }, (resultError) => { errorText = string.Format("<><DeleteAction.DoAction><delete folder>Result error: {0}", resultError); }); } break; case "MODULE": { this.ResourceUtils.DeleteModule(parts[1], (result) => { error = false; }, (resultError) => { errorText = string.Format("<><DeleteAction.DoAction><delete module>Result error: {0}", resultError); }); } break; default: errorText = string.Format("<><DeleteAction.DoAction><unknown operate>todoid: {0}, operate: {1}, path: {2}", this.data.todoid, parts[0], parts[1]); break; } } catch (Exception ex) { errorText = string.Format("<><DeleteAction.DoAction><unknown error>todoid: {0}, content: {1}, message: {0}", this.data.todoid, this.data.content, ex.Message); } } else { errorText = string.Format("<><DeleteAction.DoAction><content format error>todoid: {0}, content: {1}", this.data.todoid, this.data.content); } } else { errorText = string.Format("<><DeleteAction.DoAction><content is null>todoid: {0}, content: {1}", this.data.todoid, this.data.content); } if (error) { GuLog.Error(errorText); BuildBackAckBody(this.data.ack, errorText, "ERROR", this.data.todoid); } else { BuildBackAckBody(this.data.ack, "Delete", "OK", this.data.todoid); } Loom.QueueOnMainThread(() => { this.UIState.PushNewState(UIStateEnum.eRefreshMainByData); }); }
/************************************************私 有 方 法************************************************/ //读取语言配置文件 private void Parser(WWW www) { m_LoadOk = true; GuLog.Debug("ResConfigPath WWW::" + www.error); if (www.isDone && (www.error == null || www.error.Length == 0)) { SecurityParser xmlDoc = new SecurityParser(); GuLog.Debug("ResConfigPath" + www.text); xmlDoc.LoadXml(www.text); ArrayList allNodes = xmlDoc.ToXml().Children; foreach (SecurityElement xeResConfigs in allNodes) { //根节点 if (xeResConfigs.Tag == "ResConfigs") { //ResConfigs节点 ArrayList resConfigNodes = xeResConfigs.Children; foreach (SecurityElement xeResConfig in resConfigNodes) {//ResConfig节点 if (xeResConfig.Tag == "ResConfig") { string language = xeResConfig.Attribute("Language"); if (this.LanConfig.IsValid(language)) { ResConfig resConfig = new ResConfig() { Language = language }; ArrayList elementNodes = xeResConfig.Children; foreach (SecurityElement xeText in elementNodes) { if (xeText.Tag == "Text") {//TextElement节点 TextElement textElement = new TextElement() { Key = xeText.Attribute("Key"), Value = xeText.Attribute("Value") }; resConfig.TextElements.Add(textElement); } else if (xeText.Tag == "Image") {//ImageElement节点 ImageElement imageElement = new ImageElement() { Key = xeText.Attribute("Key"), Value = xeText.Attribute("Value") }; resConfig.ImageElements.Add(imageElement); } else if (xeText.Tag == "Animation") {//AnimationElement节点 AnimationElement animationElement = new AnimationElement() { Key = xeText.Attribute("Key"), Value = xeText.Attribute("Value") }; resConfig.AnimationElements.Add(animationElement); } else if (xeText.Tag == "Audio") {//AudioElement节点 AudioElement audioElement = new AudioElement() { Key = xeText.Attribute("Key"), Value = xeText.Attribute("Value") }; resConfig.AudioElements.Add(audioElement); } } this.resConfigs.Add(language, resConfig); } else { GuLog.Error(string.Format("----I18NConfig.Parser----ResConfigs.Language: {0}", language)); } } } } } //GuLog.Debug(string.Format("----I18NConfig.Parser----I18NConfig.xml: {0}", www.text)); } }
/// <summary> /// 从网络或缓存中获取AssetBundle包 /// </summary> /// <param name="assetBundlePath">AssetBundle包相对路径</param> /// <param name="success">成功时的回调</param> /// <param name="failure">失败时的回调</param> /// <param name="forcedDownload">是否强制下载(即使本地存在文件也下载并覆盖)</param> /// <returns></returns> public IEnumerator LoadAssetBundle(string assetBundlePath, Action <AssetBundle> success = null, Action <FailureInfo> failure = null, bool forcedDownload = false) { if (string.IsNullOrEmpty(assetBundlePath)) {//AB包文件路径异常,退出下载 GuLog.Error("<><ResourceUtils.LoadAssetBundle>assetBundlePath is null"); if (failure != null) { failure(new FailureInfo() { Interrupt = false, Message = "assetBundlePath is null" }); } yield break; } if (this.CheckAssetBundleBuffer(assetBundlePath) && success != null) { success(this.assetBundleBuffer[assetBundlePath]); Debug.LogFormat("<><ResourceUtils.LoadAssetBundle>AssetBundle '{0}' existed", assetBundlePath); yield break; } string fileName = string.Format("{0}/{1}", Application.persistentDataPath, assetBundlePath); Debug.LogFormat("<><ResourceUtils.LoadAssetBundle>local file name: {0}", fileName); if (!this.CheckFolderExist(Path.GetDirectoryName(fileName))) {//逐级检查检查本地是否存在指定的目录,没有则创建 Debug.LogErrorFormat("<><ResourceUtils.LoadAssetBundle>Folder Not Exist: {0}", Path.GetDirectoryName(fileName)); if (failure != null) { failure(new FailureInfo() { Interrupt = false, Message = string.Format("Folder Not Exist: {0}", Path.GetDirectoryName(fileName)) }); } yield break; } bool fileExisted = File.Exists(fileName) && !forcedDownload;//文件不存在或指定强制下载,都视为文件不存在 if (!fileExisted) { //如果AssetBundle包文件不存在则从服务器上下载,否则什么都不做 fileName = string.Format("{0}/{1}", this.serverPath, assetBundlePath); //拼接文件网络获取路径 Debug.LogFormat("<><ResourceUtils.LoadAssetBundle>{0} file name: {1}", fileExisted ? "cache" : "server", fileName); WWW www = new WWW(fileName); yield return(www); if (!string.IsNullOrEmpty(www.error)) {//下载过程中遇到错误,退出下载 Debug.LogErrorFormat("<><ResourceUtils.LoadAssetBundle>Download error: {0}({1})", www.error, fileName); string errorText = www.error; www.Dispose(); www = null; if (failure != null) { failure(new FailureInfo() { Interrupt = !this.IgnoreFileNotExisted, Message = string.Format("Download error: {0}({1})", errorText, fileName) }); } yield break; } else { if (!fileExisted) {//如果文件原本不存在,则写文件到本地指定目录 fileName = string.Format("{0}/{1}", Application.persistentDataPath, assetBundlePath); Debug.LogFormat("<><ResourceUtils.LoadAssetBundle>write file name: {0}", fileName); File.WriteAllBytes(fileName, www.bytes); } if (www.assetBundle != null && success != null) { if (!this.CheckAssetBundleBuffer(assetBundlePath)) { this.assetBundleBuffer.Add(assetBundlePath, www.assetBundle); } Debug.LogFormat("<><ResourceUtils.LoadAssetBundle>Path: {0}, AssetBundle: {1}", assetBundlePath, www.assetBundle.name); success(www.assetBundle); } www.Dispose(); www = null; } } }
/// <summary> /// 从网络或缓存中获取音频 /// </summary> /// <param name="audioPath">音频相对路径</param> /// <param name="success">成功时的回调</param> /// <param name="failure">失败时的回调</param> /// <param name="forcedDownload">是否强制下载(即使本地存在文件也下载并覆盖)</param> /// <returns></returns> public IEnumerator LoadAudio(string audioPath, Action <AudioClip> success = null, Action <FailureInfo> failure = null, bool forcedDownload = false) { if (string.IsNullOrEmpty(audioPath)) {//音频文件路径异常,退出下载 GuLog.Error("<><ResourceUtils.LoadAudio>audioPath is null"); if (failure != null) { failure(new FailureInfo() { Interrupt = false, Message = "audioPath is null" }); } yield break; } string fileName = string.Format("{0}/{1}", Application.persistentDataPath, audioPath); Debug.LogFormat("<><ResourceUtils.LoadAudio>local file name: {0}", fileName); if (!this.CheckFolderExist(Path.GetDirectoryName(fileName))) {//逐级检查检查本地是否存在指定的目录,没有则创建 Debug.LogErrorFormat("<><ResourceUtils.LoadAudio>Folder Not Exist: {0}", Path.GetDirectoryName(fileName)); if (failure != null) { failure(new FailureInfo() { Interrupt = false, Message = string.Format("Folder Not Exist: {0}", Path.GetDirectoryName(fileName)) }); } yield break; } bool fileExisted = File.Exists(fileName) && !forcedDownload; //文件不存在或指定强制下载,都视为文件不存在 fileName = string.Format("{0}/{1}", fileExisted ? this.localPath : this.serverPath, audioPath); //根据本地是否存在指定文件,拼接文件获取路径(本地或网络) Debug.LogFormat("<><ResourceUtils.LoadAudio>{0} file name: {1}", fileExisted ? "cache" : "server", fileName); WWW www = new WWW(fileName); yield return(www); if (!string.IsNullOrEmpty(www.error)) {//下载过程中遇到错误,退出下载 Debug.LogErrorFormat("<><ResourceUtils.LoadAudio>Download error: {0}({1})", www.error, fileName); string errorText = www.error; www.Dispose(); www = null; if (failure != null) { failure(new FailureInfo() { Interrupt = !this.IgnoreFileNotExisted, Message = string.Format("Download error: {0}({1})", errorText, fileName) }); } yield break; } else { if (!fileExisted) {//如果文件原本不存在,则写文件到本地指定目录 fileName = string.Format("{0}/{1}", Application.persistentDataPath, audioPath); Debug.LogFormat("<><ResourceUtils.LoadAudio>write file name: {0}", fileName); File.WriteAllBytes(fileName, www.bytes); } if (success != null) { AudioClip audioClip = www.GetAudioClipCompressed(); if (audioClip != null) { Debug.LogFormat("<><ResourceUtils.LoadAudio>Path: {0}, Size: {1}", audioPath, audioClip.length); success(audioClip); } } www.Dispose(); www = null; } }