fix unity log call from native.
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -2,6 +2,8 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
#pragma warning disable 114, 465
|
||||||
|
|
||||||
namespace uDesktopDuplication
|
namespace uDesktopDuplication
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -77,9 +79,9 @@ public static class Lib
|
|||||||
public delegate void DebugLogDelegate(string str);
|
public delegate void DebugLogDelegate(string str);
|
||||||
|
|
||||||
[DllImport("uDesktopDuplication")]
|
[DllImport("uDesktopDuplication")]
|
||||||
public static extern void InitializeUDD();
|
public static extern void Initialize();
|
||||||
[DllImport("uDesktopDuplication")]
|
[DllImport("uDesktopDuplication")]
|
||||||
public static extern void FinalizeUDD();
|
public static extern void Finalize();
|
||||||
[DllImport("uDesktopDuplication")]
|
[DllImport("uDesktopDuplication")]
|
||||||
public static extern void Reinitialize();
|
public static extern void Reinitialize();
|
||||||
[DllImport("uDesktopDuplication")]
|
[DllImport("uDesktopDuplication")]
|
||||||
@@ -93,9 +95,9 @@ public static class Lib
|
|||||||
[DllImport("uDesktopDuplication")]
|
[DllImport("uDesktopDuplication")]
|
||||||
public static extern void SetDebugMode(DebugMode mode);
|
public static extern void SetDebugMode(DebugMode mode);
|
||||||
[DllImport("uDesktopDuplication")]
|
[DllImport("uDesktopDuplication")]
|
||||||
public static extern void SetLogFunc(IntPtr func);
|
public static extern void SetLogFunc(DebugLogDelegate func);
|
||||||
[DllImport("uDesktopDuplication")]
|
[DllImport("uDesktopDuplication")]
|
||||||
public static extern void SetErrorFunc(IntPtr func);
|
public static extern void SetErrorFunc(DebugLogDelegate func);
|
||||||
[DllImport("uDesktopDuplication")]
|
[DllImport("uDesktopDuplication")]
|
||||||
public static extern int GetMonitorCount();
|
public static extern int GetMonitorCount();
|
||||||
[DllImport("uDesktopDuplication")]
|
[DllImport("uDesktopDuplication")]
|
||||||
|
|||||||
@@ -52,7 +52,9 @@ public class Manager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Tooltip("Debug mode is not applied while running.")]
|
||||||
[SerializeField] DebugMode debugMode = DebugMode.File;
|
[SerializeField] DebugMode debugMode = DebugMode.File;
|
||||||
|
|
||||||
[SerializeField] int desktopDuplicationApiTimeout = 0;
|
[SerializeField] int desktopDuplicationApiTimeout = 0;
|
||||||
[SerializeField] float retryReinitializationDuration = 1f;
|
[SerializeField] float retryReinitializationDuration = 1f;
|
||||||
|
|
||||||
@@ -61,6 +63,9 @@ public class Manager : MonoBehaviour
|
|||||||
private float reinitializationTimer_ = 0f;
|
private float reinitializationTimer_ = 0f;
|
||||||
private bool isFirstFrame_ = true;
|
private bool isFirstFrame_ = true;
|
||||||
|
|
||||||
|
public static event Lib.DebugLogDelegate onDebugLog = msg => Debug.Log(msg);
|
||||||
|
public static event Lib.DebugLogDelegate onDebugErr = msg => Debug.LogError(msg);
|
||||||
|
|
||||||
public delegate void ReinitializeHandler();
|
public delegate void ReinitializeHandler();
|
||||||
public static event ReinitializeHandler onReinitialized;
|
public static event ReinitializeHandler onReinitialized;
|
||||||
|
|
||||||
@@ -89,15 +94,18 @@ public class Manager : MonoBehaviour
|
|||||||
instance_ = this;
|
instance_ = this;
|
||||||
|
|
||||||
Lib.SetDebugMode(debugMode);
|
Lib.SetDebugMode(debugMode);
|
||||||
|
Lib.SetLogFunc(onDebugLog);
|
||||||
|
Lib.SetErrorFunc(onDebugErr);
|
||||||
|
|
||||||
Lib.SetTimeout(desktopDuplicationApiTimeout);
|
Lib.SetTimeout(desktopDuplicationApiTimeout);
|
||||||
Lib.InitializeUDD();
|
Lib.Initialize();
|
||||||
|
|
||||||
CreateMonitors();
|
CreateMonitors();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnApplicationQuit()
|
void OnApplicationQuit()
|
||||||
{
|
{
|
||||||
Lib.FinalizeUDD();
|
Lib.Finalize();
|
||||||
DestroyMonitors();
|
DestroyMonitors();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,6 +115,9 @@ public class Manager : MonoBehaviour
|
|||||||
if (!isFirstFrame_) {
|
if (!isFirstFrame_) {
|
||||||
Reinitialize();
|
Reinitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Lib.SetDebugMode(debugMode);
|
||||||
|
Lib.SetLogFunc(onDebugLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnDisable()
|
void OnDisable()
|
||||||
@@ -115,6 +126,9 @@ public class Manager : MonoBehaviour
|
|||||||
StopCoroutine(renderCoroutine_);
|
StopCoroutine(renderCoroutine_);
|
||||||
renderCoroutine_ = null;
|
renderCoroutine_ = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Lib.SetLogFunc(null);
|
||||||
|
Lib.SetErrorFunc(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
|
|||||||
@@ -4,15 +4,19 @@
|
|||||||
#include "Debug.h"
|
#include "Debug.h"
|
||||||
|
|
||||||
|
|
||||||
decltype(Debug::mode_) Debug::mode_ = Debug::Mode::File;
|
decltype(Debug::isInitialized_) Debug::isInitialized_ = false;
|
||||||
decltype(Debug::logFunc_) Debug::logFunc_ = nullptr;
|
decltype(Debug::mode_) Debug::mode_ = Debug::Mode::File;
|
||||||
decltype(Debug::errFunc_) Debug::errFunc_ = nullptr;
|
decltype(Debug::logFunc_) Debug::logFunc_ = nullptr;
|
||||||
decltype(Debug::fs_) Debug::fs_;
|
decltype(Debug::errFunc_) Debug::errFunc_ = nullptr;
|
||||||
decltype(Debug::ss_) Debug::ss_;
|
decltype(Debug::fs_) Debug::fs_;
|
||||||
|
decltype(Debug::ss_) Debug::ss_;
|
||||||
|
|
||||||
|
|
||||||
void Debug::Initialize()
|
void Debug::Initialize()
|
||||||
{
|
{
|
||||||
|
if (isInitialized_) return;
|
||||||
|
isInitialized_ = true;
|
||||||
|
|
||||||
if (mode_ == Mode::File)
|
if (mode_ == Mode::File)
|
||||||
{
|
{
|
||||||
fs_.open("uDesktopDuplication.log");
|
fs_.open("uDesktopDuplication.log");
|
||||||
@@ -23,6 +27,9 @@ void Debug::Initialize()
|
|||||||
|
|
||||||
void Debug::Finalize()
|
void Debug::Finalize()
|
||||||
{
|
{
|
||||||
|
if (!isInitialized_) return;
|
||||||
|
isInitialized_ = false;
|
||||||
|
|
||||||
if (mode_ == Mode::File)
|
if (mode_ == Mode::File)
|
||||||
{
|
{
|
||||||
Debug::Log("Stop");
|
Debug::Log("Stop");
|
||||||
|
|||||||
@@ -64,8 +64,12 @@ private:
|
|||||||
{
|
{
|
||||||
switch (level)
|
switch (level)
|
||||||
{
|
{
|
||||||
case Level::Log : logFunc_(ss_.str().c_str()); break;
|
case Level::Log :
|
||||||
case Level::Error : errFunc_(ss_.str().c_str()); break;
|
if (logFunc_) logFunc_(ss_.str().c_str());
|
||||||
|
break;
|
||||||
|
case Level::Error :
|
||||||
|
if (errFunc_) errFunc_(ss_.str().c_str());
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -119,6 +123,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static bool isInitialized_;
|
||||||
static Mode mode_;
|
static Mode mode_;
|
||||||
static std::ofstream fs_;
|
static std::ofstream fs_;
|
||||||
static std::ostringstream ss_;
|
static std::ostringstream ss_;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ std::queue<Message> g_messages;
|
|||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API InitializeUDD()
|
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API Initialize()
|
||||||
{
|
{
|
||||||
if (g_unity && !g_manager)
|
if (g_unity && !g_manager)
|
||||||
{
|
{
|
||||||
@@ -34,7 +34,7 @@ extern "C"
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API FinalizeUDD()
|
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API Finalize()
|
||||||
{
|
{
|
||||||
if (!g_manager) return;
|
if (!g_manager) return;
|
||||||
|
|
||||||
@@ -52,12 +52,12 @@ extern "C"
|
|||||||
{
|
{
|
||||||
case kUnityGfxDeviceEventInitialize:
|
case kUnityGfxDeviceEventInitialize:
|
||||||
{
|
{
|
||||||
InitializeUDD();
|
Initialize();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case kUnityGfxDeviceEventShutdown:
|
case kUnityGfxDeviceEventShutdown:
|
||||||
{
|
{
|
||||||
FinalizeUDD();
|
Finalize();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,8 +66,6 @@ extern "C"
|
|||||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces)
|
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces)
|
||||||
{
|
{
|
||||||
g_unity = unityInterfaces;
|
g_unity = unityInterfaces;
|
||||||
InitializeUDD();
|
|
||||||
|
|
||||||
auto unityGraphics = g_unity->Get<IUnityGraphics>();
|
auto unityGraphics = g_unity->Get<IUnityGraphics>();
|
||||||
unityGraphics->RegisterDeviceEventCallback(OnGraphicsDeviceEvent);
|
unityGraphics->RegisterDeviceEventCallback(OnGraphicsDeviceEvent);
|
||||||
}
|
}
|
||||||
@@ -76,8 +74,6 @@ extern "C"
|
|||||||
{
|
{
|
||||||
auto unityGraphics = g_unity->Get<IUnityGraphics>();
|
auto unityGraphics = g_unity->Get<IUnityGraphics>();
|
||||||
unityGraphics->UnregisterDeviceEventCallback(OnGraphicsDeviceEvent);
|
unityGraphics->UnregisterDeviceEventCallback(OnGraphicsDeviceEvent);
|
||||||
|
|
||||||
FinalizeUDD();
|
|
||||||
g_unity = nullptr;
|
g_unity = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user