Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
UFrameIT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FrameIT
UFrameIT
Commits
710fd613
Commit
710fd613
authored
2 years ago
by
Tobias Schöner
Browse files
Options
Downloads
Patches
Plain Diff
feat: Android: double-tap fact to favorise it
parent
cdca1e3b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Assets/Scripts/UI/FactExplorer/FactFavorisation.cs
+44
-10
44 additions, 10 deletions
Assets/Scripts/UI/FactExplorer/FactFavorisation.cs
with
44 additions
and
10 deletions
Assets/Scripts/UI/FactExplorer/FactFavorisation.cs
+
44
−
10
View file @
710fd613
...
...
@@ -4,7 +4,7 @@
using
UnityEngine.Events
;
using
UnityEngine.EventSystems
;
[
RequireComponent
(
typeof
(
FactWrapper
))]
[
RequireComponent
(
typeof
(
FactWrapper
)
,
typeof
(
RectTransform
)
)]
public
class
FactFavorisation
:
MonoBehaviour
,
IPointerClickHandler
{
#
region
InspectorVariables
...
...
@@ -20,6 +20,8 @@ public class FactFavorisation : MonoBehaviour, IPointerClickHandler
#
region
Variables
private
GameObject
favoriteDisplay
;
private
Fact
fact
;
private
const
float
COOLDOWN_DURATION
=
0.15f
;
// cooldown of the double touch
private
bool
touchOnCooldown
=
false
;
#
endregion
Variables
#
region
Properties
...
...
@@ -34,20 +36,18 @@ public bool IsFavorite
#
region
UnityMethods
public
void
OnPointerClick
(
PointerEventData
eventData
)
{
// TODO: add support for other input systems
if
(
eventData
.
button
==
PointerEventData
.
InputButton
.
Middle
)
{
// write to property to invoke event
IsFavorite
=
!
IsFavorite
;
// update favorites list
if
(
isFavorite
)
favorites
.
Add
(
fact
);
else
favorites
.
Remove
(
fact
);
ToggleFavorite
();
}
}
private
void
Update
()
{
if
(!
touchOnCooldown
)
HandleTouches
();
}
private
void
Start
()
{
fact
=
transform
.
GetComponent
<
FactWrapper
>().
fact
;
...
...
@@ -68,6 +68,28 @@ private void Start()
}
#
endregion
UnityMethods
#
region
TouchControls
private
void
HandleTouches
()
{
if
(
Input
.
touchCount
!=
1
)
return
;
var
touch
=
Input
.
touches
[
0
];
if
(
RectTransformUtility
.
RectangleContainsScreenPoint
(
transform
.
GetComponent
<
RectTransform
>(),
touch
.
position
)
&&
touch
.
tapCount
==
2
)
{
StartCoroutine
(
Cooldown
());
ToggleFavorite
();
}
}
private
IEnumerator
Cooldown
()
{
touchOnCooldown
=
true
;
yield
return
new
WaitForSeconds
(
COOLDOWN_DURATION
);
touchOnCooldown
=
false
;
}
#
endregion
TouchControls
#
region
Implementation
private
void
OnFavoriteChange
(
Fact
changedFact
,
bool
isFavorite
)
{
...
...
@@ -82,5 +104,17 @@ private void UpdateDisplay()
{
favoriteDisplay
.
SetActive
(
isFavorite
);
}
private
void
ToggleFavorite
()
{
// write to property to invoke event
IsFavorite
=
!
IsFavorite
;
// update favorites list
if
(
isFavorite
)
favorites
.
Add
(
fact
);
else
favorites
.
Remove
(
fact
);
}
#
endregion
Implementation
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment