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 2 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
8 changes: 8 additions & 0 deletions Samples/UIWidgetsSamples_2019_4/Assets/Materials.meta

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

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.

1 change: 1 addition & 0 deletions com.unity.uiwidgets/Editor/UIWidgetsEditorPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ float _currentDevicePixelRatio {
}

void Update() {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will delete it. This might come from auth reformat code.

_wrapper.onEditorUpdate();
}

Expand Down
65 changes: 52 additions & 13 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,32 @@ void _convertPointerData(PointerEventData evt, out Vector2? position, out int po
}

void Input_OnEnable() {
Input.touchRawProcess += ProcessRawTouch;

_inputMode = Input.mousePresent ? UIWidgetsInputMode.Mouse : UIWidgetsInputMode.Touch;
}

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use "magic number", please define some enums and use them instead

_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 -= ProcessRawTouch;
}

void Input_Update() {
Expand All @@ -457,7 +486,7 @@ void Input_Update() {
}
}
}

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

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

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

D.assert(eventData.pointerId < 0);
_isEntered = true;
_lastMousePosition = Input.mousePosition;
Expand All @@ -503,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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can wrap onPointerDown, onPointerUp, onDrag into one single #if block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried and failed. Since we inherent certain interface, wee need to add these function. Or do we add #if for interface as well?

#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
}
}
}
8 changes: 8 additions & 0 deletions com.unity.uiwidgets/Scripts/node_modules.meta

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