浏览代码

android/ios/webgl device pixel ratio to unity

/main
fzhangtj 6 年前
当前提交
d9da1de6
共有 9 个文件被更改,包括 318 次插入9 次删除
  1. 22
      Runtime/engine/WidgetCanvas.cs
  2. 8
      Runtime/Plugins.meta
  3. 58
      Runtime/engine/DisplayMetrics.cs
  4. 11
      Runtime/engine/DisplayMetrics.cs.meta
  5. 8
      Runtime/Plugins/DeviceScreen.mm
  6. 104
      Runtime/Plugins/DeviceScreen.mm.meta
  7. 7
      Runtime/Plugins/webgl.jslib
  8. 109
      Runtime/Plugins/webgl.jslib.meta

22
Runtime/engine/WidgetCanvas.cs


}
protected override Vector2 queryWindowSize() {
return this._widgetCanvas.rectTransform.rect.size;
var size = this._widgetCanvas.rectTransform.rect.size;
size = size * this._widgetCanvas.canvas.scaleFactor / (float)this._widgetCanvas.pixelRatio;
return new Vector2 (Mathf.Round (size.x), Mathf.Round (size.y));
}
}

}
public double pixelRatio {
get { return this.canvas.scaleFactor; }
get { return DisplayMetrics.devicePixelRatio; }
}
protected virtual Dictionary<string, WidgetBuilder> routes {

if (this._mouseEntered) {
if (Input.mouseScrollDelta.y != 0 || Input.mouseScrollDelta.x != 0) {
var scaleFactor = this.canvas.scaleFactor;
this._scrollInput.onScroll((float) (Input.mouseScrollDelta.x * this.pixelRatio),
(float) (Input.mouseScrollDelta.y * this.pixelRatio),
this._scrollInput.onScroll((float) (Input.mouseScrollDelta.x * scaleFactor),
(float) (Input.mouseScrollDelta.y * scaleFactor),
pos.x,
pos.y,
this.getScrollButton());

Vector2 localPoint;
RectTransformUtility.ScreenPointToLocalPointInRectangle(this.rectTransform, eventData.position,
eventData.enterEventCamera, out localPoint);
var pixelRatio = this.pixelRatio;
localPoint.x = (float) ((localPoint.x - this.rectTransform.rect.min.x) * pixelRatio);
localPoint.y = (float) ((this.rectTransform.rect.max.y - localPoint.y) * pixelRatio);
var scaleFactor = this.canvas.scaleFactor;
localPoint.x = (localPoint.x - this.rectTransform.rect.min.x) * scaleFactor;
localPoint.y = (this.rectTransform.rect.max.y - localPoint.y) * scaleFactor;
return localPoint;
}

RectTransformUtility.ScreenPointToLocalPointInRectangle(this.rectTransform, position,
eventCamera, out localPoint);
localPoint.x = (float) ((localPoint.x - this.rectTransform.rect.min.x) * this.pixelRatio);
localPoint.y = (float) ((this.rectTransform.rect.max.y - localPoint.y) * this.pixelRatio);
var scaleFactor = this.canvas.scaleFactor;
localPoint.x = (localPoint.x - this.rectTransform.rect.min.x) * scaleFactor;
localPoint.y = (this.rectTransform.rect.max.y - localPoint.y) * scaleFactor;
return localPoint;
}

8
Runtime/Plugins.meta


fileFormatVersion: 2
guid: 748885407ae664e1093421099f1ad4b6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

58
Runtime/engine/DisplayMetrics.cs


using System.Runtime.InteropServices;
using UnityEngine;
namespace Unity.UIWidgets.engine {
public class DisplayMetrics {
static float _devicePixelRatio = 0;
public static float devicePixelRatio {
get {
if (_devicePixelRatio > 0) {
return _devicePixelRatio;
}
if (Application.platform == RuntimePlatform.Android) {
_devicePixelRatio = DevicePixelRatioAndroid();
} else if (Application.platform == RuntimePlatform.WebGLPlayer) {
_devicePixelRatio = UIWidgetsWebGLDevicePixelRatio();
} else if (Application.platform == RuntimePlatform.IPhonePlayer ||
Application.platform == RuntimePlatform.tvOS) {
_devicePixelRatio = IOSDeviceSaleFactor();
}
if (_devicePixelRatio <= 0) {
_devicePixelRatio = 1;
}
return _devicePixelRatio;
}
}
static float DevicePixelRatioAndroid() {
using (
AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")
) {
using (
AndroidJavaObject metricsInstance = new AndroidJavaObject("android.util.DisplayMetrics"),
activityInstance = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity"),
windowManagerInstance = activityInstance.Call<AndroidJavaObject>("getWindowManager"),
displayInstance = windowManagerInstance.Call<AndroidJavaObject>("getDefaultDisplay")
) {
displayInstance.Call("getMetrics", metricsInstance);
return metricsInstance.Get<float>("density");
}
}
}
[DllImport("__Internal")]
static extern float UIWidgetsWebGLDevicePixelRatio();
[DllImport("__Internal")]
static extern int IOSDeviceSaleFactor();
}
}

11
Runtime/engine/DisplayMetrics.cs.meta


fileFormatVersion: 2
guid: 6427f06ce097c4650a5aaa5b9ecb41bf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

8
Runtime/Plugins/DeviceScreen.mm


#import <UIKit/UIKit.h>
extern "C"
{
int IOSDeviceSaleFactor()
{
return [[UIScreen mainScreen] scale];
}
}

104
Runtime/Plugins/DeviceScreen.mm.meta


fileFormatVersion: 2
guid: 349072cdca47948b89f3e8cfab33f642
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 1
isExplicitlyReferenced: 0
platformData:
- first:
'': Any
second:
enabled: 0
settings:
Exclude Android: 1
Exclude Editor: 1
Exclude Linux: 1
Exclude Linux64: 1
Exclude LinuxUniversal: 1
Exclude OSXUniversal: 1
Exclude WebGL: 1
Exclude Win: 1
Exclude Win64: 1
Exclude iOS: 0
- first:
Android: Android
second:
enabled: 0
settings:
CPU: ARMv7
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
CPU: AnyCPU
DefaultValueInitialized: true
OS: AnyOS
- first:
Facebook: Win
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Facebook: Win64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Linux
second:
enabled: 0
settings:
CPU: x86
- first:
Standalone: Linux64
second:
enabled: 0
settings:
CPU: x86_64
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Win
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Win64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
CompileFlags:
FrameworkDependencies:
- first:
tvOS: tvOS
second:
enabled: 1
settings: {}
userData:
assetBundleName:
assetBundleVariant:

7
Runtime/Plugins/webgl.jslib


mergeInto(LibraryManager.library, {
UIWidgetsWebGLDevicePixelRatio: function () {
return window.devicePixelRatio || 1;
},
});

109
Runtime/Plugins/webgl.jslib.meta


fileFormatVersion: 2
guid: 7d896da6a0e454594a11916493dae285
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 1
isExplicitlyReferenced: 0
platformData:
- first:
'': Any
second:
enabled: 0
settings:
Exclude Android: 1
Exclude Editor: 1
Exclude Linux: 1
Exclude Linux64: 1
Exclude LinuxUniversal: 1
Exclude OSXUniversal: 1
Exclude WebGL: 0
Exclude Win: 1
Exclude Win64: 1
Exclude iOS: 1
- first:
Android: Android
second:
enabled: 0
settings:
CPU: ARMv7
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
CPU: AnyCPU
DefaultValueInitialized: true
OS: AnyOS
- first:
Facebook: WebGL
second:
enabled: 1
settings: {}
- first:
Facebook: Win
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Facebook: Win64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Linux
second:
enabled: 0
settings:
CPU: x86
- first:
Standalone: Linux64
second:
enabled: 0
settings:
CPU: x86_64
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Win
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Win64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
WebGL: WebGL
second:
enabled: 1
settings: {}
- first:
iPhone: iOS
second:
enabled: 0
settings:
AddToEmbeddedBinaries: false
CompileFlags:
FrameworkDependencies:
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存