From adf2c8d95a927b9deec820393e4ecd3f48d27be1 Mon Sep 17 00:00:00 2001 From: siyao Date: Tue, 13 Jul 2021 15:57:10 +0800 Subject: [PATCH 1/5] add touch --- .../Assets/Materials.meta | 8 ++++ .../Assets/Scene/ImageTest.unity | 47 +++++++++++++++++-- .../WidgetsSample/MobileTouchSample.cs.meta | 11 +++++ .../Editor/UIWidgetsEditorPanel.cs | 1 + .../Runtime/engine/UIWidgetsPanel.cs | 11 +++++ com.unity.uiwidgets/Scripts/node_modules.meta | 8 ++++ 6 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 Samples/UIWidgetsSamples_2019_4/Assets/Materials.meta create mode 100644 Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/MobileTouchSample.cs.meta create mode 100644 com.unity.uiwidgets/Scripts/node_modules.meta diff --git a/Samples/UIWidgetsSamples_2019_4/Assets/Materials.meta b/Samples/UIWidgetsSamples_2019_4/Assets/Materials.meta new file mode 100644 index 000000000..fb3533cae --- /dev/null +++ b/Samples/UIWidgetsSamples_2019_4/Assets/Materials.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 78131615b01837e4ca2d2b318e272475 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Samples/UIWidgetsSamples_2019_4/Assets/Scene/ImageTest.unity b/Samples/UIWidgetsSamples_2019_4/Assets/Scene/ImageTest.unity index 52a7c3c07..497cd9947 100644 --- a/Samples/UIWidgetsSamples_2019_4/Assets/Scene/ImageTest.unity +++ b/Samples/UIWidgetsSamples_2019_4/Assets/Scene/ImageTest.unity @@ -269,16 +269,15 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_Texture: {fileID: 0} + m_Texture: {fileID: 1525330782} m_UVRect: serializedVersion: 2 x: 0 y: 0 width: 1 height: 1 - fonts: [] - devicePixelRatioOverride: 0 hardwareAntiAliasing: 0 + fonts: [] --- !u!222 &847097471 CanvasRenderer: m_ObjectHideFlags: 0 @@ -287,6 +286,48 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 847097468} m_CullTransparentMesh: 0 +--- !u!28 &1525330782 +Texture2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_ImageContentsHash: + serializedVersion: 2 + Hash: 00000000000000000000000000000000 + m_ForcedFallbackFormat: 4 + m_DownscaleFallback: 0 + serializedVersion: 2 + m_Width: 0 + m_Height: 0 + m_CompleteImageSize: 0 + m_TextureFormat: 0 + m_MipCount: 1 + m_IsReadable: 1 + m_IgnoreMasterTextureLimit: 0 + m_IsPreProcessed: 0 + m_StreamingMipmaps: 0 + m_StreamingMipmapsPriority: 0 + m_AlphaIsTransparency: 0 + m_ImageCount: 0 + m_TextureDimension: 2 + m_TextureSettings: + serializedVersion: 2 + m_FilterMode: 1 + m_Aniso: 1 + m_MipBias: 0 + m_WrapU: 0 + m_WrapV: 0 + m_WrapW: 0 + m_LightmapFormat: 0 + m_ColorSpace: 0 + image data: 0 + _typelessdata: + m_StreamData: + offset: 0 + size: 0 + path: --- !u!1 &1548023132 GameObject: m_ObjectHideFlags: 0 diff --git a/Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/MobileTouchSample.cs.meta b/Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/MobileTouchSample.cs.meta new file mode 100644 index 000000000..0195576d7 --- /dev/null +++ b/Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/MobileTouchSample.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a5573cb4e607a9e48983cecf7876926e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.uiwidgets/Editor/UIWidgetsEditorPanel.cs b/com.unity.uiwidgets/Editor/UIWidgetsEditorPanel.cs index f50660aee..4c77a617c 100644 --- a/com.unity.uiwidgets/Editor/UIWidgetsEditorPanel.cs +++ b/com.unity.uiwidgets/Editor/UIWidgetsEditorPanel.cs @@ -28,6 +28,7 @@ float _currentDevicePixelRatio { } void Update() { + _wrapper.onEditorUpdate(); } diff --git a/com.unity.uiwidgets/Runtime/engine/UIWidgetsPanel.cs b/com.unity.uiwidgets/Runtime/engine/UIWidgetsPanel.cs index ba17216d5..dd25872eb 100644 --- a/com.unity.uiwidgets/Runtime/engine/UIWidgetsPanel.cs +++ b/com.unity.uiwidgets/Runtime/engine/UIWidgetsPanel.cs @@ -181,6 +181,8 @@ protected virtual void Update() { CollectGarbageOnDemand(); #endif + + Input_Update(); } @@ -431,13 +433,22 @@ void _convertPointerData(PointerEventData evt, out Vector2? position, out int po } void Input_OnEnable() { + Input.touchRawProcess += LogTouch; + _inputMode = Input.mousePresent ? UIWidgetsInputMode.Mouse : UIWidgetsInputMode.Touch; } + public static int count = 0; + public void LogTouch(Input.ProcessRawTouchesParam param) { + _wrapper.OnDrag(new Vector2(param.x, param.y), (int) param.pointerId); + } + void Input_OnDisable() { + Input.touchRawProcess -= LogTouch; } void Input_Update() { + Debug.Log($"count {count}"); //we only process hover events for desktop applications if (_inputMode == UIWidgetsInputMode.Mouse) { if (_isEntered) { diff --git a/com.unity.uiwidgets/Scripts/node_modules.meta b/com.unity.uiwidgets/Scripts/node_modules.meta new file mode 100644 index 000000000..050c11d96 --- /dev/null +++ b/com.unity.uiwidgets/Scripts/node_modules.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 74fb90dac38da964980b37b5d68c6a95 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From 17bb61644fc25f062f5eee28bea1aa8e597d6b20 Mon Sep 17 00:00:00 2001 From: siyao Date: Wed, 14 Jul 2021 10:42:38 +0800 Subject: [PATCH 2/5] format --- .../Runtime/engine/UIWidgetsPanel.cs | 68 +++++++++++++------ 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/com.unity.uiwidgets/Runtime/engine/UIWidgetsPanel.cs b/com.unity.uiwidgets/Runtime/engine/UIWidgetsPanel.cs index dd25872eb..688d37b28 100644 --- a/com.unity.uiwidgets/Runtime/engine/UIWidgetsPanel.cs +++ b/com.unity.uiwidgets/Runtime/engine/UIWidgetsPanel.cs @@ -47,16 +47,18 @@ public interface IUIWidgetsWindow { UIWidgetsWindowType getWindowType(); } + public class Configurations { - private Dictionary _textFonts = new Dictionary(); public void Clear() { _textFonts.Clear(); } + public void AddFont(string family, TextFont font) { - _textFonts[key: family] = font; + _textFonts[key: family] = font; } + public object fontsToObject() { Dictionary settings = _textFonts; if (settings == null || settings.Count == 0) { @@ -72,7 +74,7 @@ public object fontsToObject() { for (var j = 0; j < setting.Value.fonts.Length; j++) { var fontDic = new Dictionary(); var fileExist = false; - + if (setting.Value.fonts[j].asset.Length > 0) { var assetPath = setting.Value.fonts[j].asset; var assetAbsolutePath = Path.Combine(Application.streamingAssetsPath, assetPath); @@ -81,11 +83,13 @@ public object fontsToObject() { #else if (!File.Exists(assetAbsolutePath)) { #endif - Debug.LogError($"The font asset (family: \"{setting.Key}\", path: \"{assetPath}\") is not found"); + Debug.LogError( + $"The font asset (family: \"{setting.Key}\", path: \"{assetPath}\") is not found"); } else { fileExist = true; } + fontDic.Add("asset", value: setting.Value.fonts[j].asset); } @@ -176,17 +180,17 @@ protected virtual void Update() { UIWidgetsMessageManager.instance?.AddChannelMessageDelegate("ViewportMetricsChanged", _handleViewMetricsChanged); } - + #if !UNITY_EDITOR CollectGarbageOnDemand(); #endif - Input_Update(); } #region OnDemandGC + #if !UNITY_EDITOR // 8 MB const long kCollectAfterAllocating = 8 * 1024 * 1024; @@ -235,6 +239,7 @@ void CollectGarbageOnDemand() lastFrameMemory = mem; } #endif + #endregion #if !UNITY_EDITOR && UNITY_ANDROID @@ -265,7 +270,7 @@ protected void OnEnable() { //the hook API cannot be automatically called on IOS, so we need try hook it here Hooks.tryHook(); #endif - + #if !UNITY_EDITOR TryEnableOnDemandGC(); Application.lowMemory += () => { @@ -276,7 +281,7 @@ protected void OnEnable() { #endif base.OnEnable(); - + D.assert(_wrapper == null); _configurations = new Configurations(); _wrapper = new UIWidgetsPanelWrapper(); @@ -286,6 +291,7 @@ protected void OnEnable() { AddFont(family: font.family, font: font); } } + _wrapper.Initiate(this, width: _currentWidth, height: _currentHeight, dpr: _currentDevicePixelRatio, _configurations: _configurations); _configurations.Clear(); @@ -357,9 +363,9 @@ public void mainEntry() { protected virtual void onEnable() { } - + protected void AddFont(string family, TextFont font) { - _configurations.AddFont(family,font); + _configurations.AddFont(family, font); } protected void AddFont(string family, List assets, List weights) { @@ -378,13 +384,12 @@ protected void AddFont(string family, List assets, List weights) { textFont.fonts = fonts; AddFont(family: family, font: textFont); } - + protected virtual void main() { } } - enum UIWidgetsInputMode - { + enum UIWidgetsInputMode { Mouse, Touch } @@ -433,22 +438,35 @@ void _convertPointerData(PointerEventData evt, out Vector2? position, out int po } void Input_OnEnable() { - Input.touchRawProcess += LogTouch; + Input.touchRawProcess += ProcessRawTouch; _inputMode = Input.mousePresent ? UIWidgetsInputMode.Mouse : UIWidgetsInputMode.Touch; } - public static int count = 0; - public void LogTouch(Input.ProcessRawTouchesParam param) { - _wrapper.OnDrag(new Vector2(param.x, param.y), (int) param.pointerId); + public void ProcessRawTouch(Input.ProcessRawTouchesParam param) { + var position = _getPointerPosition(new Vector2(param.x, param.y)); + var pointerId = -1 - param.pointerId; + switch (param.phase) { + case 0: + _wrapper.OnPointerDown(position, pointerId); + break; + case 1: + _wrapper.OnDrag(position, pointerId); + break; + + case 3: + _wrapper.OnPointerUp(position, pointerId); + break; + default: + break; + } } void Input_OnDisable() { - Input.touchRawProcess -= LogTouch; + Input.touchRawProcess -= ProcessRawTouch; } void Input_Update() { - Debug.Log($"count {count}"); //we only process hover events for desktop applications if (_inputMode == UIWidgetsInputMode.Mouse) { if (_isEntered) { @@ -468,7 +486,7 @@ void Input_Update() { } } } - + #if UNITY_ANDROID && !UNITY_EDITOR if (Input.GetKeyDown(KeyCode.Escape)) { using (Isolate.getScope(anyIsolate)) { @@ -489,6 +507,7 @@ void _onMouseMove() { if (_inputMode != UIWidgetsInputMode.Mouse) { return; } + var pos = _getPointerPosition(Input.mousePosition); _wrapper.OnMouseMove(pos); } @@ -497,6 +516,7 @@ void _onScroll() { if (_inputMode != UIWidgetsInputMode.Mouse) { return; } + var pos = _getPointerPosition(Input.mousePosition); _wrapper.OnMouseScroll(Input.mouseScrollDelta, pos); } @@ -505,6 +525,7 @@ public void OnPointerEnter(PointerEventData eventData) { if (_inputMode != UIWidgetsInputMode.Mouse) { return; } + D.assert(eventData.pointerId < 0); _isEntered = true; _lastMousePosition = Input.mousePosition; @@ -514,24 +535,31 @@ public void OnPointerExit(PointerEventData eventData) { if (_inputMode != UIWidgetsInputMode.Mouse) { return; } + D.assert(eventData.pointerId < 0); _isEntered = false; _wrapper.OnPointerLeave(); } public void OnPointerDown(PointerEventData eventData) { +#if UNITY_EDITOR || (!UNITY_IOS && !UNITY_ANDROID) _convertPointerData(eventData, out var pos, out var pointerId); _wrapper.OnPointerDown(pos, pointerId); +#endif } public void OnPointerUp(PointerEventData eventData) { +#if UNITY_EDITOR || (!UNITY_IOS && !UNITY_ANDROID) _convertPointerData(eventData, out var pos, out var pointerId); _wrapper.OnPointerUp(pos, pointerId); +#endif } public void OnDrag(PointerEventData eventData) { +#if UNITY_EDITOR || (!UNITY_IOS && !UNITY_ANDROID) _convertPointerData(eventData, out var pos, out var pointerId); _wrapper.OnDrag(pos, pointerId); +#endif } } } \ No newline at end of file From b9725341bd6fdb6af4044e07fb6d9bcc17a65dee Mon Sep 17 00:00:00 2001 From: siyao Date: Wed, 14 Jul 2021 15:51:12 +0800 Subject: [PATCH 3/5] fix --- .../Editor/UIWidgetsEditorPanel.cs | 1 - .../Runtime/engine/UIWidgetsPanel.cs | 46 +++++++++++++------ 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/com.unity.uiwidgets/Editor/UIWidgetsEditorPanel.cs b/com.unity.uiwidgets/Editor/UIWidgetsEditorPanel.cs index 4c77a617c..f50660aee 100644 --- a/com.unity.uiwidgets/Editor/UIWidgetsEditorPanel.cs +++ b/com.unity.uiwidgets/Editor/UIWidgetsEditorPanel.cs @@ -28,7 +28,6 @@ float _currentDevicePixelRatio { } void Update() { - _wrapper.onEditorUpdate(); } diff --git a/com.unity.uiwidgets/Runtime/engine/UIWidgetsPanel.cs b/com.unity.uiwidgets/Runtime/engine/UIWidgetsPanel.cs index 688d37b28..ab1fdc5f4 100644 --- a/com.unity.uiwidgets/Runtime/engine/UIWidgetsPanel.cs +++ b/com.unity.uiwidgets/Runtime/engine/UIWidgetsPanel.cs @@ -438,23 +438,32 @@ void _convertPointerData(PointerEventData evt, out Vector2? position, out int po } void Input_OnEnable() { - Input.touchRawProcess += ProcessRawTouch; - +#if !UNITY_EDITOR && (UNITY_IOS || UNITY_ANDROID) + Input.RawTouchEvent += ProcessRawTouch; +#endif _inputMode = Input.mousePresent ? UIWidgetsInputMode.Mouse : UIWidgetsInputMode.Touch; } - public void ProcessRawTouch(Input.ProcessRawTouchesParam param) { + enum TouchPhase { + Began = 0, + Moved = 1, + Stationary = 2, + Ended = 3, + Canceled = 4 + } + + void ProcessRawTouch(Input.RawTouchEventParam param) { var position = _getPointerPosition(new Vector2(param.x, param.y)); var pointerId = -1 - param.pointerId; - switch (param.phase) { - case 0: + switch ((TouchPhase)param.phase) { + case TouchPhase.Began: _wrapper.OnPointerDown(position, pointerId); break; - case 1: + case TouchPhase.Moved: _wrapper.OnDrag(position, pointerId); break; - case 3: + case TouchPhase.Ended: _wrapper.OnPointerUp(position, pointerId); break; default: @@ -463,7 +472,9 @@ public void ProcessRawTouch(Input.ProcessRawTouchesParam param) { } void Input_OnDisable() { - Input.touchRawProcess -= ProcessRawTouch; +#if !UNITY_EDITOR && (UNITY_IOS || UNITY_ANDROID) + Input.RawTouchEvent -= ProcessRawTouch; +#endif } void Input_Update() { @@ -540,26 +551,31 @@ public void OnPointerExit(PointerEventData eventData) { _isEntered = false; _wrapper.OnPointerLeave(); } - - public void OnPointerDown(PointerEventData eventData) { + #if UNITY_EDITOR || (!UNITY_IOS && !UNITY_ANDROID) + public void OnPointerDown(PointerEventData eventData) { _convertPointerData(eventData, out var pos, out var pointerId); _wrapper.OnPointerDown(pos, pointerId); -#endif } public void OnPointerUp(PointerEventData eventData) { -#if UNITY_EDITOR || (!UNITY_IOS && !UNITY_ANDROID) _convertPointerData(eventData, out var pos, out var pointerId); _wrapper.OnPointerUp(pos, pointerId); -#endif } public void OnDrag(PointerEventData eventData) { -#if UNITY_EDITOR || (!UNITY_IOS && !UNITY_ANDROID) _convertPointerData(eventData, out var pos, out var pointerId); _wrapper.OnDrag(pos, pointerId); -#endif } +#else + public void OnPointerDown(PointerEventData eventData) { + } + + public void OnPointerUp(PointerEventData eventData) { + } + + public void OnDrag(PointerEventData eventData) { + } +#endif } } \ No newline at end of file From ec1cf5ae2de3cb13b1bc363b94c179dae2f09e4d Mon Sep 17 00:00:00 2001 From: Xingwei Zhu Date: Tue, 10 Aug 2021 11:48:26 +0800 Subject: [PATCH 4/5] remove unused file --- com.unity.uiwidgets/Scripts/node_modules.meta | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 com.unity.uiwidgets/Scripts/node_modules.meta diff --git a/com.unity.uiwidgets/Scripts/node_modules.meta b/com.unity.uiwidgets/Scripts/node_modules.meta deleted file mode 100644 index 050c11d96..000000000 --- a/com.unity.uiwidgets/Scripts/node_modules.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 74fb90dac38da964980b37b5d68c6a95 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: From 76123f4d3e0ff334d6c6fff08718e2a610cc5369 Mon Sep 17 00:00:00 2001 From: Xingwei Zhu Date: Tue, 10 Aug 2021 11:49:32 +0800 Subject: [PATCH 5/5] remove unused file --- Samples/UIWidgetsSamples_2019_4/Assets/Materials.meta | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 Samples/UIWidgetsSamples_2019_4/Assets/Materials.meta diff --git a/Samples/UIWidgetsSamples_2019_4/Assets/Materials.meta b/Samples/UIWidgetsSamples_2019_4/Assets/Materials.meta deleted file mode 100644 index fb3533cae..000000000 --- a/Samples/UIWidgetsSamples_2019_4/Assets/Materials.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 78131615b01837e4ca2d2b318e272475 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: