diff --git a/Assets/QFramework/Toolkits/ResKit/Scripts/LocalAudioSupport.cs b/Assets/QFramework/Toolkits/ResKit/Scripts/LocalAudioSupport.cs index bd027002..025d12cc 100644 --- a/Assets/QFramework/Toolkits/ResKit/Scripts/LocalAudioSupport.cs +++ b/Assets/QFramework/Toolkits/ResKit/Scripts/LocalAudioSupport.cs @@ -3,6 +3,7 @@ namespace QFramework using UnityEngine; using System.Collections; using UnityEngine.Networking; + using UnityEngine.Rendering; public static class LocalAudioResUtil { @@ -192,9 +193,30 @@ namespace QFramework } else { - // Convert the downloaded data to an AudioClip + // 等待下载完成 + while (!request.downloadHandler.isDone) + { + yield return null; + } + + + // 下载完成后,转换为 AudioClip AudioClip clip = DownloadHandlerAudioClip.GetContent(request); - mAsset = clip; + + if (clip != null) + { + // 检查音频加载状态 + while (clip.loadState != AudioDataLoadState.Loaded) + { + yield return null; + } + + mAsset = clip; // 音频加载完成后赋值给 mAsset + } + else + { + Debug.LogError("Failed to load audio clip."); + } } if (RefCount <= 0) diff --git a/Assets/Scripts/Actions/AnimationAction.cs b/Assets/Scripts/Actions/AnimationAction.cs index f2cc26a3..5a9691af 100644 --- a/Assets/Scripts/Actions/AnimationAction.cs +++ b/Assets/Scripts/Actions/AnimationAction.cs @@ -46,30 +46,39 @@ namespace QFramework GameObject obj = Utility.FindObj(path); if (obj != null) { - anim = obj.GetComponent(); + try + { + anim = obj.GetComponent(); - if (string.IsNullOrEmpty(frame) == false && frame != "-1") - { - int curFrame = 0; - int.TryParse(frame, out curFrame); - anim[animName].time = curFrame / anim.clip.frameRate; - anim[animName].speed = 0; - anim.Play(animName); - this.Finish(); - } - else - { - float curSpeed = 1; - if (string.IsNullOrEmpty(speed)==false) + if (string.IsNullOrEmpty(frame) == false && frame != "-1") { - float.TryParse(speed, out curSpeed); + int curFrame = 0; + int.TryParse(frame, out curFrame); + anim[animName].time = curFrame / anim.clip.frameRate; + anim[animName].speed = 0; + anim.Play(animName); + this.Finish(); + } + else + { + float curSpeed = 1; + if (string.IsNullOrEmpty(speed) == false) + { + float.TryParse(speed, out curSpeed); + } + anim[animName].speed = curSpeed; + anim.Play(animName); } - anim[animName].speed = curSpeed; - anim.Play(animName); } + catch (Exception) + { + Debug.LogError($"{path} 播放动画 {animName} 出错"); + } + } else { + Debug.LogError("未找到路径:" + path); this.Finish(); } }