there is only one cursor in screens.
This commit is contained in:
Binary file not shown.
@@ -54,14 +54,15 @@ public class Cursor : MonoBehaviour
|
||||
}
|
||||
|
||||
var cursorTexture = textures_[scale];
|
||||
monitor.UpdateCursorTexture(cursorTexture.GetNativeTexturePtr());
|
||||
monitor.GetCursorTexture(cursorTexture.GetNativeTexturePtr());
|
||||
uddTexture_.material.SetTexture("_CursorTex", cursorTexture);
|
||||
}
|
||||
|
||||
void UpdateMaterial()
|
||||
{
|
||||
var x = (float)monitor.cursorX / monitor.width;
|
||||
var y = (float)monitor.cursorY / monitor.height;
|
||||
Debug.Log(monitor.isCursorVisible);
|
||||
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));
|
||||
|
||||
@@ -98,7 +98,7 @@ public static class Lib
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern CursorShapeType GetCursorShapeType(int id);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern void UpdateCursorTexture(int id, System.IntPtr ptr);
|
||||
public static extern void GetCursorTexture(int id, System.IntPtr ptr);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int SetTexturePtr(int id, IntPtr ptr);
|
||||
|
||||
|
||||
@@ -12,7 +12,17 @@ public class Manager : MonoBehaviour
|
||||
{
|
||||
get
|
||||
{
|
||||
if (instance_) return instance_;
|
||||
if (instance_) {
|
||||
return instance_;
|
||||
}
|
||||
|
||||
var manager = FindObjectOfType<Manager>();
|
||||
if (manager) {
|
||||
manager.Awake();
|
||||
instance_ = manager;
|
||||
return instance_;
|
||||
}
|
||||
|
||||
var go = new GameObject("uDesktopDuplicationManager");
|
||||
return go.AddComponent<Manager>();
|
||||
}
|
||||
@@ -81,12 +91,19 @@ public class Manager : MonoBehaviour
|
||||
UpdateMessage();
|
||||
}
|
||||
|
||||
[ContextMenu("Reinitialize")]
|
||||
void Reinitialize()
|
||||
{
|
||||
Lib.Reinitialize();
|
||||
}
|
||||
|
||||
void ReinitializeIfNeeded()
|
||||
{
|
||||
for (int i = 0; i < monitors.Count; ++i) {
|
||||
var monitor = monitors[i];
|
||||
if (monitor.state == MonitorState.AccessLost ||
|
||||
monitor.state == MonitorState.AccessDenied) {
|
||||
monitor.state == MonitorState.AccessDenied ||
|
||||
monitor.state == MonitorState.SessionDisconnected) {
|
||||
if (!shouldReinitialize) {
|
||||
shouldReinitialize = true;
|
||||
reinitializationTimer = 0f;
|
||||
@@ -97,7 +114,7 @@ public class Manager : MonoBehaviour
|
||||
|
||||
if (shouldReinitialize) {
|
||||
if (reinitializationTimer > retryReinitializationDuration) {
|
||||
Lib.Reinitialize();
|
||||
Reinitialize();
|
||||
shouldReinitialize = false;
|
||||
}
|
||||
reinitializationTimer += Time.deltaTime;
|
||||
@@ -110,8 +127,7 @@ public class Manager : MonoBehaviour
|
||||
while (message != Message.None) {
|
||||
switch (message) {
|
||||
case Message.Reinitialized:
|
||||
Debug.Log("Reinitialize");
|
||||
Reinitialize();
|
||||
ReinitializeMonitors();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -141,7 +157,7 @@ public class Manager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
void Reinitialize()
|
||||
void ReinitializeMonitors()
|
||||
{
|
||||
for (int i = 0; i < monitorCount; ++i) {
|
||||
if (i == monitors.Count) {
|
||||
|
||||
@@ -8,6 +8,27 @@ public class Monitor
|
||||
public Monitor(int id)
|
||||
{
|
||||
this.id = id;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case MonitorState.InvalidArg:
|
||||
Debug.LogErrorFormat("[{0}:{1}] Invalid.", id, name);
|
||||
break;
|
||||
case MonitorState.AccessDenied:
|
||||
Debug.LogErrorFormat("[{0}:{1}] Access Denied.", id, name);
|
||||
break;
|
||||
case MonitorState.Unsupported:
|
||||
Debug.LogErrorFormat("[{0}:{1}] Unsupported.", id, name);
|
||||
break;
|
||||
case MonitorState.SessionDisconnected:
|
||||
Debug.LogErrorFormat("[{0}:{1}] Disconnected.", id, name);
|
||||
break;
|
||||
case MonitorState.NotSet:
|
||||
Debug.LogErrorFormat("[{0}:{1}] Something wrong.", id, name);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public int id
|
||||
@@ -150,9 +171,9 @@ public class Monitor
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateCursorTexture(System.IntPtr ptr)
|
||||
public void GetCursorTexture(System.IntPtr ptr)
|
||||
{
|
||||
Lib.UpdateCursorTexture(id, ptr);
|
||||
Lib.GetCursorTexture(id, ptr);
|
||||
}
|
||||
|
||||
void CreateTexture()
|
||||
|
||||
Reference in New Issue
Block a user