Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unity3d 使用开始时间在编辑器中播放音频_Unity3d_Audio_Unity Editor_Unity3d Editor - Fatal编程技术网

Unity3d 使用开始时间在编辑器中播放音频

Unity3d 使用开始时间在编辑器中播放音频,unity3d,audio,unity-editor,unity3d-editor,Unity3d,Audio,Unity Editor,Unity3d Editor,您好,我正在尝试在自定义编辑器中播放音频,并设置开始采样时间 public static void PlayClip(AudioClip clip, int startSample = 0, bool loop = false) { System.Reflection.Assembly unityEditorAssembly = typeof(AudioImporter).Assembly; System.Type audioUtilClass = unityEditorAsse

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

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 }
    );
}

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

大概你当前的代码不工作了?发生了什么事?@PhilippLenssen Yeah:)除了startSample之外,一切都正常……不管它的价值是什么,这首歌总是从一开始就开始。我在一些论坛上发现更多人有相同的问题和相同的代码,但似乎只有一个人知道解决方案,但我无法理解@PhilippLenssen如果你知道如何解决这个问题,请帮助我。我正在工作的编辑器扩展,我真的需要这个功能。如果我找不到解决方案,我将不得不更改大量代码,并在播放模式下使用扩展。如果你能帮我,这对我来说意义重大:)