forked from microsoft/MixedRealityToolkit-Unity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PanZoomRectTransf.cs
124 lines (101 loc) · 5.11 KB
/
PanZoomRectTransf.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using Microsoft.MixedReality.Toolkit.Input;
using UnityEngine;
namespace Microsoft.MixedReality.Toolkit.Examples.Demos.EyeTracking
{
/// <summary>
/// This script allows to scroll a texture both horizontally and vertically.
/// </summary>
public class PanZoomRectTransf : PanZoomBaseRectTransf
{
[Tooltip("RectTransform from, for example, your TextMeshPro game object.")]
[SerializeField]
private RectTransform rectTransfToNavigate = null;
[Tooltip("Reference to the viewport restricting the viewbox. This is important for identifying the max constrains for panning.")]
[SerializeField]
private RectTransform refToViewPort = null;
// Zoom
[Tooltip("Zoom acceleration defining the steepness of logistic speed function mapping.")]
[SerializeField]
private float zoomAcceleration = 10f;
[Tooltip("Maximum zoom speed.")]
[SerializeField]
private float zoomSpeedMax = 0.02f;
[Tooltip("Minimum scale of the texture for zoom in - e.g., 0.5f (half the original size)")]
[SerializeField]
private float zoomMinScale = 0.1f;
[Tooltip("Maximum scale of the texture for zoom out - e.g., 1f (the original size) or 2.0f (double the original size).")]
[SerializeField]
private float zoomMaxScale = 1.0f;
[Tooltip("Timed zoom: Once triggered, a zoom in/out will be performed for the given amount of time in seconds.")]
[SerializeField]
private float zoomTimeInSecToZoom = 0.5f;
[Tooltip("Enable or disable hand gestures for zooming on startup.")]
[SerializeField]
private bool zoomGestureEnabledOnStartup = false;
// Pan
[Tooltip("Ability to scroll using your eye gaze without any additional input (e.g., air tap or button presses).")]
[SerializeField]
private bool panAutoScrollIsActive = true;
[Tooltip("Horizontal scroll speed. For example: 0.1f for slow panning. 0.6f for fast panning.")]
[SerializeField]
private float panSpeedHorizontal = 0.3f;
[Tooltip("Vertical scroll speed. For example: 0.1f for slow panning. 0.6f for fast panning.")]
[SerializeField]
private float panSpeedVertical = 0.3f;
[Tooltip("Minimal distance in x and y from center of the target's hit box (0, 0) to scroll. Thus, values must range between 0 (always scroll) and 0.5 (no scroll).")]
[SerializeField]
private Vector2 panMinDistFromCenter = new Vector2(0.2f, 0.2f);
[Tooltip("Set to true to prevent sudden scrolling when quickly looking around. This may make scrolling feel less responsive though.")]
[SerializeField]
private bool useSkimProofing = false;
[Tooltip("The lower the value, the slower the scrolling will speed up after skimming. Recommended value: 5.")]
[SerializeField]
[Range(0, 10)]
private float skimProofUpdateSpeed = 5f;
protected override void Start()
{
// Assigning values to base PanZoom class
// Zoom
ZoomAcceleration = zoomAcceleration;
ZoomSpeedMax = zoomSpeedMax;
ZoomMinScale = zoomMinScale;
ZoomMaxScale = zoomMaxScale;
ZoomGestureEnabledOnStartup = zoomGestureEnabledOnStartup;
timeInSecondsToZoom = zoomTimeInSecToZoom;
// Pan
autoGazePanIsActive = panAutoScrollIsActive;
panSpeedLeftRight = panSpeedHorizontal;
panSpeedUpDown = panSpeedVertical;
minDistFromCenterForAutoPan = panMinDistFromCenter;
useSkimProof = useSkimProofing;
// Set up rect transform
viewportRectTransf = refToViewPort;
navRectTransf = rectTransfToNavigate;
navRectTransf.anchorMin = new Vector2(0.5f, 0.5f);
navRectTransf.anchorMax = new Vector2(0.5f, 0.5f);
navRectTransf.pivot = new Vector2(0.5f, 0.5f);
base.Start();
}
protected override void Update()
{
UpdateValues(ref navRectTransf, rectTransfToNavigate);
UpdateValues(ref ZoomAcceleration, zoomAcceleration);
UpdateValues(ref ZoomSpeedMax, zoomSpeedMax);
UpdateValues(ref ZoomMinScale, zoomMinScale);
UpdateValues(ref ZoomMaxScale, zoomMaxScale);
UpdateValues(ref timeInSecondsToZoom, zoomTimeInSecToZoom);
UpdateValues(ref autoGazePanIsActive, panAutoScrollIsActive);
UpdateValues(ref panSpeedLeftRight, panSpeedHorizontal);
UpdateValues(ref panSpeedUpDown, panSpeedVertical);
UpdateValues(ref minDistFromCenterForAutoPan, panMinDistFromCenter);
UpdateValues(ref useSkimProof, useSkimProofing);
if (UpdateValues(ref skimproof_UpdateSpeedFromUser, skimProofUpdateSpeed))
{
SetSkimProofUpdateSpeed(skimproof_UpdateSpeedFromUser);
}
base.Update();
}
}
}