This repository has been archived on 2025-04-28. You can view files and clone it, but cannot push or open issues or pull requests.
ARPlusSystem/ARPlusSystem-250418/Library/PackageCache/com.unity.xr.arcore@4.2.10/Runtime/ArString.cs

54 lines
1.2 KiB
C#

using System;
using System.Runtime.InteropServices;
using System.Text;
namespace UnityEngine.XR.ARCore
{
unsafe struct ArString : IDisposable
{
byte* m_Bytes;
public override string ToString() => m_Bytes == null
? string.Empty
: Marshal.PtrToStringAnsi(new IntPtr(m_Bytes));
public string ToString(Encoding encoding) => m_Bytes == null
? null
: encoding.GetString(m_Bytes, CalculateNullTerminatedByteCount());
public void Dispose()
{
if (m_Bytes != null)
{
Release(m_Bytes);
}
m_Bytes = null;
}
public int CalculateNullTerminatedByteCount()
{
if (m_Bytes == null)
{
return 0;
}
var bytes = m_Bytes;
var byteCount = 0;
while (*bytes++ != 0)
{
byteCount++;
}
return byteCount;
}
#if UNITY_ANDROID && !UNITY_EDITOR
[DllImport("arcore_sdk_c", EntryPoint = "ArString_release")]
static extern void Release(byte* str);
#else
static void Release(byte* str) { }
#endif
}
}