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