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