1
0
mirror of synced 2024-12-05 02:57:57 +01:00
WACVR/Assets/uWindowCapture/Runtime/UwcCursor.cs
2022-05-16 23:38:40 +02:00

76 lines
1.4 KiB
C#

using UnityEngine;
namespace uWindowCapture
{
public class UwcCursor
{
public UwcCursor()
{
onCaptured.AddListener(OnCaptured);
}
public int x
{
get { return Lib.GetCursorX(); }
}
public int y
{
get { return Lib.GetCursorY(); }
}
public int width
{
get { return Lib.GetCursorWidth(); }
}
public int height
{
get { return Lib.GetCursorHeight(); }
}
public Texture2D texture
{
get;
private set;
}
UwcEvent onCaptured_ = new UwcEvent();
public UwcEvent onCaptured
{
get { return onCaptured_; }
}
UwcEvent onTextureChanged_ = new UwcEvent();
public UwcEvent onTextureChanged
{
get { return onTextureChanged_; }
}
public void RequestCapture()
{
Lib.RequestCaptureCursor();
}
void OnCaptured()
{
}
public void CreateTextureIfNeeded()
{
var w = width;
var h = height;
if (w == 0 || h == 0) return;
if (!texture || texture.width != w || texture.height != h) {
texture = new Texture2D(w, h, TextureFormat.BGRA32, false);
texture.filterMode = FilterMode.Point;
texture.wrapMode = TextureWrapMode.Clamp;
Lib.SetCursorTexturePtr(texture.GetNativeTexturePtr());
onTextureChanged.Invoke();
}
}
}
}