-
Notifications
You must be signed in to change notification settings - Fork 79
Siyao h/1.17/raw touches #201
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ float _currentDevicePixelRatio { | |
} | ||
|
||
void Update() { | ||
|
||
_wrapper.onEditorUpdate(); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
|
@@ -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); | ||
|
@@ -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<string> assets, List<int> weights) { | ||
|
@@ -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 | ||
} | ||
|
@@ -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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() { | ||
|
@@ -457,7 +486,7 @@ void Input_Update() { | |
} | ||
} | ||
} | ||
|
||
#if UNITY_ANDROID && !UNITY_EDITOR | ||
if (Input.GetKeyDown(KeyCode.Escape)) { | ||
using (Isolate.getScope(anyIsolate)) { | ||
|
@@ -478,6 +507,7 @@ void _onMouseMove() { | |
if (_inputMode != UIWidgetsInputMode.Mouse) { | ||
return; | ||
} | ||
|
||
var pos = _getPointerPosition(Input.mousePosition); | ||
_wrapper.OnMouseMove(pos); | ||
} | ||
|
@@ -486,6 +516,7 @@ void _onScroll() { | |
if (_inputMode != UIWidgetsInputMode.Mouse) { | ||
return; | ||
} | ||
|
||
var pos = _getPointerPosition(Input.mousePosition); | ||
_wrapper.OnMouseScroll(Input.mouseScrollDelta, pos); | ||
} | ||
|
@@ -494,6 +525,7 @@ public void OnPointerEnter(PointerEventData eventData) { | |
if (_inputMode != UIWidgetsInputMode.Mouse) { | ||
return; | ||
} | ||
|
||
D.assert(eventData.pointerId < 0); | ||
_isEntered = true; | ||
_lastMousePosition = Input.mousePosition; | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can wrap onPointerDown, onPointerUp, onDrag into one single #if block? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty line?
There was a problem hiding this comment.
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.