Unity 2019.4.8f1 ではこちらの記事にひと工夫が必要でしたので、載せておきます。(元記事には感謝です!)
var clip = AssetDatabase.LoadAssetAtPath<AudioClip>(”[Assets/から始まるパス]");
if (clip == null) return;
System.Reflection.Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
System.Type audioUtilClass = unityEditorAssembly.GetType( "UnityEditor.AudioUtil" );
System.Reflection.MethodInfo method =
audioUtilClass.GetMethod(
"PlayClip",
BindingFlags.Static | BindingFlags.Public,
null,
new Type[] { typeof(AudioClip), typeof(int), typeof(bool) },
null
);
method.Invoke( null, new object[] { clip, 0, false } );
色のついた箇所が変更点です。
OnCompilationStarted() でレトロゲーのクレジット音をランダム再生したらやかましく、1日で断念しました。
