Files
UltimateFishing/Assets/Scripts/Assembly-CSharp/LIV/SDK/Unity/SharedTextureProtocol.cs
2026-02-21 16:45:37 +08:00

79 lines
1.5 KiB
C#

using System;
using System.Collections;
using System.Runtime.InteropServices;
using UnityEngine;
namespace LIV.SDK.Unity
{
[AddComponentMenu("LIV/SharedTextureProtocol")]
public class SharedTextureProtocol : MonoBehaviour
{
public static bool IsActive
{
get
{
return GetIsCaptureActive();
}
}
public static int TextureWidth
{
get
{
return GetTextureWidth();
}
}
public static int TextureHeight
{
get
{
return GetTextureHeight();
}
}
[DllImport("LIV_MR")]
private static extern IntPtr GetRenderEventFunc();
[DllImport("LIV_MR", EntryPoint = "LivCaptureIsActive")]
[return: MarshalAs(UnmanagedType.U1)]
private static extern bool GetIsCaptureActive();
[DllImport("LIV_MR", EntryPoint = "LivCaptureWidth")]
private static extern int GetTextureWidth();
[DllImport("LIV_MR", EntryPoint = "LivCaptureHeight")]
private static extern int GetTextureHeight();
[DllImport("LIV_MR", EntryPoint = "LivCaptureSetTextureFromUnity")]
private static extern void SetTexture(IntPtr texture);
public static void SetOutputTexture(Texture texture)
{
if (IsActive)
{
SetTexture(texture.GetNativeTexturePtr());
}
}
private void OnEnable()
{
StartCoroutine(CallPluginAtEndOfFrames());
}
private IEnumerator CallPluginAtEndOfFrames()
{
while (base.enabled)
{
yield return new WaitForEndOfFrame();
GL.IssuePluginEvent(GetRenderEventFunc(), 1);
}
}
private void OnDisable()
{
SetTexture(IntPtr.Zero);
}
}
}