diff --git a/Samples/UIWidgetsSamples_2019_4/Assets/Scene/ImageTest.unity b/Samples/UIWidgetsSamples_2019_4/Assets/Scene/ImageTest.unity index 52a7c3c0..497cd994 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 00000000..0195576d --- /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/Runtime/engine/UIWidgetsPanel.cs b/com.unity.uiwidgets/Runtime/engine/UIWidgetsPanel.cs index ba17216d..ab1fdc5f 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,15 +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; @@ -233,6 +239,7 @@ void CollectGarbageOnDemand() lastFrameMemory = mem; } #endif + #endregion #if !UNITY_EDITOR && UNITY_ANDROID @@ -263,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 += () => { @@ -274,7 +281,7 @@ protected void OnEnable() { #endif base.OnEnable(); - + D.assert(_wrapper == null); _configurations = new Configurations(); _wrapper = new UIWidgetsPanelWrapper(); @@ -284,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(); @@ -355,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) { @@ -376,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 } @@ -431,10 +438,43 @@ void _convertPointerData(PointerEventData evt, out Vector2? position, out int po } void Input_OnEnable() { +#if !UNITY_EDITOR && (UNITY_IOS || UNITY_ANDROID) + Input.RawTouchEvent += ProcessRawTouch; +#endif _inputMode = Input.mousePresent ? UIWidgetsInputMode.Mouse : UIWidgetsInputMode.Touch; } + 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 ((TouchPhase)param.phase) { + case TouchPhase.Began: + _wrapper.OnPointerDown(position, pointerId); + break; + case TouchPhase.Moved: + _wrapper.OnDrag(position, pointerId); + break; + + case TouchPhase.Ended: + _wrapper.OnPointerUp(position, pointerId); + break; + default: + break; + } + } + void Input_OnDisable() { +#if !UNITY_EDITOR && (UNITY_IOS || UNITY_ANDROID) + Input.RawTouchEvent -= ProcessRawTouch; +#endif } void Input_Update() { @@ -457,7 +497,7 @@ void Input_Update() { } } } - + #if UNITY_ANDROID && !UNITY_EDITOR if (Input.GetKeyDown(KeyCode.Escape)) { using (Isolate.getScope(anyIsolate)) { @@ -478,6 +518,7 @@ void _onMouseMove() { if (_inputMode != UIWidgetsInputMode.Mouse) { return; } + var pos = _getPointerPosition(Input.mousePosition); _wrapper.OnMouseMove(pos); } @@ -486,6 +527,7 @@ void _onScroll() { if (_inputMode != UIWidgetsInputMode.Mouse) { return; } + var pos = _getPointerPosition(Input.mousePosition); _wrapper.OnMouseScroll(Input.mouseScrollDelta, pos); } @@ -494,6 +536,7 @@ public void OnPointerEnter(PointerEventData eventData) { if (_inputMode != UIWidgetsInputMode.Mouse) { return; } + D.assert(eventData.pointerId < 0); _isEntered = true; _lastMousePosition = Input.mousePosition; @@ -503,11 +546,13 @@ public void OnPointerExit(PointerEventData eventData) { if (_inputMode != UIWidgetsInputMode.Mouse) { return; } + D.assert(eventData.pointerId < 0); _isEntered = false; _wrapper.OnPointerLeave(); } - + +#if UNITY_EDITOR || (!UNITY_IOS && !UNITY_ANDROID) public void OnPointerDown(PointerEventData eventData) { _convertPointerData(eventData, out var pos, out var pointerId); _wrapper.OnPointerDown(pos, pointerId); @@ -522,5 +567,15 @@ public void OnDrag(PointerEventData eventData) { _convertPointerData(eventData, out var pos, out var pointerId); _wrapper.OnDrag(pos, pointerId); } +#else + public void OnPointerDown(PointerEventData eventData) { + } + + public void OnPointerUp(PointerEventData eventData) { + } + + public void OnDrag(PointerEventData eventData) { + } +#endif } } \ No newline at end of file