get dpi of monitor and calculate actual size of it.
This commit is contained in:
@@ -4,7 +4,7 @@ using System.Collections.Generic;
|
||||
public class MultipleMonitorCreator : MonoBehaviour
|
||||
{
|
||||
[SerializeField] GameObject monitorPrefab;
|
||||
[SerializeField] float width = 0.3f;
|
||||
[SerializeField] float scale = 1f;
|
||||
[SerializeField] float margin = 1f;
|
||||
|
||||
private List<GameObject> monitors_ = new List<GameObject>();
|
||||
@@ -49,19 +49,17 @@ public class MultipleMonitorCreator : MonoBehaviour
|
||||
// Assign monitor
|
||||
var texture = go.GetComponent<uDesktopDuplication.Texture>();
|
||||
texture.monitorId = i;
|
||||
var monitor = texture.monitor;
|
||||
|
||||
// Set width / height
|
||||
var isHorizontal = texture.monitor.isHorizontal;
|
||||
var w = isHorizontal ? width : (width * texture.monitor.aspect);
|
||||
var h = isHorizontal ? width / texture.monitor.aspect : width;
|
||||
go.transform.localScale = new Vector3(w, go.transform.localScale.y, h);
|
||||
go.transform.localScale = new Vector3(monitor.widthMeter, go.transform.localScale.y, monitor.heightMeter);
|
||||
|
||||
// Set parent as this object
|
||||
go.transform.SetParent(transform);
|
||||
|
||||
// Calc actual size considering mesh size
|
||||
var scaleX = go.GetComponent<MeshFilter>().sharedMesh.bounds.extents.x * 2f;
|
||||
totalWidth_ += w * scaleX;
|
||||
totalWidth_ += monitor.widthMeter * scaleX;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,10 +69,10 @@ public class MultipleMonitorCreator : MonoBehaviour
|
||||
totalWidth_ += margin * (monitors_.Count - 1);
|
||||
var x = -totalWidth_ / 2;
|
||||
foreach (var go in monitors_) {
|
||||
var texture = go.GetComponent<uDesktopDuplication.Texture>();
|
||||
var monitor = go.GetComponent<uDesktopDuplication.Texture>().monitor;
|
||||
var halfScaleX = go.GetComponent<MeshFilter>().sharedMesh.bounds.extents.x;
|
||||
var w = texture.monitor.isHorizontal ? width : (width * texture.monitor.aspect);
|
||||
var halfWidth = w * halfScaleX;
|
||||
var width = monitor.widthMeter;
|
||||
var halfWidth = width * halfScaleX;
|
||||
x += halfWidth;
|
||||
go.transform.localPosition = new Vector3(x, 0f, 0f);
|
||||
x += halfWidth + margin;
|
||||
|
||||
Binary file not shown.
@@ -80,6 +80,10 @@ public static class Lib
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetHeight(int id);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetDpiX(int id);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetDpiY(int id);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern MonitorRotation GetRotation(int id);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern bool IsPrimary(int id);
|
||||
|
||||
@@ -92,6 +92,26 @@ public class Monitor
|
||||
get { return Lib.GetHeight(id); }
|
||||
}
|
||||
|
||||
public int dpiX
|
||||
{
|
||||
get { return Lib.GetDpiX(id); }
|
||||
}
|
||||
|
||||
public int dpiY
|
||||
{
|
||||
get { return Lib.GetDpiY(id); }
|
||||
}
|
||||
|
||||
public float widthMeter
|
||||
{
|
||||
get { return width / dpiX * 0.0254f; }
|
||||
}
|
||||
|
||||
public float heightMeter
|
||||
{
|
||||
get { return height / dpiY * 0.0254f; }
|
||||
}
|
||||
|
||||
public MonitorRotation rotation
|
||||
{
|
||||
get { return Lib.GetRotation(id); }
|
||||
|
||||
Reference in New Issue
Block a user