浏览代码

refine code for mac

/siyaoH-1.17-PlatformMessage
xingwei.zhu 4 年前
当前提交
09653fa7
共有 3 个文件被更改,包括 51 次插入7 次删除
  1. 15
      engine/src/shell/platform/unity/darwin/macos/uiwidgets_panel.h
  2. 37
      engine/src/shell/platform/unity/darwin/macos/uiwidgets_panel.mm
  3. 6
      engine/src/shell/platform/unity/darwin/macos/uiwidgets_system.mm

15
engine/src/shell/platform/unity/darwin/macos/uiwidgets_panel.h


namespace uiwidgets {
enum UIWidgetsWindowType {
InvalidPanel = 0,
GameObjectPanel = 1,
EditorWindowPanel = 2
};
struct MouseState {
bool state_is_down = false;
bool state_is_added = false;

typedef void (*EntrypointCallback)(Mono_Handle handle);
static fml::RefPtr<UIWidgetsPanel> Create(
Mono_Handle handle, EntrypointCallback entrypoint_callback);
Mono_Handle handle, UIWidgetsWindowType window_type, EntrypointCallback entrypoint_callback);
~UIWidgetsPanel();

void OnMouseLeave();
bool NeedUpdateByPlayerLoop();
bool NeedUpdateByEditorLoop();
UIWidgetsPanel(Mono_Handle handle, EntrypointCallback entrypoint_callback);
UIWidgetsPanel(Mono_Handle handle, UIWidgetsWindowType window_type, EntrypointCallback entrypoint_callback);
void CreateInternalUIWidgetsEngine(size_t width, size_t height, float device_pixel_ratio, const char* streaming_assets_path, const char* settings);

Mono_Handle handle_;
EntrypointCallback entrypoint_callback_;
UIWidgetsWindowType window_type_;
std::unique_ptr<UnitySurfaceManager> surface_manager_;

37
engine/src/shell/platform/unity/darwin/macos/uiwidgets_panel.mm


namespace uiwidgets {
fml::RefPtr<UIWidgetsPanel> UIWidgetsPanel::Create(
Mono_Handle handle, EntrypointCallback entrypoint_callback) {
return fml::MakeRefCounted<UIWidgetsPanel>(handle, entrypoint_callback);
Mono_Handle handle, UIWidgetsWindowType window_type, EntrypointCallback entrypoint_callback) {
return fml::MakeRefCounted<UIWidgetsPanel>(handle, window_type, entrypoint_callback);
UIWidgetsWindowType window_type,
: handle_(handle), entrypoint_callback_(entrypoint_callback) {}
: handle_(handle), window_type_(window_type), entrypoint_callback_(entrypoint_callback) {}
bool UIWidgetsPanel::NeedUpdateByPlayerLoop() {
return window_type_ == GameObjectPanel;
}
bool UIWidgetsPanel::NeedUpdateByEditorLoop() {
return window_type_ == EditorWindowPanel;
}
void* UIWidgetsPanel::OnEnable(size_t width, size_t height, float device_pixel_ratio,
const char* streaming_assets_path, const char* settings)

UIWIDGETS_API(UIWidgetsPanel*)
UIWidgetsPanel_constructor(
Mono_Handle handle,
Mono_Handle handle, int windowType,
const auto panel = UIWidgetsPanel::Create(handle, entrypoint_callback);
UIWidgetsWindowType window_type = static_cast<UIWidgetsWindowType>(windowType);
const auto panel = UIWidgetsPanel::Create(handle, window_type, entrypoint_callback);
panel->AddRef();
return panel.get();
}

UIWIDGETS_API(void)
UIWidgetsPanel_onMouseLeave(UIWidgetsPanel* panel) { panel->OnMouseLeave(); }
UIWIDGETS_API(void)
UIWidgetsPanel_onEditorUpdate(UIWidgetsPanel* panel) {
if (!panel->NeedUpdateByEditorLoop()) {
std::cerr << "only EditorWindowPanel can be updated using onEditorUpdate" << std::endl;
return;
}
//_Update
panel->ProcessMessages();
//_ProcessVSync
panel->ProcessVSync();
//_Wait
panel->ProcessMessages();
}
} // namespace uiwidgets

6
engine/src/shell/platform/unity/darwin/macos/uiwidgets_system.mm


void UIWidgetsSystem::Update() {
TimePoint next_event_time = TimePoint::max();
for (auto* uiwidgets_panel : uiwidgets_panels_) {
if (!uiwidgets_panel->NeedUpdateByPlayerLoop()) {
continue;
}
std::chrono::nanoseconds wait_duration = uiwidgets_panel->ProcessMessages();
if (wait_duration != std::chrono::nanoseconds::max()) {
next_event_time =

void UIWidgetsSystem::VSync() {
for (auto* uiwidgets_panel : uiwidgets_panels_) {
if (!uiwidgets_panel->NeedUpdateByPlayerLoop()) {
continue;
}
uiwidgets_panel->ProcessVSync();
}
}

正在加载...
取消
保存