浏览代码

fix format problems

/siyaoH-1.17-PlatformMessage
guanghuispark 4 年前
当前提交
7b701649
共有 7 个文件被更改,包括 49 次插入44 次删除
  1. 3
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsExample.cs
  2. 1
      com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs
  3. 6
      engine/src/shell/platform/unity/uiwidgets_panel.cc
  4. 18
      com.unity.uiwidgets/Runtime/engine2/native_console.cs
  5. 27
      engine/src/shell/platform/unity/unity_console.h
  6. 21
      Samples/UIWidgetsSamples_2019_4/Assets/NativeConsole.cs
  7. 17
      engine/src/shell/platform/unity/uiwidgets_log.h

3
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsExample.cs


// add material icons, familyName must be "Material Icons"
// 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
NativeConsole.InitLogMessageFromCppDelegate(NativeConsole.LogMessageFromCpp);
base.OnEnable();
}

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


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

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


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

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

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


using UnityEngine;
using AOT;
using System;
using System.Runtime.InteropServices;
using NativeBindings = Unity.UIWidgets.ui.NativeBindings;
public static class NativeConsole {
public delegate void LogDelegate(IntPtr message, int iSize);
[DllImport(NativeBindings.dllName)]
public static extern void InitNativeConsoleDelegate(LogDelegate log);
[MonoPInvokeCallback(typeof(LogDelegate))]
public static void LogMessageFromCpp(IntPtr message, int iSize) {
Debug.Log(Marshal.PtrToStringAnsi(message, iSize));
}
}

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


#include "runtime/mono_api.h"
namespace uiwidgets {
typedef void (*LogDelegate)(char* message, int iSize);
extern "C"{
class UnityConsole{
public:
static void (*Log)(char* message,int iSize);
/*
output the log to unity editor console window
*/
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);
}
};
void (*UnityConsole::Log)(char* message, int iSize);
UIWIDGETS_API(void)
InitNativeConsoleDelegate(LogDelegate Log){ UnityConsole::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));
}
}

17
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
#define UnityLog(...) {char log_str[512] = { 0 }; sprintf_s(log_str, __VA_ARGS__); Debug::Log(log_str, strlen(log_str));}
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)
InitLogMessageFromCppDelegate(void (*Log)(char* message, int iSize)){ Debug::Log = Log; }
}
} // namespace uiwidgets
正在加载...
取消
保存