fix singleton bug.
This commit is contained in:
@@ -8,20 +8,30 @@ public class MultipleMonitorCreator : MonoBehaviour
|
|||||||
[SerializeField] float margin = 1f;
|
[SerializeField] float margin = 1f;
|
||||||
|
|
||||||
private List<GameObject> monitors_ = new List<GameObject>();
|
private List<GameObject> monitors_ = new List<GameObject>();
|
||||||
|
private float totalWidth_ = 0f;
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
Create();
|
||||||
|
}
|
||||||
|
|
||||||
void OnEnable()
|
void OnEnable()
|
||||||
{
|
{
|
||||||
Create();
|
uDesktopDuplication.Manager.onReinitialized += Recreate;
|
||||||
uDesktopDuplication.Manager.instance.onReinitialized += Recreate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnDisable()
|
void OnDisable()
|
||||||
{
|
{
|
||||||
Clear();
|
uDesktopDuplication.Manager.onReinitialized -= Recreate;
|
||||||
uDesktopDuplication.Manager.instance.onReinitialized -= Recreate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Create()
|
void Create()
|
||||||
|
{
|
||||||
|
CreateMonitors();
|
||||||
|
LayoutMonitors();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreateMonitors()
|
||||||
{
|
{
|
||||||
// Sort monitors in coordinate order
|
// Sort monitors in coordinate order
|
||||||
var monitors = uDesktopDuplication.Manager.monitors;
|
var monitors = uDesktopDuplication.Manager.monitors;
|
||||||
@@ -29,7 +39,7 @@ public class MultipleMonitorCreator : MonoBehaviour
|
|||||||
|
|
||||||
// Create monitors
|
// Create monitors
|
||||||
var n = monitors.Count;
|
var n = monitors.Count;
|
||||||
var totalWidth = 0f;
|
totalWidth_ = 0f;
|
||||||
for (int i = 0 ; i < n; ++i) {
|
for (int i = 0 ; i < n; ++i) {
|
||||||
// Create monitor obeject
|
// Create monitor obeject
|
||||||
var go = Instantiate(monitorPrefab);
|
var go = Instantiate(monitorPrefab);
|
||||||
@@ -51,12 +61,15 @@ public class MultipleMonitorCreator : MonoBehaviour
|
|||||||
|
|
||||||
// Calc actual size considering mesh size
|
// Calc actual size considering mesh size
|
||||||
var scaleX = go.GetComponent<MeshFilter>().sharedMesh.bounds.extents.x * 2f;
|
var scaleX = go.GetComponent<MeshFilter>().sharedMesh.bounds.extents.x * 2f;
|
||||||
totalWidth += w * scaleX;
|
totalWidth_ += w * scaleX;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LayoutMonitors()
|
||||||
|
{
|
||||||
// Set positions with margin
|
// Set positions with margin
|
||||||
totalWidth += margin * (n - 1);
|
totalWidth_ += margin * (monitors_.Count - 1);
|
||||||
var x = -totalWidth / 2;
|
var x = -totalWidth_ / 2;
|
||||||
foreach (var go in monitors_) {
|
foreach (var go in monitors_) {
|
||||||
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;
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class Manager : MonoBehaviour
|
|||||||
private float reinitializationTimer = 0f;
|
private float reinitializationTimer = 0f;
|
||||||
|
|
||||||
public delegate void ReinitializeHandler();
|
public delegate void ReinitializeHandler();
|
||||||
public event ReinitializeHandler onReinitialized;
|
public static event ReinitializeHandler onReinitialized;
|
||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
@@ -92,9 +92,11 @@ public class Manager : MonoBehaviour
|
|||||||
ReinitializeIfNeeded();
|
ReinitializeIfNeeded();
|
||||||
UpdateMessage();
|
UpdateMessage();
|
||||||
|
|
||||||
|
/*
|
||||||
foreach (var monitor in monitors_) {
|
foreach (var monitor in monitors_) {
|
||||||
Debug.LogFormat("[{0}] {1}", monitor.id, monitor.state);
|
Debug.LogFormat("[{0}] {1}", monitor.id, monitor.state);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
[ContextMenu("Reinitialize")]
|
[ContextMenu("Reinitialize")]
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ Properties
|
|||||||
_Color ("Color", Color) = (1, 1, 1, 1)
|
_Color ("Color", Color) = (1, 1, 1, 1)
|
||||||
_MainTex ("Texture", 2D) = "white" {}
|
_MainTex ("Texture", 2D) = "white" {}
|
||||||
[Toggle(USE_BEND)] _UseBend("UseBend", Float) = 0
|
[Toggle(USE_BEND)] _UseBend("UseBend", Float) = 0
|
||||||
[PowerSlider(10.0)]_Radius ("Radius", Range(3, 100)) = 10
|
[PowerSlider(10.0)]_Radius ("Radius", Range(10, 100)) = 30
|
||||||
[KeywordEnum(Off, Front, Back)] _Cull("Culling", Int) = 2
|
[KeywordEnum(Off, Front, Back)] _Cull("Culling", Int) = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user