浏览代码

Merge branch 'master' into 'master'

android/ios/webgl device pixel ratio to unity

See merge request upm-packages/ui-widgets/com.unity.uiwidgets!61
/main
Shenhua Gu 6 年前
当前提交
7229064f
共有 13 个文件被更改,包括 425 次插入13 次删除
  1. 29
      Runtime/engine/WidgetCanvas.cs
  2. 80
      Samples/UIWidgetSample/TextInput.unity
  3. 8
      Editor/editor.meta
  4. 8
      Runtime/Plugins.meta
  5. 58
      Runtime/engine/DisplayMetrics.cs
  6. 11
      Runtime/engine/DisplayMetrics.cs.meta
  7. 16
      Editor/editor/WidgetCanvasEditor.cs
  8. 8
      Runtime/Plugins/DeviceScreen.mm
  9. 104
      Runtime/Plugins/DeviceScreen.mm.meta
  10. 7
      Runtime/Plugins/webgl.jslib
  11. 109
      Runtime/Plugins/webgl.jslib.meta

29
Runtime/engine/WidgetCanvas.cs


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

static Event _repaintEvent;
[SerializeField]
protected double devicePixelRatioOverride;
WindowAdapter _windowAdapter;
Texture _texture;
Vector2 _lastMouseMove;

this._lastMouseMove = Input.mousePosition;
}
public double pixelRatio {
get { return this.canvas.scaleFactor; }
public double devicePixelRatio {
get { return this.devicePixelRatioOverride > 0 ? this.devicePixelRatioOverride : 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;
}

80
Samples/UIWidgetSample/TextInput.unity


m_LocalScale: {x: 0, y: 0, z: 0}
m_Children:
- {fileID: 1387978527}
- {fileID: 1354314692}
- {fileID: 1142533064}
- {fileID: 1399904531}
m_Father: {fileID: 0}

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 304189374}
m_RootOrder: 1
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}

y: 0
width: 1
height: 1
devicePixelRatioOverride: 0
--- !u!222 &1142533066
CanvasRenderer:
m_ObjectHideFlags: 0

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1148735784}
m_CullTransparentMesh: 0
--- !u!1 &1354314691
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1354314692}
- component: {fileID: 1354314694}
- component: {fileID: 1354314693}
m_Layer: 5
m_Name: TextInput Override Ratio
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!224 &1354314692
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1354314691}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 304189374}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1354314693
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1354314691}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e9bc91696c1584e11b23dca1a9e3cde3, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Texture: {fileID: 0}
m_UVRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
devicePixelRatioOverride: 4
--- !u!222 &1354314694
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1354314691}
m_CullTransparentMesh: 0
--- !u!1 &1387978526
GameObject:
m_ObjectHideFlags: 0

y: 0
width: 1
height: 1
devicePixelRatioOverride: 0
--- !u!222 &1387978529
CanvasRenderer:
m_ObjectHideFlags: 0

- {fileID: 1556903570}
- {fileID: 335487699}
m_Father: {fileID: 304189374}
m_RootOrder: 2
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 1, y: 1}
m_AnchorMax: {x: 1, y: 1}

8
Editor/editor.meta


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

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:

16
Editor/editor/WidgetCanvasEditor.cs


using Unity.UIWidgets.engine;
using UnityEditor;
using UnityEditor.UI;
namespace Unity.UIWidgets.Editor {
[CustomEditor(typeof(WidgetCanvas), true)]
[CanEditMultipleObjects]
public class WidgetCanvasEditor : RawImageEditor {
public override void OnInspectorGUI() {
base.OnInspectorGUI();
var pixelRatioProperty = this.serializedObject.FindProperty("devicePixelRatioOverride");
EditorGUILayout.PropertyField(pixelRatioProperty);
this.serializedObject.ApplyModifiedProperties();
}
}
}

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:
正在加载...
取消
保存