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