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
8022f5a8
Commit
8022f5a8
authored
2 years ago
by
Tobias Schöner
Browse files
Options
Downloads
Patches
Plain Diff
feat: FactExplorer can be opened on long touch
parent
226d92b1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Assets/Scripts/UI/FactExplorer/OpenFactExplorer.cs
+58
-6
58 additions, 6 deletions
Assets/Scripts/UI/FactExplorer/OpenFactExplorer.cs
with
58 additions
and
6 deletions
Assets/Scripts/UI/FactExplorer/OpenFactExplorer.cs
+
58
−
6
View file @
8022f5a8
using
System
;
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
...
...
@@ -6,23 +7,74 @@
[
RequireComponent
(
typeof
(
FactWrapper
))]
public
class
OpenFactExplorer
:
MonoBehaviour
,
IPointerClickHandler
{
#
region
Variables
public
GameObject
factExplorerPrefab
;
private
static
Transform
factExplorer
;
private
float
pressTime
=
0f
;
private
const
float
LONG_PRESS_DURATION
=
0.5f
;
#
endregion
Variables
#
region
UnityMethods
public
void
OnPointerClick
(
PointerEventData
eventData
)
{
//
TODO: add support for other input systems
//
open FactExplorer on right click on PC
if
(
eventData
.
button
==
PointerEventData
.
InputButton
.
Right
)
{
Destroy
(
factExplorer
!=
null
?
factExplorer
.
gameObject
:
null
);
DoOpenFactExplorer
();
}
}
private
void
Update
()
{
// open FactExplorer on press on fact longer than LONG_PRESS_DURATION
HandleTouches
();
}
#
endregion
UnityMethods
#
region
Implementation
private
void
HandleTouches
()
{
if
(
Input
.
touchCount
!=
1
)
{
pressTime
=
0
;
return
;
}
var
parent
=
transform
.
GetComponentInParent
<
Canvas
>().
transform
;
var
fact
=
transform
.
GetComponent
<
FactWrapper
>().
fact
;
var
touch
=
Input
.
GetTouch
(
0
);
if
(!
RectTransformUtility
.
RectangleContainsScreenPoint
(
transform
.
GetComponent
<
RectTransform
>(),
touch
.
position
))
{
pressTime
=
0
;
return
;
}
factExplorer
=
Instantiate
(
factExplorerPrefab
.
transform
,
Input
.
mousePosition
,
Quaternion
.
identity
,
parent
);
factExplorer
.
GetComponent
<
FactExplorer
>().
Initialize
(
fact
,
transform
.
position
);
switch
(
touch
.
phase
)
{
case
TouchPhase
.
Moved
:
case
TouchPhase
.
Began
:
case
TouchPhase
.
Ended
:
case
TouchPhase
.
Canceled
:
pressTime
=
0
;
break
;
case
TouchPhase
.
Stationary
:
pressTime
+=
Time
.
deltaTime
;
if
(
pressTime
>=
LONG_PRESS_DURATION
)
DoOpenFactExplorer
();
break
;
}
}
private
void
DoOpenFactExplorer
()
{
Destroy
(
factExplorer
!=
null
?
factExplorer
.
gameObject
:
null
);
var
parent
=
transform
.
GetComponentInParent
<
Canvas
>().
transform
;
var
fact
=
transform
.
GetComponent
<
FactWrapper
>().
fact
;
factExplorer
=
Instantiate
(
factExplorerPrefab
.
transform
,
Input
.
mousePosition
,
Quaternion
.
identity
,
parent
);
factExplorer
.
GetComponent
<
FactExplorer
>().
Initialize
(
fact
,
transform
.
position
);
}
#
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