gree / unity-webview

zlib License
2.26k stars 688 forks source link

MacOS WKWebview has delayed inputs when using non-English characters #805

Open sangpan opened 2 years ago

sangpan commented 2 years ago

this problem reported to Unity. https://issuetracker.unity3d.com/issues/macos-wkwebview-has-delayed-inputs-when-using-non-english-characters

reproduce Video : https://youtu.be/bSBh88YvSPY

But

They said..

Hi,

Short story: Plugin developer needs to update their code.

Long story: The PR that caused the issue was correcting the Mac player's implementation of the playerloop to fire constantly, instead of using a timer approximate to the frame rate. This meant that the player loop is being fired more quickly (every 0.001 seconds) instead of 0.167s (60fps) which means there is not enough time between loops.

The reason it's different in the editor and player is that they don't share code, and the player code is the more correct of the two.

Therefore, it's down to the plugin maintainer to fix the user's issue.

This particular case has been investigated thoroughly and we have decided, in the interest of protecting the stability and features of Unity for users that rely upon the affected versions, to not address this fix for the time being. We understand that this will cause problems for some users, so we may address this in a future version.

We appreciate your contribution to the Unity product.

tried to belows. But can't resolve.

Anyone with other opinions?

KojiNakamaru commented 2 years ago

I tried to refine the osx implementation in #806 and updated binaries. It should run more smoothly compared with the last version. Please note, however, the osx implementation is still tricky/experimental and has various limitations about event handling and/or movies. You can find other better solutions on Asset Store (cf. https://github.com/gree/unity-webview/issues/612#issuecomment-724541385 ).

sangpan commented 2 years ago

Ah osx experimental.. thank you for response.

anyway.. I tried to apply this plugin to UNITY 2019.4.32 ( Run on macOS 12.3.1)

More detailed about what is problem.

I understood this original source logic like below:

  1. make webview object.
  2. draw by update call webview object.
  3. if event from os (keyboard) pass to first unity Update().
  4. pass to webview object.
  5. event process

has some problem. draw screen speed is normal, but international language input is broken. (IME composition is ignored, ex: Korean, Chinese, or Japanese)

then I tried to fork repository and modify some logic showing webview .

  1. make webview object.
  2. add to mainwindow webview object by addsubview API
  3. if event from os (keyboard) pass to webview directly.
  4. Not need update draw from object or getmessage or other relate with lifecycle.

just showing native webview itself.

But getting slow when try to input internation characters . and be normal after change to english input mode.

I am looking for resolve or avoid this slow running....

KojiNakamaru commented 2 years ago

I've tried your approach, i.e., [NSApp.mainWindow.contentView addSubview:webView]. As you reported, Event handling didn't work well. For osx, "unity as a library" is not available so it should require a long time to seek a good solution. If you get any clue, please let me know.