【问题标题】:Can't Play AudioClips via Addressable Asset System无法通过可寻址资产系统播放音频剪辑
【发布时间】:2022-10-06 22:50:17
【问题描述】:

问题

我通过 Addressable Asset System 获取 AudioClip 并将其传递给 AudioSource 进行播放。如果我将 PlayMode 设置为 Use Asset Database,它可以正常播放,但如果我指定 Use Existing Build,它就不会播放。 请帮我。

我尝试过的事情

  1. 我从 Addressable Group 窗口执行了 New Build > Default Build Script,但情况并没有改善。另外,即使执行了Clean Build,也是一样的。

  2. 原以为自己采集没有做完,用​​DebugLog显示了采集到的AudioClip的名字,但是显示正常,认为采集好了。
    但是当我在编辑器中查看时,AudioClip 没有注册到 AudioSource 并且 VoiceTrack.clip = clip 没有正常完成。

  3. 我尝试将 AssetBundleCompression 设置切换为 UnCompressed,但没有效果。

    版本

    • Unity 版本 2021.3.10f1
    • Addressables 版本 1.19.19

    代码在相关部分

    主文件

    public async UniTask ExecuteAsync(CallInstReference reference, InstRunner runner, CancellationToken cancelToken)
    {
        AudioClip clip = await Addressables.LoadAssetAsync<AudioClip>(clipAddress.Get());
        reference.world.callSoundManager.PlayVoice(clip, duration );
            Addressables.Release(clip);
        }
    

    callSoundManager.cs

        public void PlayVoice( AudioClip clip , float duration = 0.2f , bool loop = false)
        {
            Debug.Log(clip.name + \" voiceStart\"); //currect clip name displayed.
            VoiceTrack.clip = clip; //no clip attached the audioSource in Editor
            VoiceTrack.loop = loop;
            VoiceTrack.Play();
            VoiceTrack.DOFade(1f, duration);
    
        }
    

    如果有什么遗漏,请评论。谢谢你。

    标签: c# unity3d


    【解决方案1】:

    自行解决。我试过了

    AudioClip 剪辑 = 等待 Addressables.LoadAssetAsync(clipAddress.Get());

    但似乎我需要取出手柄并等待单独的任务。抱歉,添麻烦了。以下代码工作正常。

    AsyncOperationHandle 句柄 = Addressables.LoadAssetAsync(key);等待 处理.任务;

    if (handle.Status == AsyncOperationStatus.Succeeded) 结果=句柄。结果;

    【讨论】:

    • 感谢与社区分享解决方案。请关闭问题。欢迎!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-03
    • 2018-05-11
    • 2021-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多