浏览代码

split unity_console.h to unity_console.cc and unity_console.h and make the details of native console logging invisible to users

/siyaoH-1.17-PlatformMessage
guanghuispark 4 年前
当前提交
c9a49958
共有 6 个文件被更改,包括 46 次插入22 次删除
  1. 2
      com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs
  2. 10
      com.unity.uiwidgets/Runtime/engine2/native_console.cs
  3. 2
      engine/Build.bee.cs
  4. 3
      engine/src/shell/platform/unity/uiwidgets_panel.cc
  5. 29
      engine/src/shell/platform/unity/unity_console.h
  6. 22
      engine/src/shell/platform/unity/unity_console.cc

2
com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs


_width, _height, _devicePixelRatio, Application.streamingAssetsPath);
Input_OnEnable();
NativeConsole.InitNativeConsoleDelegate(NativeConsole.LogMessageFromCpp);
NativeConsole.OnEnable();
}
protected virtual void main() {

10
com.unity.uiwidgets/Runtime/engine2/native_console.cs


using NativeBindings = Unity.UIWidgets.ui.NativeBindings;
public static class NativeConsole {
public delegate void LogDelegate(IntPtr message, int iSize);
internal delegate void LogDelegate(IntPtr message, int iSize);
public static extern void InitNativeConsoleDelegate(LogDelegate log);
internal static extern void InitNativeConsoleDelegate(LogDelegate log);
public static void LogMessageFromCpp(IntPtr message, int iSize) {
internal static void LogMessageFromCpp(IntPtr message, int iSize) {
public static void OnEnable()
{
InitNativeConsoleDelegate(LogMessageFromCpp);
}
}

2
engine/Build.bee.cs


"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",

3
engine/src/shell/platform/unity/uiwidgets_panel.cc


#include "shell/common/switches.h"
#include "uiwidgets_system.h"
#include "unity_external_texture_gl.h"
#include "unity_console.h"
namespace uiwidgets {

UIWidgetsPanel_onMouseDown(UIWidgetsPanel* panel, float x, float y,
int button) {
panel->OnMouseDown(x, y, button);
UnityConsole::WriteLine("OnMouseDown");
UnityConsole::WriteLine("OnMouseUp");
}
UIWIDGETS_API(void)

29
engine/src/shell/platform/unity/unity_console.h


#pragma once
#include "runtime/mono_api.h"
namespace uiwidgets {

extern "C"{
static void (*Log)(char* message,int iSize);
/*
static LogDelegate _log;
/**
@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, ...){
char log_str[512] = { 0 };
va_list ap;
va_start(ap, fmt);
sprintf_s(log_str, fmt, ap);
Log(log_str, strlen(log_str));
va_end(ap);
}
static void WriteLine(const char* fmt, ...);
void (*UnityConsole::Log)(char* message, int iSize);
UIWIDGETS_API(void)
InitNativeConsoleDelegate(LogDelegate Log){ UnityConsole::Log = Log; }
}
} // namespace uiwidgets

22
engine/src/shell/platform/unity/unity_console.cc


#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;
}
}
正在加载...
取消
保存