remove monitor if unsupported.
This commit is contained in:
@@ -4,6 +4,10 @@ using System.Collections.Generic;
|
|||||||
public class MultipleMonitorCreator : MonoBehaviour
|
public class MultipleMonitorCreator : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField] GameObject monitorPrefab;
|
[SerializeField] GameObject monitorPrefab;
|
||||||
|
[SerializeField] bool removeIfUnsupported = true;
|
||||||
|
[SerializeField] float removeWaitDuration = 5f;
|
||||||
|
bool hasMonitorUnsupportStateChecked = false;
|
||||||
|
float removeWaitTimer_ = 0f;
|
||||||
|
|
||||||
public class MonitorInfo
|
public class MonitorInfo
|
||||||
{
|
{
|
||||||
@@ -13,14 +17,21 @@ public class MultipleMonitorCreator : MonoBehaviour
|
|||||||
public Vector3 meshBounds;
|
public Vector3 meshBounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<MonitorInfo> monitors_ = new List<MonitorInfo>();
|
private List<MonitorInfo> monitors_ = new List<MonitorInfo>();
|
||||||
public List<MonitorInfo> monitors { get { return monitors_; } }
|
public List<MonitorInfo> monitors { get { return monitors_; } }
|
||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
Create();
|
Create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
if (removeIfUnsupported) {
|
||||||
|
RemoveUnsupportedDisplayAfterRemoveTimer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void OnEnable()
|
void OnEnable()
|
||||||
{
|
{
|
||||||
uDesktopDuplication.Manager.onReinitialized += Recreate;
|
uDesktopDuplication.Manager.onReinitialized += Recreate;
|
||||||
@@ -31,14 +42,37 @@ public class MultipleMonitorCreator : MonoBehaviour
|
|||||||
uDesktopDuplication.Manager.onReinitialized -= Recreate;
|
uDesktopDuplication.Manager.onReinitialized -= Recreate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RemoveUnsupportedDisplayAfterRemoveTimer()
|
||||||
|
{
|
||||||
|
if (!hasMonitorUnsupportStateChecked) {
|
||||||
|
removeWaitTimer_ += Time.deltaTime;
|
||||||
|
if (removeWaitTimer_ > removeWaitDuration) {
|
||||||
|
hasMonitorUnsupportStateChecked = true;
|
||||||
|
foreach (var info in monitors_) {
|
||||||
|
if (info.uddTexture.monitor.state == uDesktopDuplication.MonitorState.Unsupported) {
|
||||||
|
Destroy(info.gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResetRemoveTimer()
|
||||||
|
{
|
||||||
|
hasMonitorUnsupportStateChecked = false;
|
||||||
|
removeWaitTimer_ = 0f;
|
||||||
|
}
|
||||||
|
|
||||||
void Create()
|
void Create()
|
||||||
{
|
{
|
||||||
|
ResetRemoveTimer();
|
||||||
|
|
||||||
// Sort monitors in coordinate order
|
// Sort monitors in coordinate order
|
||||||
var monitors = uDesktopDuplication.Manager.monitors;
|
var monitors = uDesktopDuplication.Manager.monitors;
|
||||||
monitors.Sort((a, b) => a.left - b.left);
|
monitors.Sort((a, b) => a.left - b.left);
|
||||||
|
|
||||||
// Create monitors
|
// Create monitors
|
||||||
for (int i = 0 ; i < uDesktopDuplication.Manager.monitorCount; ++i) {
|
for (int i = 0; i < uDesktopDuplication.Manager.monitorCount; ++i) {
|
||||||
// Create monitor obeject
|
// Create monitor obeject
|
||||||
var go = Instantiate(monitorPrefab);
|
var go = Instantiate(monitorPrefab);
|
||||||
go.name = "Monitor " + i;
|
go.name = "Monitor " + i;
|
||||||
|
|||||||
Reference in New Issue
Block a user