首页 > 解决方案 > 在编辑器中播放带有开始时间的音频

问题描述

您好我正在尝试在自定义编辑器中播放音频并设置开始采样时间。

public static void PlayClip(AudioClip clip, int startSample = 0, bool loop = false)
{
    System.Reflection.Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
    System.Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
    System.Reflection.MethodInfo method = audioUtilClass.GetMethod(
        "PlayClip",
        System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public,
        null,
        new System.Type[] { typeof(AudioClip), typeof(int), typeof(bool) },
        null
    );
    method.Invoke(
        null,
        new object[] { clip, startSample, loop }
    );
}

如果有人知道该怎么做,请帮助我:)

标签: unity3daudiounity-editorunity3d-editor

解决方案


推荐阅读