Merge pull request #26 from guanghuispark/zgh/skia/log
output cpp log to c#
This commit is contained in:
Коммит
3d6973c481
|
@ -111,6 +111,7 @@ namespace Unity.UIWidgets.engine2 {
|
|||
JSONMessageCodec.instance.toJson(settings));
|
||||
|
||||
Input_OnEnable();
|
||||
NativeConsole.OnEnable();
|
||||
}
|
||||
|
||||
protected virtual void main() {
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
using UnityEngine;
|
||||
using AOT;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using NativeBindings = Unity.UIWidgets.ui.NativeBindings;
|
||||
|
||||
public static class NativeConsole {
|
||||
internal delegate void LogDelegate(IntPtr message, int iSize);
|
||||
|
||||
[DllImport(NativeBindings.dllName)]
|
||||
internal static extern void InitNativeConsoleDelegate(LogDelegate log);
|
||||
|
||||
[MonoPInvokeCallback(typeof(LogDelegate))]
|
||||
internal static void LogMessageFromCpp(IntPtr message, int iSize) {
|
||||
Debug.Log(Marshal.PtrToStringAnsi(message, iSize));
|
||||
}
|
||||
|
||||
public static void OnEnable()
|
||||
{
|
||||
InitNativeConsoleDelegate(LogMessageFromCpp);
|
||||
}
|
||||
}
|
|
@ -310,6 +310,8 @@ class Build
|
|||
"src/shell/platform/unity/unity_surface_manager.h",
|
||||
"src/shell/platform/unity/win32_task_runner.cc",
|
||||
"src/shell/platform/unity/win32_task_runner.h",
|
||||
"src/shell/platform/unity/unity_console.cc",
|
||||
"src/shell/platform/unity/unity_console.h",
|
||||
|
||||
"src/shell/version/version.cc",
|
||||
"src/shell/version/version.h",
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
#include "unity_console.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
namespace uiwidgets {
|
||||
|
||||
void UnityConsole::WriteLine(const char* fmt, ...) {
|
||||
char log_str[512] = { 0 };
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vsprintf(log_str, fmt, ap);
|
||||
_log(log_str, strlen(log_str));
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
LogDelegate UnityConsole::_log;
|
||||
|
||||
UIWIDGETS_API(void)
|
||||
InitNativeConsoleDelegate(LogDelegate Log) {
|
||||
UnityConsole::_log = Log;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
#pragma once
|
||||
#include "runtime/mono_api.h"
|
||||
|
||||
namespace uiwidgets {
|
||||
|
||||
typedef void (*LogDelegate)(char* message, int iSize);
|
||||
|
||||
|
||||
class UnityConsole{
|
||||
public:
|
||||
static LogDelegate _log;
|
||||
|
||||
/**
|
||||
output the log to unity editor console window
|
||||
@param fmt log format
|
||||
@param ... log args
|
||||
@return null
|
||||
|
||||
example:
|
||||
UnityConsole::WriteLine("output log without fmt param");
|
||||
UnityConsole::WriteLine("%s: %d + %d = %d","output log with param", 1, 2, 3);
|
||||
*/
|
||||
static void WriteLine(const char* fmt, ...);
|
||||
};
|
||||
|
||||
} // namespace uiwidgets
|
Загрузка…
Ссылка в новой задаче