Skip to content

Instantly share code, notes, and snippets.

@martindevans
Created March 3, 2022 17:19
Show Gist options
  • Save martindevans/397afa11580fbf0da46072f900cab17f to your computer and use it in GitHub Desktop.
Save martindevans/397afa11580fbf0da46072f900cab17f to your computer and use it in GitHub Desktop.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using UnityEngine;
namespace Assets
{
public class TestOpus
: MonoBehaviour
{
public bool TestNow;
void Update()
{
if (TestNow)
{
TestNow = false;
Debug.Log(OpusVersion());
}
}
public static string OpusVersion()
{
// ReSharper disable once AssignNullToNotNullAttribute
return Marshal.PtrToStringAnsi(OpusNativeMethods.opus_get_version_string());
}
#if UNITY_IOS && !UNITY_EDITOR
private const string ImportString = "__Internal";
private const CallingConvention Convention = CallingConvention.Cdecl;
#else
private const string ImportString = "opus";
private const CallingConvention Convention = CallingConvention.Cdecl;
#endif
/// <summary>
/// General opus methods
/// </summary>
private static partial class OpusNativeMethods
{
#if UNITY_IOS && !UNITY_EDITOR
[DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
#else
[DllImport(ImportString, EntryPoint = "opus_get_version_string", CallingConvention = CallingConvention.Cdecl)]
#endif
internal static extern IntPtr opus_get_version_string();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment