X Tutup
Skip to content

Commit 361912c

Browse files
committed
Fix zoom on mobile to work after tapping button in decorations scroll view
Improved click detection to avoid cancelling too many move tool drags Fix move tool creature edit cancellation
1 parent 575c1d3 commit 361912c

File tree

7 files changed

+41
-64
lines changed

7 files changed

+41
-64
lines changed

Assets/Scenes/EditorScene.unity

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,7 +2533,6 @@ GameObject:
25332533
- component: {fileID: 111325318}
25342534
- component: {fileID: 111325319}
25352535
- component: {fileID: 111325320}
2536-
- component: {fileID: 111325321}
25372536
m_Layer: 5
25382537
m_Name: Decorations Container
25392538
m_TagString: Untagged
@@ -2615,19 +2614,6 @@ MonoBehaviour:
26152614
m_PreInfinity: 2
26162615
m_PostInfinity: 2
26172616
m_RotationOrder: 4
2618-
--- !u!114 &111325321
2619-
MonoBehaviour:
2620-
m_ObjectHideFlags: 0
2621-
m_CorrespondingSourceObject: {fileID: 0}
2622-
m_PrefabInstance: {fileID: 0}
2623-
m_PrefabAsset: {fileID: 0}
2624-
m_GameObject: {fileID: 111325317}
2625-
m_Enabled: 1
2626-
m_EditorHideFlags: 0
2627-
m_Script: {fileID: 11500000, guid: 4a771390974b54ebd86609cf0505e8a4, type: 3}
2628-
m_Name:
2629-
m_EditorClassIdentifier:
2630-
isHovered: 0
26312617
--- !u!1 &112237770
26322618
GameObject:
26332619
m_ObjectHideFlags: 0
@@ -12204,7 +12190,7 @@ MonoBehaviour:
1220412190
m_HandleRect: {fileID: 727723756}
1220512191
m_Direction: 2
1220612192
m_Value: 1
12207-
m_Size: 0.41993958
12193+
m_Size: 0.41993964
1220812194
m_NumberOfSteps: 0
1220912195
m_OnValueChanged:
1221012196
m_PersistentCalls:
@@ -31332,8 +31318,8 @@ MonoBehaviour:
3133231318
zoomOutLength: 10
3133331319
InteractiveZoomEnabled: 1
3133431320
pointerHoverAreasToIgnore:
31335-
- {fileID: 111325321}
31336-
- {fileID: 2146675146}
31321+
- {fileID: 111325317}
31322+
- {fileID: 1735218480}
3133731323
bottomMovementPadding: 10
3133831324
topMovementPadding: 10
3133931325
leftMovementPadding: 18
@@ -36740,19 +36726,6 @@ MonoBehaviour:
3674036726
m_Script: {fileID: 11500000, guid: 76b19727cc9c74f958d6f0045394281e, type: 3}
3674136727
m_Name:
3674236728
m_EditorClassIdentifier:
36743-
--- !u!114 &2146675146
36744-
MonoBehaviour:
36745-
m_ObjectHideFlags: 0
36746-
m_CorrespondingSourceObject: {fileID: 0}
36747-
m_PrefabInstance: {fileID: 0}
36748-
m_PrefabAsset: {fileID: 0}
36749-
m_GameObject: {fileID: 1735218480}
36750-
m_Enabled: 1
36751-
m_EditorHideFlags: 0
36752-
m_Script: {fileID: 11500000, guid: 4a771390974b54ebd86609cf0505e8a4, type: 3}
36753-
m_Name:
36754-
m_EditorClassIdentifier:
36755-
isHovered: 0
3675636729
--- !u!1 &1076516961774623
3675736730
GameObject:
3675836731
m_ObjectHideFlags: 0
@@ -38305,11 +38278,7 @@ PrefabInstance:
3830538278
m_RemovedComponents: []
3830638279
m_RemovedGameObjects: []
3830738280
m_AddedGameObjects: []
38308-
m_AddedComponents:
38309-
- targetCorrespondingSourceObject: {fileID: 3593883801664574350, guid: dfac67bc1c72344cc9fea855a05b1677,
38310-
type: 3}
38311-
insertIndex: -1
38312-
addedObject: {fileID: 2146675146}
38281+
m_AddedComponents: []
3831338282
m_SourcePrefab: {fileID: 100100000, guid: dfac67bc1c72344cc9fea855a05b1677, type: 3}
3831438283
--- !u!1660057539 &9223372036854775807
3831538284
SceneRoots:

Assets/Scripts/Controllers/CreatureEditor.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,6 @@ private void HandleClicks() {
457457
break;
458458

459459
case Tool.Move:
460-
if (!this.currentClickStartedOverUI) {
461-
creatureEdited = creatureBuilder.MoveEnded(jointsToMove, decorationsToMove);
462-
}
463460
if (GestureRecognizerCollection.shared.GetClickGestureRecognizer().ClickEndedOnThisFrame() &&
464461
selectionManager.LastHoveringIsPartOfSelection() &&
465462
!currentClickStartedOverTransformGizmo &&
@@ -472,8 +469,11 @@ private void HandleClicks() {
472469
transformGizmo.Reset();
473470
creatureBuilder.CancelMove(jointsToMove, decorationsToMove, oldDesign);
474471
creatureEdited = false;
475-
} else if (!currentClickStartedOverTransformGizmo) {
476-
if (!isPointerOverUI) {
472+
} else {
473+
if (!this.currentClickStartedOverUI) {
474+
creatureEdited = creatureBuilder.MoveEnded(jointsToMove, decorationsToMove);
475+
}
476+
if (!currentClickStartedOverTransformGizmo && !isPointerOverUI) {
477477
transformGizmo.gameObject.SetActive(false);
478478
jointsToMove.Clear();
479479
decorationsToMove.Clear();

Assets/Scripts/Controllers/EditorSelectionManager.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ private void UpdateHoveringSelection(Vector3 mouseScreenPos) {
102102
if (Input.touchCount != 1) {
103103
hovering = null;
104104
}
105+
if (Input.touchCount > 0 && InputUtils.IsTouchOverUI(Input.GetTouch(0).fingerId)) {
106+
hovering = null;
107+
}
105108
#endif
106109

107110
this.lastHovering = currentHovering;

Assets/Scripts/Util/ClickGestureRecognizer.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ public class ClickGestureRecognizer: MonoBehaviour, IGestureRecognizer<ClickGest
1313

1414
private float clickStartTime = 0f;
1515

16-
private const float CLICK_DURATION_THRESHOLD = 0.5f;
16+
private const float CLICK_DURATION_THRESHOLD = 0.3f;
1717
#if UNITY_IOS || UNITY_ANDROID
18-
private const float CLICK_MOVE_THRESHOLD = 40f;
18+
private const float CLICK_MOVE_THRESHOLD_IN_DP = 6f;
1919
#else
20-
private const float CLICK_MOVE_THRESHOLD = 5f;
20+
private const float CLICK_MOVE_THRESHOLD_IN_DP = 2f;
2121
#endif
2222

2323
void Update() {
@@ -43,7 +43,8 @@ void Update() {
4343
if (clickDuration > CLICK_DURATION_THRESHOLD) {
4444
this.State = GestureRecognizerState.Cancelled;
4545
}
46-
if (Vector2.Distance(Input.mousePosition, this.ClickPosition) > CLICK_MOVE_THRESHOLD) {
46+
float clickMoveThresholdInPx = DpToPixels(CLICK_MOVE_THRESHOLD_IN_DP);
47+
if (Vector2.Distance(Input.mousePosition, this.ClickPosition) > clickMoveThresholdInPx) {
4748
this.State = GestureRecognizerState.Cancelled;
4849
}
4950
}
@@ -60,5 +61,14 @@ void Update() {
6061
public bool ClickEndedOnThisFrame() {
6162
return this.State == GestureRecognizerState.Ended;
6263
}
64+
65+
private float DpToPixels(float dp) {
66+
float dpi = Screen.dpi;
67+
// Apparently, Screen.dpi can be 0 on some devices
68+
if (dpi == 0) {
69+
dpi = 160f;
70+
}
71+
return dp * (dpi / 160f);
72+
}
6373
}
6474
}

Assets/Scripts/Util/ZoomableCamera.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private float zoomLength {
4343

4444
public bool InteractiveZoomEnabled = true;
4545

46-
public PointerHoverDetector[] pointerHoverAreasToIgnore;
46+
public GameObject[] pointerHoverAreasToIgnore;
4747

4848
private Camera _camera;
4949

@@ -87,8 +87,20 @@ private bool ZoomingIsAllowed() {
8787
return false;
8888
}
8989
if (pointerHoverAreasToIgnore != null) {
90-
foreach (PointerHoverDetector pointerHoverDetector in pointerHoverAreasToIgnore) {
91-
if (pointerHoverDetector.gameObject.activeInHierarchy && pointerHoverDetector.isHovered) {
90+
foreach (GameObject pointerHoverArea in pointerHoverAreasToIgnore) {
91+
if (!pointerHoverArea.gameObject.activeInHierarchy) {
92+
continue;
93+
}
94+
bool isHovered = false;
95+
RectTransform rect = pointerHoverArea.transform as RectTransform;
96+
#if UNITY_IOS || UNITY_ANDROID
97+
for (int touchI = 0; touchI < Input.touchCount; touchI++) {
98+
isHovered |= RectTransformUtility.RectangleContainsScreenPoint(rect, Input.GetTouch(touchI).position);
99+
}
100+
#else
101+
isHovered = RectTransformUtility.RectangleContainsScreenPoint(rect, Input.mousePosition);
102+
#endif
103+
if (isHovered) {
92104
return false;
93105
}
94106
}

Assets/Scripts/View/PointerHoverDetector.cs

Lines changed: 0 additions & 15 deletions
This file was deleted.

Assets/Scripts/View/PointerHoverDetector.cs.meta

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)
X Tutup