浏览代码

fix format errors about log message from cpp

/siyaoH-1.17-PlatformMessage
guanghuispark 4 年前
当前提交
770ca668
共有 3 个文件被更改,包括 34 次插入31 次删除
  1. 22
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsExample.cs
  2. 22
      engine/src/shell/platform/unity/uiwidgets_log.h
  3. 21
      Samples/UIWidgetsSamples_2019_4/Assets/NativeConsole.cs

22
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsExample.cs


using FontStyle = Unity.UIWidgets.ui.FontStyle;
using ui_ = Unity.UIWidgets.widgets.ui_;
using AOT;
using System;
using System.Runtime.InteropServices;
public delegate void LogDelegate(IntPtr message, int iSize);
[DllImport("libUIWidgets_d.dll")]
public static extern void InitCSharpDelegate(LogDelegate log);
//C# Function for C++'s call
[MonoPInvokeCallback(typeof(LogDelegate))]
public static void LogMessageFromCpp(IntPtr message, int iSize)
{
Debug.Log(Marshal.PtrToStringAnsi(message, iSize));
}
protected void OnEnable() {
// if you want to use your own font or font icons.
// FontManager.instance.addFont(Resources.Load<Font>(path: "path to your font"), "font family name");

// FontManager.instance.addFont(Resources.Load<Font>(path: "path to material icons"), "Material Icons");
// Pass the C# Debug function reference to C++ to save, and then C++ calls C# through the function pointer
UIWidgetsExample.InitCSharpDelegate(UIWidgetsExample.LogMessageFromCpp);
base.OnEnable();
NativeConsole.InitLogMessageFromCppDelegate(NativeConsole.LogMessageFromCpp);
base.OnEnable();
}
protected override void main()

22
engine/src/shell/platform/unity/uiwidgets_log.h


#include "runtime/mono_api.h"
namespace uiwidgets {
//use UnityLog just like printf, and this will output the result to unity
// use UnityLog just like printf, and this will output the result to unity
extern "C"
{
class Debug
{
public:
static void (*Log)(char* message,int iSize);
};
extern "C"{
class Debug{
public:
static void (*Log)(char* message,int iSize);
};
void (*Debug::Log)(char* message, int iSize);
// export c++ function interface for c#
UIWIDGETS_API(void) InitCSharpDelegate(void (*Log)(char* message, int iSize)){Debug::Log = Log;}
void (*Debug::Log)(char* message, int iSize);
// export c++ function interface for c#
UIWIDGETS_API(void)
InitLogMessageFromCppDelegate(void (*Log)(char* message, int iSize)){ Debug::Log = Log; }
} // namespace uiwidgets

21
Samples/UIWidgetsSamples_2019_4/Assets/NativeConsole.cs


using UnityEngine;
using AOT;
using System;
using System.Runtime.InteropServices;
public static class NativeConsole
{
public delegate void LogDelegate(IntPtr message, int iSize);
[DllImport("libUIWidgets_d.dll")]
public static extern void InitLogMessageFromCppDelegate(LogDelegate log);
//C# Function for C++'s call
[MonoPInvokeCallback(typeof(LogDelegate))]
public static void LogMessageFromCpp(IntPtr message, int iSize)
{
Debug.Log(Marshal.PtrToStringAnsi(message, iSize));
}
}
正在加载...
取消
保存