This repository has been archived by the owner on Apr 29, 2021. It is now read-only.
[WIP] Add basic support for PlayerDisplayMetrics.devicePixelRatio on macOS #213
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a working proof of concept of devicePixelRatio support on macOS standalone player. As that being said, the current progress may not suitable for direct production usage, but to provide an idea on how to do this on macOS.
Added Features
OSXDeviceScaleFactor
methodViewportMatricsChanged
eventChanges
How this works
This is achieved by providing
OSXDeviceScaleFactor
the NSScreenUtils.m file:This is a bit tricky because:
unity-classes.jar
and call 'com.unity3d.player.UnityPlayer.UnitySendMessage') or iOS (importUnityInterface.h
). So I have to build a custom UnitySendMessage clone and name it UnityOSXSendMessage. If there is an official way to call UnitySendMessage in macOS plugins then please ignore this issue.As the UnityOSXSendMessage link is established, we now send a "ViewportMatricsChanged" message whenever the screen change notification is triggered. The "UIWidgetViewController.keyboardChanged" argument is copied from the Java implementation and may need to change to a more suitable name.
In the Update function of DisplayMetrics.cs I added a line to invalidate the current scale factor, then in the next cycle UIWidgets would call OSXDeviceScaleFactor to get a new scale value.
Concern & To-do
displayMetrics.Update
is called in UIWidgetsPanel.Update(), which is expensive on CPU usage. I wonder if there is a solution to calldisplayMetrics.Update
only if needed.Reference
Demo Video
demo.mp4.zip