add clipping function and the example.
This commit is contained in:
@@ -60,9 +60,8 @@ public class Cursor : MonoBehaviour
|
||||
|
||||
void UpdateMaterial()
|
||||
{
|
||||
bool isVisible = monitor.isCursorVisible;
|
||||
var x = isVisible ? (float)monitor.cursorX / monitor.width : -9999f;
|
||||
var y = isVisible ? (float)monitor.cursorY / monitor.height : -9999f;
|
||||
var x = monitor.isCursorVisible ? (float)monitor.cursorX / monitor.width : -9999f;
|
||||
var y = monitor.isCursorVisible ? (float)monitor.cursorY / monitor.height : -9999f;
|
||||
var w = (float)monitor.cursorShapeWidth / monitor.width;
|
||||
var h = (float)monitor.cursorShapeHeight / monitor.height;
|
||||
uddTexture_.material.SetVector("_CursorPositionScale", new Vector4(x, y, w, h));
|
||||
|
||||
@@ -56,6 +56,8 @@ public static class Lib
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetMonitorCount();
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetCursorMonitorId();
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetTotalWidth();
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetTotalHeight();
|
||||
|
||||
@@ -38,6 +38,11 @@ public class Manager : MonoBehaviour
|
||||
get { return Lib.GetMonitorCount(); }
|
||||
}
|
||||
|
||||
static public int cursorMonitorId
|
||||
{
|
||||
get { return Lib.GetCursorMonitorId(); }
|
||||
}
|
||||
|
||||
static public Monitor primary
|
||||
{
|
||||
get
|
||||
|
||||
@@ -196,7 +196,7 @@ public class Monitor
|
||||
Lib.GetCursorTexture(id, ptr);
|
||||
}
|
||||
|
||||
void CreateTexture()
|
||||
public void CreateTexture()
|
||||
{
|
||||
if (!available) return;
|
||||
|
||||
|
||||
@@ -24,9 +24,15 @@ public class Texture : MonoBehaviour
|
||||
set { monitor = Manager.monitors[Mathf.Clamp(value, 0, Manager.monitorCount - 1)]; }
|
||||
}
|
||||
|
||||
[Header("Invert UVs")]
|
||||
public bool invertX = false;
|
||||
public bool invertY = false;
|
||||
|
||||
[Header("Clip")]
|
||||
public bool useClip = false;
|
||||
public Vector2 clipPos = Vector2.zero;
|
||||
public Vector2 clipScale = new Vector2(0.2f, 0.2f);
|
||||
|
||||
public Material material
|
||||
{
|
||||
get;
|
||||
@@ -55,6 +61,13 @@ public class Texture : MonoBehaviour
|
||||
}
|
||||
|
||||
void UpdateMaterial()
|
||||
{
|
||||
Invert();
|
||||
Rotate();
|
||||
Clip();
|
||||
}
|
||||
|
||||
void Invert()
|
||||
{
|
||||
if (invertX) {
|
||||
material.EnableKeyword("INVERT_X");
|
||||
@@ -67,7 +80,10 @@ public class Texture : MonoBehaviour
|
||||
} else {
|
||||
material.DisableKeyword("INVERT_Y");
|
||||
}
|
||||
}
|
||||
|
||||
void Rotate()
|
||||
{
|
||||
switch (monitor.rotation)
|
||||
{
|
||||
case MonitorRotation.Identity:
|
||||
@@ -94,6 +110,16 @@ public class Texture : MonoBehaviour
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Clip()
|
||||
{
|
||||
if (useClip) {
|
||||
material.EnableKeyword("USE_CLIP");
|
||||
material.SetVector("_ClipPositionScale", new Vector4(clipPos.x, clipPos.y, clipScale.x, clipScale.y));
|
||||
} else {
|
||||
material.DisableKeyword("USE_CLIP");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user