Skip to content
This repository was archived by the owner on Sep 7, 2022. It is now read-only.

Siyao h/1.17/raw touches #201

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions Samples/UIWidgetsSamples_2019_4/Assets/Scene/ImageTest.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 69 additions & 14 deletions com.unity.uiwidgets/Runtime/engine/UIWidgetsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,18 @@ public interface IUIWidgetsWindow {

UIWidgetsWindowType getWindowType();
}

public class Configurations {

private Dictionary<string, TextFont> _textFonts = new Dictionary<string, TextFont>();

public void Clear() {
_textFonts.Clear();
}

public void AddFont(string family, TextFont font) {
_textFonts[key: family] = font;
_textFonts[key: family] = font;
}

public object fontsToObject() {
Dictionary<string, TextFont> settings = _textFonts;
if (settings == null || settings.Count == 0) {
Expand All @@ -72,7 +74,7 @@ public object fontsToObject() {
for (var j = 0; j < setting.Value.fonts.Length; j++) {
var fontDic = new Dictionary<string, object>();
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);
Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -233,6 +239,7 @@ void CollectGarbageOnDemand()
lastFrameMemory = mem;
}
#endif

#endregion

#if !UNITY_EDITOR && UNITY_ANDROID
Expand Down Expand Up @@ -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 += () => {
Expand All @@ -274,7 +281,7 @@ protected void OnEnable() {
#endif

base.OnEnable();

D.assert(_wrapper == null);
_configurations = new Configurations();
_wrapper = new UIWidgetsPanelWrapper();
Expand All @@ -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();
Expand Down Expand Up @@ -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<string> assets, List<int> weights) {
Expand All @@ -376,13 +384,12 @@ protected void AddFont(string family, List<string> assets, List<int> weights) {
textFont.fonts = fonts;
AddFont(family: family, font: textFont);
}

protected virtual void main() {
}
}

enum UIWidgetsInputMode
{
enum UIWidgetsInputMode {
Mouse,
Touch
}
Expand Down Expand Up @@ -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() {
Expand All @@ -457,7 +497,7 @@ void Input_Update() {
}
}
}

#if UNITY_ANDROID && !UNITY_EDITOR
if (Input.GetKeyDown(KeyCode.Escape)) {
using (Isolate.getScope(anyIsolate)) {
Expand All @@ -478,6 +518,7 @@ void _onMouseMove() {
if (_inputMode != UIWidgetsInputMode.Mouse) {
return;
}

var pos = _getPointerPosition(Input.mousePosition);
_wrapper.OnMouseMove(pos);
}
Expand All @@ -486,6 +527,7 @@ void _onScroll() {
if (_inputMode != UIWidgetsInputMode.Mouse) {
return;
}

var pos = _getPointerPosition(Input.mousePosition);
_wrapper.OnMouseScroll(Input.mouseScrollDelta, pos);
}
Expand All @@ -494,6 +536,7 @@ public void OnPointerEnter(PointerEventData eventData) {
if (_inputMode != UIWidgetsInputMode.Mouse) {
return;
}

D.assert(eventData.pointerId < 0);
_isEntered = true;
_lastMousePosition = Input.mousePosition;
Expand All @@ -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);
Expand All @@ -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
}
}