support hot-reload.
This commit is contained in:
@@ -1,18 +1,22 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
[RequireComponent(typeof(uDesktopDuplication.Texture)),
|
||||||
|
RequireComponent(typeof(uDesktopDuplication.Cursor))]
|
||||||
public class Loupe : MonoBehaviour
|
public class Loupe : MonoBehaviour
|
||||||
{
|
{
|
||||||
private uDesktopDuplication.Texture uddTexture_;
|
private uDesktopDuplication.Texture uddTexture_;
|
||||||
|
private uDesktopDuplication.Cursor uddCursor_;
|
||||||
public float zoom = 3f;
|
public float zoom = 3f;
|
||||||
public float aspect = 1f;
|
public float aspect = 1f;
|
||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
uddTexture_ = GetComponent<uDesktopDuplication.Texture>();
|
uddTexture_ = GetComponent<uDesktopDuplication.Texture>();
|
||||||
|
uddCursor_ = GetComponent<uDesktopDuplication.Cursor>();
|
||||||
uddTexture_.useClip = true;
|
uddTexture_.useClip = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update()
|
void LateUpdate()
|
||||||
{
|
{
|
||||||
CheckVariables();
|
CheckVariables();
|
||||||
|
|
||||||
@@ -26,11 +30,12 @@ public class Loupe : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
var monitor = uddTexture_.monitor;
|
var monitor = uddTexture_.monitor;
|
||||||
var cursorX = monitor.isCursorVisible ? monitor.cursorX : monitor.systemCursorX;
|
var x = monitor.isCursorVisible ?
|
||||||
var cursorY = monitor.isCursorVisible ? monitor.cursorY : monitor.systemCursorY;
|
uddCursor_.coord.x :
|
||||||
|
(float)monitor.systemCursorX / monitor.width;
|
||||||
var x = (float)cursorX / monitor.width;
|
var y = monitor.isCursorVisible ?
|
||||||
var y = (float)cursorY / monitor.height;
|
uddCursor_.coord.y :
|
||||||
|
(float)monitor.systemCursorY / monitor.height;
|
||||||
var w = 1f / zoom;
|
var w = 1f / zoom;
|
||||||
var h = w / aspect * monitor.aspect;
|
var h = w / aspect * monitor.aspect;
|
||||||
x = Mathf.Clamp(x - w / 2, 0f, 1f - w);
|
x = Mathf.Clamp(x - w / 2, 0f, 1f - w);
|
||||||
@@ -40,7 +45,7 @@ public class Loupe : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CheckVariables()
|
void CheckVariables()
|
||||||
{
|
{
|
||||||
if (zoom < 1f) zoom = 1f;
|
if (zoom < 1f) zoom = 1f;
|
||||||
if (aspect < 0.01f) aspect = 0.01f;
|
if (aspect < 0.01f) aspect = 0.01f;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using UnityEngine.Assertions;
|
using UnityEngine.Assertions;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using MeshForwardDirection = uDesktopDuplication.Texture.MeshForwardDirection;
|
using MeshForwardDirection = uDesktopDuplication.Texture.MeshForwardDirection;
|
||||||
|
using MonitorState = uDesktopDuplication.MonitorState;
|
||||||
|
|
||||||
public class MultipleMonitorCreator : MonoBehaviour
|
public class MultipleMonitorCreator : MonoBehaviour
|
||||||
{
|
{
|
||||||
@@ -36,12 +37,6 @@ public class MultipleMonitorCreator : MonoBehaviour
|
|||||||
bool hasMonitorUnsupportStateChecked_ = false;
|
bool hasMonitorUnsupportStateChecked_ = false;
|
||||||
float removeWaitTimer_ = 0f;
|
float removeWaitTimer_ = 0f;
|
||||||
|
|
||||||
public class SavedMonitorInfo
|
|
||||||
{
|
|
||||||
public float widthScale = 1f;
|
|
||||||
public float heightScale = 1f;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class MonitorInfo
|
public class MonitorInfo
|
||||||
{
|
{
|
||||||
public GameObject gameObject { get; set; }
|
public GameObject gameObject { get; set; }
|
||||||
@@ -54,6 +49,12 @@ public class MultipleMonitorCreator : MonoBehaviour
|
|||||||
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_; } }
|
||||||
|
|
||||||
|
public class SavedMonitorInfo
|
||||||
|
{
|
||||||
|
public float widthScale = 1f;
|
||||||
|
public float heightScale = 1f;
|
||||||
|
}
|
||||||
|
|
||||||
private List<SavedMonitorInfo> savedInfoList_ = new List<SavedMonitorInfo>();
|
private List<SavedMonitorInfo> savedInfoList_ = new List<SavedMonitorInfo>();
|
||||||
public List<SavedMonitorInfo> savedInfoList { get { return savedInfoList_; } }
|
public List<SavedMonitorInfo> savedInfoList { get { return savedInfoList_; } }
|
||||||
|
|
||||||
@@ -90,12 +91,12 @@ public class MultipleMonitorCreator : MonoBehaviour
|
|||||||
removeWaitTimer_ += Time.deltaTime;
|
removeWaitTimer_ += Time.deltaTime;
|
||||||
if (removeWaitTimer_ > removeWaitDuration) {
|
if (removeWaitTimer_ > removeWaitDuration) {
|
||||||
hasMonitorUnsupportStateChecked_ = true;
|
hasMonitorUnsupportStateChecked_ = true;
|
||||||
foreach (var info in monitors_) {
|
foreach (var info in monitors) {
|
||||||
if (info.uddTexture.monitor.state == uDesktopDuplication.MonitorState.Unsupported) {
|
if (info.uddTexture.monitor.state == MonitorState.Unsupported) {
|
||||||
Destroy(info.gameObject);
|
Destroy(info.gameObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
monitors_.RemoveAll(info => info.uddTexture.monitor.state == uDesktopDuplication.MonitorState.Unsupported);
|
monitors.RemoveAll(info => info.uddTexture.monitor.state == MonitorState.Unsupported);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,14 +112,16 @@ public class MultipleMonitorCreator : MonoBehaviour
|
|||||||
ResetRemoveTimer();
|
ResetRemoveTimer();
|
||||||
|
|
||||||
// Create monitors
|
// Create monitors
|
||||||
for (int i = 0; i < uDesktopDuplication.Manager.monitors.Count; ++i) {
|
var n = uDesktopDuplication.Manager.monitors.Count;
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
// Create monitor obeject
|
// Create monitor obeject
|
||||||
var go = Instantiate(monitorPrefab);
|
var go = Instantiate(monitorPrefab);
|
||||||
go.name = "Monitor " + i;
|
go.name = "Monitor " + i;
|
||||||
|
|
||||||
// Saved infomation
|
// Saved infomation
|
||||||
if (savedInfoList.Count == i) {
|
if (savedInfoList.Count == i) {
|
||||||
savedInfoList.Add(new SavedMonitorInfo());
|
savedInfoList.Add(new SavedMonitorInfo());
|
||||||
|
Assert.AreEqual(i, savedInfoList.Count - 1);
|
||||||
}
|
}
|
||||||
var savedInfo = savedInfoList[i];
|
var savedInfo = savedInfoList[i];
|
||||||
|
|
||||||
@@ -164,24 +167,22 @@ public class MultipleMonitorCreator : MonoBehaviour
|
|||||||
go.transform.SetParent(transform);
|
go.transform.SetParent(transform);
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
{
|
var info = new MonitorInfo();
|
||||||
var info = new MonitorInfo();
|
info.gameObject = go;
|
||||||
info.gameObject = go;
|
info.originalRotation = go.transform.rotation;
|
||||||
info.originalRotation = go.transform.rotation;
|
info.originalLocalScale = go.transform.localScale;
|
||||||
info.originalLocalScale = go.transform.localScale;
|
info.uddTexture = texture;
|
||||||
info.uddTexture = texture;
|
info.mesh = mesh;
|
||||||
info.mesh = mesh;
|
monitors.Add(info);
|
||||||
monitors.Add(info);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort monitors in coordinate order
|
// Sort monitors in coordinate order
|
||||||
monitors_.Sort((a, b) => a.uddTexture.monitor.left - b.uddTexture.monitor.left);
|
monitors.Sort((a, b) => a.uddTexture.monitor.left - b.uddTexture.monitor.left);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clear()
|
void Clear()
|
||||||
{
|
{
|
||||||
foreach (var info in monitors_) {
|
foreach (var info in monitors) {
|
||||||
Destroy(info.gameObject);
|
Destroy(info.gameObject);
|
||||||
}
|
}
|
||||||
if (removeChildrenWhenClear) {
|
if (removeChildrenWhenClear) {
|
||||||
@@ -189,7 +190,7 @@ public class MultipleMonitorCreator : MonoBehaviour
|
|||||||
Destroy(transform.GetChild(i).gameObject);
|
Destroy(transform.GetChild(i).gameObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
monitors_.Clear();
|
monitors.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
[ContextMenu("Recreate")]
|
[ContextMenu("Recreate")]
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public class MultipleMonitorRoundLayouter : MultipleMonitorLayouter
|
|||||||
|
|
||||||
// Keep the local scale z of monitors as 1 to bend them correctly.
|
// Keep the local scale z of monitors as 1 to bend them correctly.
|
||||||
// And save width / height to use same values after reinitialization.
|
// And save width / height to use same values after reinitialization.
|
||||||
for (int i = 0; i < monitors.Count; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
var info = monitors[i];
|
var info = monitors[i];
|
||||||
var savedInfo = creator_.savedInfoList[i];
|
var savedInfo = creator_.savedInfoList[i];
|
||||||
var scale = info.gameObject.transform.localScale;
|
var scale = info.gameObject.transform.localScale;
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ public class Cursor : MonoBehaviour
|
|||||||
{
|
{
|
||||||
[SerializeField] Vector2 modelScale = Vector2.one;
|
[SerializeField] Vector2 modelScale = Vector2.one;
|
||||||
|
|
||||||
Vector3 worldPosition { get; set; }
|
public Vector3 worldPosition { get; set; }
|
||||||
|
public Vector2 coord { get; set; }
|
||||||
|
|
||||||
private Texture uddTexture_;
|
private Texture uddTexture_;
|
||||||
private Monitor monitor { get { return uddTexture_.monitor; } }
|
private Monitor monitor { get { return uddTexture_.monitor; } }
|
||||||
@@ -65,6 +66,8 @@ public class Cursor : MonoBehaviour
|
|||||||
var w = (float)monitor.cursorShapeWidth / monitor.width;
|
var w = (float)monitor.cursorShapeWidth / monitor.width;
|
||||||
var h = (float)monitor.cursorShapeHeight / monitor.height;
|
var h = (float)monitor.cursorShapeHeight / monitor.height;
|
||||||
uddTexture_.material.SetVector("_CursorPositionScale", new Vector4(x, y, w, h));
|
uddTexture_.material.SetVector("_CursorPositionScale", new Vector4(x, y, w, h));
|
||||||
|
|
||||||
|
coord = new Vector2(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ public class Manager : MonoBehaviour
|
|||||||
private Coroutine renderCoroutine_ = null;
|
private Coroutine renderCoroutine_ = null;
|
||||||
private bool shouldReinitialize_ = false;
|
private bool shouldReinitialize_ = false;
|
||||||
private float reinitializationTimer_ = 0f;
|
private float reinitializationTimer_ = 0f;
|
||||||
|
private bool isFirstFrame_ = true;
|
||||||
|
|
||||||
public delegate void ReinitializeHandler();
|
public delegate void ReinitializeHandler();
|
||||||
public static event ReinitializeHandler onReinitialized;
|
public static event ReinitializeHandler onReinitialized;
|
||||||
@@ -72,16 +73,17 @@ public class Manager : MonoBehaviour
|
|||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
Lib.SetDebugMode(debugMode);
|
// for simple singleton
|
||||||
Lib.SetTimeout(desktopDuplicationApiTimeout);
|
|
||||||
Lib.InitializeUDD();
|
|
||||||
|
|
||||||
if (instance_ != null) {
|
if (instance_ != null) {
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
instance_ = this;
|
instance_ = this;
|
||||||
|
|
||||||
|
Lib.SetDebugMode(debugMode);
|
||||||
|
Lib.SetTimeout(desktopDuplicationApiTimeout);
|
||||||
|
Lib.InitializeUDD();
|
||||||
|
|
||||||
CreateMonitors();
|
CreateMonitors();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,6 +96,9 @@ public class Manager : MonoBehaviour
|
|||||||
void OnEnable()
|
void OnEnable()
|
||||||
{
|
{
|
||||||
renderCoroutine_ = StartCoroutine(OnRender());
|
renderCoroutine_ = StartCoroutine(OnRender());
|
||||||
|
if (!isFirstFrame_) {
|
||||||
|
Reinitialize();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnDisable()
|
void OnDisable()
|
||||||
@@ -109,6 +114,7 @@ public class Manager : MonoBehaviour
|
|||||||
Lib.Update();
|
Lib.Update();
|
||||||
ReinitializeIfNeeded();
|
ReinitializeIfNeeded();
|
||||||
UpdateMessage();
|
UpdateMessage();
|
||||||
|
isFirstFrame_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ContextMenu("Reinitialize")]
|
[ContextMenu("Reinitialize")]
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ public class Texture : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int lastMonitorId_ = 0;
|
||||||
public int monitorId
|
public int monitorId
|
||||||
{
|
{
|
||||||
get { return monitor.id; }
|
get { return monitor.id; }
|
||||||
@@ -125,10 +126,20 @@ public class Texture : MonoBehaviour
|
|||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
|
KeepMonitor();
|
||||||
monitor.shouldBeUpdated = true;
|
monitor.shouldBeUpdated = true;
|
||||||
UpdateMaterial();
|
UpdateMaterial();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KeepMonitor()
|
||||||
|
{
|
||||||
|
if (monitor == null) {
|
||||||
|
Reinitialize();
|
||||||
|
} else {
|
||||||
|
lastMonitorId_ = monitorId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AddCursorIfNotAttached()
|
void AddCursorIfNotAttached()
|
||||||
{
|
{
|
||||||
if (!GetComponent<Cursor>())
|
if (!GetComponent<Cursor>())
|
||||||
@@ -140,7 +151,7 @@ public class Texture : MonoBehaviour
|
|||||||
void Reinitialize()
|
void Reinitialize()
|
||||||
{
|
{
|
||||||
// Monitor instance is released here when initialized.
|
// Monitor instance is released here when initialized.
|
||||||
monitor = Manager.GetMonitor(monitor.id);
|
monitor = Manager.GetMonitor(lastMonitorId_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateMaterial()
|
void UpdateMaterial()
|
||||||
|
|||||||
Reference in New Issue
Block a user