-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hold2ChangeSAC.cs
296 lines (212 loc) · 8.03 KB
/
Hold2ChangeSAC.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using HoloToolkit.Unity.InputModule;
using System;
using UnityEngine.UI;
public class Hold2ChangeSAC : MonoBehaviour, IInputHandler, IInputClickHandler, IFocusable, IManipulationHandler
{
public float Speed = 10;
public int size_counter = 3;
[Tooltip("Speed at which the object is resized.")]
[SerializeField]
float ResizeSpeedFactor = 1.5f;
[SerializeField]
float ResizeScaleFactor = 1.5f;
[Tooltip("When warp is checked, we allow resizing of all three scale axes - otherwise we scale each axis by the same amount.")]
[SerializeField]
bool AllowResizeWarp = false;
[Tooltip("Minimum resize scale allowed.")]
[SerializeField]
float MinScale = 0.3f;
[Tooltip("Maximum resize scale allowed.")]
[SerializeField]
float MaxScale = 4f;
[SerializeField]
bool resizingEnabled = true;
Vector3 lastScale;
[SerializeField]
float DragSpeed = 1.5f;
[SerializeField]
float DragScale = 1.5f;
[SerializeField]
float MaxDragDistance = 3f;
Vector3 lastPosition;
public void SetResizing(bool enabled)
{
resizingEnabled = enabled;
}
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void OnManipulationStarted(ManipulationEventData eventData)
{
Debug.LogFormat("OnManipulation Started\r\nSource: {0} SourceId: {1}\r\nCumulativeDelta: {2} {3} {4}",
eventData.InputSource,
eventData.SourceId,
eventData.CumulativeDelta.x,
eventData.CumulativeDelta.y,
eventData.CumulativeDelta.z);
log("started");
this.GetComponent<Renderer>().material.color = Color.green;
InputManager.Instance.PushModalInputHandler(gameObject);
lastScale = transform.parent.transform.localScale;
lastPosition = transform.position;
}
public void OnManipulationUpdated(ManipulationEventData eventData)
{
if (resizingEnabled)
{
changeSAC(eventData.CumulativeDelta);
//sharing & messaging
//SharingMessages.Instance.SendResizing(Id, eventData.CumulativeDelta);
}
}
public void OnInputClicked(InputEventData eventData)
{
////throw new NotImplementedException();
//size_counter++;
//if (size_counter > 5) size_counter = 1;
//switch (size_counter)
//{
// case 1:
// transform.parent.transform.localScale = new Vector3(0.4f, 0.4f, 0.4f);
// break;
// case 2:
// transform.parent.transform.localScale = new Vector3(0.7f, 0.7f, 0.7f);
// break;
// case 3:
// transform.parent.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
// break;
// case 4:
// transform.parent.transform.localScale = new Vector3(1.3f, 1.3f, 1.3f);
// break;
// case 5:
// transform.parent.transform.localScale = new Vector3(1.6f, 1.6f, 1.6f);
// break;
//}
// click on front bottom right cube
if (gameObject.name == "A-Axial")
{
}
//// click on back top left cube
else if (gameObject.name == "P-Axial")
{
}
log("clicked");
}
void changeSAC(Vector3 positon)
{
//float resizeX, resizeY, resizeZ;
////if we are warping, honor axis delta, else take the x
//if (AllowResizeWarp)
//{
// resizeX = newScale.x * ResizeScaleFactor;
// resizeY = newScale.y * ResizeScaleFactor;
// resizeZ = newScale.z * ResizeScaleFactor;
//}
//else
//{
// resizeX = resizeY = resizeZ = newScale.x * ResizeScaleFactor;
//}
//resizeX = Mathf.Clamp(lastScale.x + resizeX, MinScale, MaxScale);
//resizeY = Mathf.Clamp(lastScale.y + resizeY, MinScale, MaxScale);
//resizeZ = Mathf.Clamp(lastScale.z + resizeZ, MinScale, MaxScale);
//transform.parent.transform.localScale = Vector3.Lerp(transform.localScale,
// new Vector3(resizeX, resizeY, resizeZ),
// ResizeSpeedFactor);
// drag on front bottom right cube
if (gameObject.name == "A-Axial")
{
var targetPosition = lastPosition + positon * DragScale;
if (Vector3.Distance(lastPosition, targetPosition) <= MaxDragDistance)
{
transform.position = Vector3.Lerp(transform.position, targetPosition, DragSpeed);
}
}
// drag on back top left cibe
else if (gameObject.name == "P-Axial")
{
var targetPosition = lastPosition + positon * DragScale;
if (Vector3.Distance(lastPosition, targetPosition) <= MaxDragDistance)
{
transform.position = Vector3.Lerp(transform.position, targetPosition, DragSpeed);
}
}
}
public void OnManipulationCompleted(ManipulationEventData eventData)
{
Debug.LogFormat("OnManipulation Completed\r\nSource: {0} SourceId: {1}\r\nCumulativeDelta: {2} {3} {4}",
eventData.InputSource,
eventData.SourceId,
eventData.CumulativeDelta.x,
eventData.CumulativeDelta.y,
eventData.CumulativeDelta.z);
log("completed");
this.GetComponent<Renderer>().material.color = Color.white;
InputManager.Instance.PopModalInputHandler();
}
public void OnManipulationCanceled(ManipulationEventData eventData)
{
Debug.LogFormat("OnManipulation Canceled\r\nSource: {0} SourceId: {1}\r\nCumulativeDelta: {2} {3} {4}",
eventData.InputSource,
eventData.SourceId,
eventData.CumulativeDelta.x,
eventData.CumulativeDelta.y,
eventData.CumulativeDelta.z);
log("canceled");
this.GetComponent<Renderer>().material.color = Color.white;
InputManager.Instance.PopModalInputHandler();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void OnInputUp(InputEventData eventData)
{
Debug.LogFormat("OnInputUp Source: {0} SourceId: {1}", eventData.InputSource, eventData.SourceId);
}
public void OnInputDown(InputEventData eventData)
{
Debug.LogFormat("OnInputDown Source: {0} SourceId: {1}", eventData.InputSource, eventData.SourceId);
}
public void OnFocusEnter()
{
Debug.Log("OnFocusEnter");
}
public void OnFocusExit()
{
Debug.Log("OnFocusExit");
}
public void OnSourceDetected(SourceStateEventData eventData)
{
Debug.LogFormat("OnSourceDetected Source: {0} SourceId: {1}", eventData.InputSource, eventData.SourceId);
}
public void OnSourceLost(SourceStateEventData eventData)
{
Debug.LogFormat("OnSourceLost Source: {0} SourceId: {1}", eventData.InputSource, eventData.SourceId);
}
public void OnHoldStarted(HoldEventData eventData)
{
Debug.LogFormat("OnHoldStarted n Source: {0} SourceId: {1}", eventData.InputSource, eventData.SourceId);
}
public void OnHoldCompleted(HoldEventData eventData)
{
Debug.LogFormat("OnHoldCompleted n Source: {0} SourceId: {1}", eventData.InputSource, eventData.SourceId);
}
public void OnHoldCanceled(HoldEventData eventData)
{
Debug.LogFormat("OnHoldCanceled n Source: {0} SourceId: {1}", eventData.InputSource, eventData.SourceId);
}
public void OnSpeechKeywordRecognized(SpeechKeywordRecognizedEventData eventData)
{
Debug.Log(eventData.RecognizedText.ToLower());
}
public void log(string str)
{
//GameObject.Find("StatusTxt").GetComponent<TextMesh>().text += str.ToString() + " \n ";
GameObject.Find("StatusTxt").GetComponent<Text>().text = str.ToString() + " \n ";
}
}