support display setting change in realtime.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class MultipleMonitorCreator : MonoBehaviour
|
||||
{
|
||||
@@ -6,7 +7,21 @@ public class MultipleMonitorCreator : MonoBehaviour
|
||||
[SerializeField] float width = 0.3f;
|
||||
[SerializeField] float margin = 1f;
|
||||
|
||||
void Start()
|
||||
private List<GameObject> monitors_ = new List<GameObject>();
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
Create();
|
||||
uDesktopDuplication.Manager.instance.onReinitialized += Recreate;
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
Clear();
|
||||
uDesktopDuplication.Manager.instance.onReinitialized -= Recreate;
|
||||
}
|
||||
|
||||
void Create()
|
||||
{
|
||||
// Sort monitors in coordinate order
|
||||
var monitors = uDesktopDuplication.Manager.monitors;
|
||||
@@ -19,6 +34,7 @@ public class MultipleMonitorCreator : MonoBehaviour
|
||||
// Create monitor obeject
|
||||
var go = Instantiate(monitorPrefab);
|
||||
go.name = "Monitor " + i;
|
||||
monitors_.Add(go);
|
||||
|
||||
// Assign monitor
|
||||
var texture = go.GetComponent<uDesktopDuplication.Texture>();
|
||||
@@ -41,9 +57,7 @@ public class MultipleMonitorCreator : MonoBehaviour
|
||||
// Set positions with margin
|
||||
totalWidth += margin * (n - 1);
|
||||
var x = -totalWidth / 2;
|
||||
for (int i = 0 ; i < n; ++i) {
|
||||
//
|
||||
var go = transform.FindChild("Monitor " + i);
|
||||
foreach (var go in monitors_) {
|
||||
var texture = go.GetComponent<uDesktopDuplication.Texture>();
|
||||
var halfScaleX = go.GetComponent<MeshFilter>().sharedMesh.bounds.extents.x;
|
||||
var w = texture.monitor.isHorizontal ? width : (width * texture.monitor.aspect);
|
||||
@@ -53,5 +67,19 @@ public class MultipleMonitorCreator : MonoBehaviour
|
||||
x += halfWidth + margin;
|
||||
}
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
foreach (var go in monitors_) {
|
||||
Destroy(go);
|
||||
}
|
||||
monitors_.Clear();
|
||||
}
|
||||
|
||||
void Recreate()
|
||||
{
|
||||
Clear();
|
||||
Create();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,6 @@ public class Cursor : MonoBehaviour
|
||||
|
||||
void UpdateMaterial()
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -19,8 +19,7 @@ public class Manager : MonoBehaviour
|
||||
var manager = FindObjectOfType<Manager>();
|
||||
if (manager) {
|
||||
manager.Awake();
|
||||
instance_ = manager;
|
||||
return instance_;
|
||||
return manager;
|
||||
}
|
||||
|
||||
var go = new GameObject("uDesktopDuplicationManager");
|
||||
@@ -48,12 +47,15 @@ public class Manager : MonoBehaviour
|
||||
}
|
||||
|
||||
[SerializeField] int desktopDuplicationApiTimeout = 0;
|
||||
[SerializeField] float retryReinitializationDuration = 0.5f;
|
||||
[SerializeField] float retryReinitializationDuration = 1f;
|
||||
|
||||
private Coroutine renderCoroutine_ = null;
|
||||
private bool shouldReinitialize = false;
|
||||
private float reinitializationTimer = 0f;
|
||||
|
||||
public delegate void ReinitializeHandler();
|
||||
public event ReinitializeHandler onReinitialized;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
Lib.InitializeUDD();
|
||||
@@ -89,19 +91,26 @@ public class Manager : MonoBehaviour
|
||||
Lib.Update();
|
||||
ReinitializeIfNeeded();
|
||||
UpdateMessage();
|
||||
|
||||
foreach (var monitor in monitors_) {
|
||||
Debug.LogFormat("[{0}] {1}", monitor.id, monitor.state);
|
||||
}
|
||||
}
|
||||
|
||||
[ContextMenu("Reinitialize")]
|
||||
void Reinitialize()
|
||||
{
|
||||
Debug.Log("[uDesktopDuplication] Reinitialize");
|
||||
Lib.Reinitialize();
|
||||
if (onReinitialized != null) onReinitialized();
|
||||
}
|
||||
|
||||
void ReinitializeIfNeeded()
|
||||
{
|
||||
for (int i = 0; i < monitors.Count; ++i) {
|
||||
var monitor = monitors[i];
|
||||
if (monitor.state == MonitorState.AccessLost ||
|
||||
if (monitor.state == MonitorState.NotSet ||
|
||||
monitor.state == MonitorState.AccessLost ||
|
||||
monitor.state == MonitorState.AccessDenied ||
|
||||
monitor.state == MonitorState.SessionDisconnected) {
|
||||
if (!shouldReinitialize) {
|
||||
|
||||
Reference in New Issue
Block a user