Tanoda
PositionAction.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Globalization;
5using System.Linq;
6using System.Runtime.Serialization;
7using GILES;
8using JetBrains.Annotations;
9using NaughtyAttributes;
10using UnityEngine;
11using UnityEngine.UI;
12using Object = UnityEngine.Object;
15#if !UNITY_WEBGL
16using Valve.VR.InteractionSystem;
17
18#endif
19public class PositionAction : ActionObject, ISerializable
20{
21 public InputField[] posInputs = new InputField[3];
22 public InputField[] rotInputs = new InputField[3];
23 public InputField toleranceField, taktTimeInput;
25 internal Vector3 fixedOriginalPosition, fixedOriginalRotation, fixedTargetRotation, fixedTargetPosition;
27 internal float tolerance = 0.05f;
28 internal bool activated;
29 internal bool forceno = false;
30 protected float chill;
31 private bool triggerOnce = true;
32 protected bool canReturnNow;
33 private bool deactivated;
34 private bool jobsDone;
35 private Coroutine mouseOver, mouseOver2;
36
37 internal GameObject cachedGO;
38 protected List<Transform> allSame;
40 protected GameObject followGo;
42
43 internal bool HasHighlight = false;
44 internal bool HasSelectedHighlight = false;
45
46#if DANA
47 public Dropdown dropDown;
48 public GameObject selectButton;
49 internal bool isLocal = false;
50 private GameObject canvasSelector;
51 public string canvasSelectorName = "Canvas_selector";
52 private GameObject canvasHierarchy;
53 private GameObject canvas;
54 public string selectedHash = "";
55 private Transform originalParent;
56 [SerializeField] internal GameObject selectedGO;
57#endif
58 private OffsetHolder offsetHolder;
59 private GameObject handPrefab, leftHandPrefab;
60 private GameObject handInstance;
61 private GameObject objectToGrab;
62 private Transform attachPoint;
63 private bool editingLeft = false;
64 private List<GameObject> modifiedCollisions = new List<GameObject>();
65 private List<Collider> modifiedColliders = new List<Collider>();
66 [SerializeField] internal bool oneHanded = true;
67 public Toggle HandToggle;
68 private GameObjectAction gameObjectActionRefference;
69
70 private Vector3[] origOHvalues;
71 private bool ogSaved = false;
72
73 public override void Triggered(string id)
74 {
75#if !UNITY_WEBGL
76 if (deactivated)
77 return;
78 triggerOnce = true;
79 base.Triggered(id);
80
81
82 if (id != GetInput())
83 {
85 var action = Controller.Instance.GetActionByInOut(connection.fromId);
86 if (action is GameObjectAction objectAction)
87 {
88 objectAction.IfTrigger(id);
89 }
90 activated = true;
91 if (!cachedGO) cachedGO = GetInputGO();
92 fixedOriginalPosition = cachedGO.transform.position;
93 fixedOriginalRotation = cachedGO.transform.eulerAngles;
94 if (cachedGO && oneHanded)
95 {
96 Destroy(cachedGO.GetComponent<TwoHandGrab>());
97 }
98 if (cachedGO && !oneHanded)
99 {
100 cachedGO.DemandComponent<TwoHandGrab>();
101 }
102 if (cachedGO) SetAsIntaractable();
103
104 if (cachedGO && cachedGO.GetComponent<ThrowableCanDisable>())
105 {
106 var tcd = cachedGO.GetComponent<ThrowableCanDisable>();
107 tcd.enabled = true;
108
109 if (tcd.IsAttachedToHand())
110 {
111
112 return;
113 }
114 }
115#if DANA
116 if (useObjectPositioning)
117 {
118 originalParent = cachedGO.transform.parent;
119 selectedLocalGo = HashingManager.instance.GetGOFromHash(selectedLocalHash);
120 if (selectedLocalGo) SetSelectedAsIntaractable();
123 if (selectedLocalGo.GetComponent<ThrowableCanDisable>())
124 {
125 var tcdLocal = selectedLocalGo.GetComponent<ThrowableCanDisable>();
126 tcdLocal.enabled = true;
127 }
128 }
129#endif
130
131 if(GetHandOffsets(out var o, out var r, out var lo, out var lr))
132 {
133 var oh = cachedGO.GetComponent<OffsetHolder>();
134 origOHvalues = new[] { oh.Offset, oh.Rotation, oh.LeftOffset, oh.LeftRotation };
135 oh.Offset = o;
136 oh.Rotation = r;
137 oh.LeftOffset = lo;
138 oh.LeftRotation = lr;
139 ogSaved = true;
140 }
141
142
143 if (!highlightCurrentObject && !jobsDone)
144 {
145 StartCoroutine(ShowHighLightCurrent());
146#if DANA
147 if (useObjectPositioning) StartCoroutine(ShowHighLightSelectedCurrent());
148#endif
149 }
150
151 //StartCoroutine(ShowHighLight());
152 }
153#endif
154 }
155
156 public override void Deactivate()
157 {
158 base.Deactivate();
159 deactivated = true;
161 }
162 private new void OnDestroy()
163 {
164 Destroy(highlightObject);
165 base.OnDestroy();
166 }
167
168 public void Reactivate()
169 {
170 deactivated = false;
171 chill = 0.1f;
172 jobsDone = false;
173 }
174
175 private void SetAsIntaractable()
176 {
177 var isStatic = cachedGO.GetComponent<StaticGO>();
178 var isImage = cachedGO.GetComponent<RawImage>();
179 var hasRigidbody = cachedGO.GetComponent<Rigidbody>();
180 var hasOffsetter = cachedGO.GetComponent<OffsetHolder>();
181#if !UNITY_WEBGL
182 var hasInteractable = cachedGO.GetComponent<Interactable>();
183 var hasThrowable = cachedGO.GetComponent<ThrowableCanDisable>();
184
185#endif
186 if (isStatic) Destroy(isStatic);
187
188 if (!hasRigidbody) cachedGO.AddComponent<Rigidbody>().isKinematic = true;
189 if (!hasOffsetter) cachedGO.AddComponent<OffsetHolder>();
190
191#if !UNITY_WEBGL
192 if (!hasInteractable) cachedGO.AddComponent<Interactable>();
193
194 if (!hasThrowable) cachedGO.AddComponent<ThrowableCanDisable>();
195
196 if (isImage) cachedGO.AddComponent<BoxCollider>();
197 Macro.allActiveTCD.Add(cachedGO.GetComponent<ThrowableCanDisable>());
198 //Macro.cacheAllTCD();
199#endif
200 }
201
202 private void SetSelectedAsIntaractable()
203 {
204 var isStatic = selectedLocalGo.GetComponent<StaticGO>();
205 var isImage = selectedLocalGo.GetComponent<RawImage>();
206 var hasRigidbody = selectedLocalGo.GetComponent<Rigidbody>();
207 var hasOffsetter = selectedLocalGo.GetComponent<OffsetHolder>();
208#if !UNITY_WEBGL
209 var hasInteractable = selectedLocalGo.GetComponent<Interactable>();
210 var hasThrowable = selectedLocalGo.GetComponent<ThrowableCanDisable>();
211
212#endif
213 if (isStatic) Destroy(isStatic);
214
215 if (!hasRigidbody) selectedLocalGo.AddComponent<Rigidbody>().isKinematic = true;
216 if (!hasOffsetter) selectedLocalGo.AddComponent<OffsetHolder>();
217
218#if !UNITY_WEBGL
219 if (!hasInteractable) selectedLocalGo.AddComponent<Interactable>();
220
221 if (!hasThrowable) selectedLocalGo.AddComponent<ThrowableCanDisable>();
222
223 if (isImage) selectedLocalGo.AddComponent<BoxCollider>();
224 Macro.allActiveTCD.Add(selectedLocalGo.GetComponent<ThrowableCanDisable>());
225#endif
226 }
228 void EnterOffsetEditor()
229 {
230 if (handPrefab == null)
231 {
232 Debug.Log("couldn't find glove, offset editor cannot be entered");
233 return;
234 }
235
236 //objectToGrab = pb_Selection.activeGameObject;
237 if (objectToGrab == null)
238 {
239 Debug.Log("no selected object, offset editor cannot be entered");
240 return;
241 }
242
243 Vector3 scale = objectToGrab.transform.localScale;
244 if (scale.x == 0f || scale.y == 0f || scale.z == 0f)
245 {
246 Debug.Log("object has at least one scale component set to 0, offset editor cannot be entered");
247 return;
248 }
249
250 offsetHolder = objectToGrab.GetComponent<OffsetHolder>();
251 StartCoroutine(SpawnHand());
252 }
253 IEnumerator SpawnHand(bool left = false)
254 {
255 editingLeft = left;
256
257 handInstance = Instantiate(left ? leftHandPrefab : handPrefab, Vector3.zero, new Quaternion(), null);
258 yield return new WaitForEndOfFrame();
259
260 attachPoint = handInstance.transform.Find("AttachPoint");
261 attachPoint.transform.SetParent(null, true);
262 yield return new WaitForEndOfFrame();
263
264 handInstance.transform.SetParent(attachPoint, true);
265 yield return new WaitForEndOfFrame();
266
267 attachPoint.transform.SetParent(objectToGrab.transform, true);
268 yield return new WaitForEndOfFrame();
269
270 attachPoint.transform.localPosition = left ? offsetHolder.LeftOffset : offsetHolder.Offset;
271 attachPoint.transform.localRotation = left ? Quaternion.Euler(offsetHolder.LeftRotation) : Quaternion.Euler(offsetHolder.Rotation);
272 yield return new WaitForEndOfFrame();
273 }
274 protected IEnumerator ShowHighLight(ThrowableCanDisable tcd)
275 {
276 if (highlightObject) Destroy(highlightObject);
277
278 if (MiscLogicManager.instance.mode != MiscLogicManager.CurrentMode.Training && MiscLogicManager.instance.mode != MiscLogicManager.CurrentMode.Optimization) yield break;
279
280 yield return new WaitForEndOfFrame();
281#if !UNITY_WEBGL
282 highlightObject = Instantiate(cachedGO, targetPosition, Quaternion.Euler(targetRotation),
283 cachedGO.transform.parent);
284 highlightObject.transform.localPosition = targetPosition;
285 highlightObject.transform.localEulerAngles = targetRotation;
286#if !UNITY_WEBGL
287 Destroy(highlightObject.GetComponent<ThrowableCanDisable>());
288 //Destroy(highlightObject.GetComponent<TwoHandGrab>());
289 Destroy(highlightObject.GetComponent<Interactable>());
290#endif
291 Destroy(highlightObject.GetComponent<Rigidbody>());
292 var allCollider = highlightObject.GetComponentsInChildren<Collider>();
293 foreach (var coll in allCollider)
294 {
295 Destroy(coll);
296 }
297 if (useObjectPositioning)
298 {
299 if (!selectedLocalGo) selectedLocalGo = HashingManager.instance.GetGOFromHash(selectedLocalHash);
300 highlightObject.transform.SetParent(selectedLocalGo.transform, true);
301 }
302
303 else
304 {
305 if (tcd)
306 {
307 if (!cachedGO.GetComponent<TwoHandGrab>())
308 {
309 highlightObject.transform.SetParent(tcd.GetHand().currentAttachedObjectInfo.Value.originalParent.transform, true);
310 }
311 else
312 {
313 highlightObject.transform.SetParent(tcd.originalParent, true);
314 }
315 }
316
317 }
318
319 yield return new WaitForEndOfFrame();
320
321 if (useObjectPositioning)
322 {
323 highlightObject.transform.localPosition = localpos;
324 highlightObject.transform.localEulerAngles = localrot;
325 }
326 else
327 {
328 highlightObject.transform.SetPositionAndRotation(targetPosition, Quaternion.Euler(targetRotation));
329 highlightObject.transform.localPosition = targetPosition;
330 highlightObject.transform.localEulerAngles = targetRotation;
331 }
332
333 MatChange(highlightObject, true);
334 HasHighlight = true;
335#endif
336 }
337
339 {
341
342 if (MiscLogicManager.instance.mode != MiscLogicManager.CurrentMode.Training && MiscLogicManager.instance.mode != MiscLogicManager.CurrentMode.Optimization) yield break;
343
344 yield return new WaitForEndOfFrame();
345#if !UNITY_WEBGL
346 highlightSelected = Instantiate(selectedLocalGo, targetPosition, Quaternion.Euler(targetRotation),
347 selectedLocalGo.transform.parent);
348 highlightSelected.transform.localPosition = targetPosition;
349 highlightSelected.transform.localEulerAngles = targetRotation;
350#if !UNITY_WEBGL
351 Destroy(highlightSelected.GetComponent<ThrowableCanDisable>());
352 //Destroy(highlightObject.GetComponent<TwoHandGrab>());
353 Destroy(highlightSelected.GetComponent<Interactable>());
354#endif
355 Destroy(highlightSelected.GetComponent<Rigidbody>());
356 var allCollider = highlightSelected.GetComponentsInChildren<Collider>();
357 foreach (var coll in allCollider)
358 {
359 Destroy(coll);
360 }
361 //if (useObjectPositioning)
362 // highlightSelected.transform.SetParent(selectedLocalGo.transform, true);
363 //else
364 //{
365 if (tcd)
366 {
367 if (!selectedLocalGo.GetComponent<TwoHandGrab>())
368 {
369 highlightSelected.transform.SetParent(tcd.GetHand().currentAttachedObjectInfo.Value.originalParent.transform, true);
370 }
371 else
372 {
373 highlightSelected.transform.SetParent(tcd.originalParent, true);
374 }
375 }
376
377 //}
378
379 yield return new WaitForEndOfFrame();
380
381
382 MatChange(highlightSelected, true);
383 HasSelectedHighlight = true;
384#endif
385 }
386 protected IEnumerator ShowHighLightOptimization()
387 {
388 if (highlightObject) Destroy(highlightObject);
389
390 if (MiscLogicManager.instance.mode != MiscLogicManager.CurrentMode.Training && MiscLogicManager.instance.mode != MiscLogicManager.CurrentMode.Optimization) yield break;
391
392 yield return new WaitForEndOfFrame();
393 fixedTargetPosition = pb_Scene.instance.transform.TransformPoint(targetPosition);
394 fixedTargetRotation = cachedGO.transform.parent.eulerAngles + targetRotation;
395#if !UNITY_WEBGL
396 highlightObject = Instantiate(cachedGO, fixedTargetPosition, Quaternion.Euler(fixedTargetRotation),
397 cachedGO.transform.parent);
398 highlightObject.transform.position = fixedTargetPosition;
399 highlightObject.transform.eulerAngles = fixedTargetRotation;
400 highlightObject.SetActive(true);
401#if !UNITY_WEBGL
402 Destroy(highlightObject.GetComponent<ThrowableCanDisable>());
403 //Destroy(highlightObject.GetComponent<TwoHandGrab>());
404 Destroy(highlightObject.GetComponent<Interactable>());
405#endif
406 Destroy(highlightObject.GetComponent<Rigidbody>());
407 var allCollider = highlightObject.GetComponentsInChildren<Collider>();
408 foreach (var coll in allCollider)
409 {
410 Destroy(coll);
411 }
412 //if (useObjectPositioning)
413 // highlightObject.transform.SetParent(selectedLocalGo.transform, true);
414 //else
415 //{
416 // highlightObject.transform.SetParent(cachedGO.transform.parent, true);
417 //}
418
419 yield return new WaitForEndOfFrame();
420
421 if (useObjectPositioning)
422 {
423 highlightObject.transform.localPosition = localpos;
424 highlightObject.transform.localEulerAngles = localrot;
425 }
426 else
427 {
428 highlightObject.transform.SetPositionAndRotation(fixedTargetPosition, Quaternion.Euler(fixedTargetRotation));
429 highlightObject.transform.position = fixedTargetPosition;
430 highlightObject.transform.eulerAngles = fixedTargetRotation;
431 }
432
433 MatChange(highlightObject, true);
434 HasHighlight = true;
435#endif
436 }
437 private IEnumerator ShowHighLightCurrent()
438 {
439 if (!cachedGO) yield break;
440
441 if (MiscLogicManager.instance.mode != MiscLogicManager.CurrentMode.Training && MiscLogicManager.instance.mode != MiscLogicManager.CurrentMode.Optimization) yield break;
442
443 yield return new WaitForEndOfFrame();
444
445 if (cachedGO.GetComponent<RawImage>())
446 {
447 var outline = cachedGO.AddComponent<Outline>();
448 outline.effectDistance = new Vector2(0.05f, 0.05f);
449 outline.effectColor = Color.cyan;
450 highlightCurrentObject = outline;
451 //MatChange((GameObject)highlightCurrentObject);
452 }
453 else
454 {
455 highlightCurrentObject = Instantiate(cachedGO, Vector3.up * 100, Quaternion.identity, cachedGO.transform);
456 ((GameObject)highlightCurrentObject).SetActive(false);
457 //((GameObject)highlightCurrentObject).transform.SetParent(cachedGO.transform, true);
458#if !UNITY_WEBGL
459 Destroy(((GameObject)highlightCurrentObject).GetComponent<ThrowableCanDisable>());
460 //Destroy(((GameObject)highlightCurrentObject).GetComponent<TwoHandGrab>());
461 Destroy(((GameObject)highlightCurrentObject).GetComponent<Interactable>());
462#endif
463 Destroy(((GameObject)highlightCurrentObject).GetComponent<Rigidbody>());
464 Destroy(((GameObject)highlightCurrentObject).GetComponent<Collider>());
465 Destroy(((GameObject)highlightCurrentObject).GetComponentInChildren<Collider>());
466 var allCollider = ((GameObject)highlightCurrentObject).GetComponentsInChildren<Collider>();
467 foreach (var coll in allCollider)
468 {
469 Destroy(coll);
470 }
471
472 yield return null;
473
475 {
476 ((GameObject)highlightCurrentObject).transform.localPosition = Vector3.zero;
477 ((GameObject)highlightCurrentObject).transform.localEulerAngles = Vector3.zero;
478 ((GameObject)highlightCurrentObject).transform.localScale *= 1.001f;
479 ((GameObject)highlightCurrentObject).SetActive(true);
480
481 MatChange((GameObject)highlightCurrentObject);
482 }
483
484 }
485 objectToGrab = cachedGO;
486 //EnterOffsetEditor();
488 {
489#if !UNITY_WEBGL
491 FollowMe.Instance?.StartFollowing(cachedGO.transform.position, cachedGO);
492#endif
493 }
494
495 }
496
497 private IEnumerator ShowHighLightSelectedCurrent()
498 {
499 if (!selectedLocalGo) yield break;
500
501 if (MiscLogicManager.instance.mode != MiscLogicManager.CurrentMode.Training && MiscLogicManager.instance.mode != MiscLogicManager.CurrentMode.Optimization) yield break;
502
503 yield return new WaitForEndOfFrame();
504
505 if (selectedLocalGo.GetComponent<RawImage>())
506 {
507 var outline = selectedLocalGo.AddComponent<Outline>();
508 outline.effectDistance = new Vector2(0.05f, 0.05f);
509 outline.effectColor = Color.cyan;
511 //MatChange((GameObject)highlightCurrentObject);
512 }
513 else
514 {
515 highlightCurrentSelectedObject = Instantiate(selectedLocalGo, Vector3.up * 100, Quaternion.identity);
516 ((GameObject)highlightCurrentSelectedObject).SetActive(false);
517 ((GameObject)highlightCurrentSelectedObject).transform.SetParent(selectedLocalGo.transform, true);
518#if !UNITY_WEBGL
519 Destroy(((GameObject)highlightCurrentSelectedObject).GetComponent<ThrowableCanDisable>());
520 //Destroy(((GameObject)highlightCurrentObject).GetComponent<TwoHandGrab>());
521 Destroy(((GameObject)highlightCurrentSelectedObject).GetComponent<Interactable>());
522#endif
523 Destroy(((GameObject)highlightCurrentSelectedObject).GetComponent<Rigidbody>());
524 Destroy(((GameObject)highlightCurrentSelectedObject).GetComponent<Collider>());
525 Destroy(((GameObject)highlightCurrentSelectedObject).GetComponentInChildren<Collider>());
526 var allCollider = ((GameObject)highlightCurrentSelectedObject).GetComponentsInChildren<Collider>();
527 foreach (var coll in allCollider)
528 {
529 Destroy(coll);
530 }
531
532 yield return new WaitForEndOfFrame();
533
535 {
536 ((GameObject)highlightCurrentSelectedObject).transform.localPosition = Vector3.zero;
537 ((GameObject)highlightCurrentSelectedObject).transform.localEulerAngles = Vector3.zero;
538 ((GameObject)highlightCurrentSelectedObject).transform.localScale *= 1.001f;
539 ((GameObject)highlightCurrentSelectedObject).SetActive(true);
540
541 MatChange((GameObject)highlightCurrentSelectedObject);
542 }
543
544 }
545 objectToGrab = cachedGO;
546 HasSelectedHighlight = true;
547 //EnterOffsetEditor();
548 // if (MiscLogicManager.instance.mode == MiscLogicManager.CurrentMode.Training || MiscLogicManager.instance.mode == MiscLogicManager.CurrentMode.Optimization)
549 // {
550 //#if !UNITY_WEBGL
551 // PreviewHand.Instance?.EnterOffsetEditor(selectedLocalGo, action, targetPosition, targetRotation);
552 // FollowMe.Instance?.StartFollowing(selectedLocalGo.transform.position, selectedLocalGo);
553 //#endif
554 // }
555
556 }
557
558 protected IEnumerator ShowHighLightOriginal()
559 {
560 if (highlightObject) Destroy(highlightObject);
561
562 if (MiscLogicManager.instance.mode != MiscLogicManager.CurrentMode.Training && MiscLogicManager.instance.mode != MiscLogicManager.CurrentMode.Optimization) yield break;
563
564 yield return new WaitForEndOfFrame();
565
566 highlightObject = Instantiate(cachedGO, originalPosition, Quaternion.Euler(originalRotation),
567 pb_Scene.instance.transform);
568 highlightObject.transform.localPosition = originalPosition;
569 highlightObject.transform.localEulerAngles = originalRotation;
570#if !UNITY_WEBGL
571 Destroy(highlightObject.GetComponent<ThrowableCanDisable>());
572 //Destroy(highlightObject.GetComponent<TwoHandGrab>());
573 Destroy(highlightObject.GetComponent<Interactable>());
574#endif
575 Destroy(highlightObject.GetComponent<Rigidbody>());
576 //Destroy(highlightObject.GetComponent<Collider>());
577 var allCollider = highlightObject.GetComponentsInChildren<Collider>();
578 foreach (var coll in allCollider)
579 {
580 Destroy(coll);
581 }
582
583 yield return new WaitForEndOfFrame();
584
585 highlightObject.transform.SetPositionAndRotation(originalPosition, Quaternion.Euler(originalRotation));
586 highlightObject.transform.localPosition = originalPosition;
587 highlightObject.transform.localEulerAngles = originalRotation;
588
589 MatChange(highlightObject);
590 HasHighlight = true;
591 }
592
593 protected IEnumerator ShowHighLightOriginalOptimization()
594 {
595 //if (highlightObject) Destroy(highlightObject);
596
597 if (MiscLogicManager.instance.mode != MiscLogicManager.CurrentMode.Training && MiscLogicManager.instance.mode != MiscLogicManager.CurrentMode.Optimization) yield break;
598
599 yield return new WaitForEndOfFrame();
600 if (fixedOriginalPosition == null)
601 {
602
603 highlightObjectOriginal = Instantiate(cachedGO, originalPosition, Quaternion.Euler(originalRotation), cachedGO.transform.parent);
604 highlightObjectOriginal.transform.localPosition = originalPosition;
605 highlightObjectOriginal.transform.localEulerAngles = originalRotation;
606 }
607 else
608 {
609 highlightObjectOriginal = Instantiate(cachedGO, fixedOriginalPosition, Quaternion.Euler(fixedOriginalRotation),
610 cachedGO.transform.parent);
611 highlightObjectOriginal.transform.position = fixedOriginalPosition;
612 highlightObjectOriginal.transform.eulerAngles = fixedOriginalRotation;
613 }
614 highlightObjectOriginal.SetActive(true);
615
616#if !UNITY_WEBGL
617 Destroy(highlightObjectOriginal.GetComponent<ThrowableCanDisable>());
618 //Destroy(highlightObject.GetComponent<TwoHandGrab>());
619 Destroy(highlightObjectOriginal.GetComponent<Interactable>());
620#endif
621 Destroy(highlightObjectOriginal.GetComponent<Rigidbody>());
622 //Destroy(highlightObject.GetComponent<Collider>());
623 var allCollider = highlightObjectOriginal.GetComponentsInChildren<Collider>();
624 foreach (var coll in allCollider)
625 {
626 Destroy(coll);
627 }
628 if (useObjectPositioning)
629 highlightObjectOriginal.transform.SetParent(selectedLocalGo.transform, true);
630 else
631 {
632 highlightObjectOriginal.transform.SetParent(cachedGO.transform.parent, true);
633 }
634 yield return new WaitForEndOfFrame();
635
636 if (fixedOriginalPosition == null)
637 {
638 highlightObjectOriginal.transform.SetPositionAndRotation(originalPosition, Quaternion.Euler(originalRotation));
639 highlightObjectOriginal.transform.localPosition = originalPosition;
640 highlightObjectOriginal.transform.localEulerAngles = originalRotation;
641 }
642 else
643 {
644 highlightObjectOriginal.transform.SetPositionAndRotation(fixedOriginalPosition, Quaternion.Euler(fixedOriginalRotation));
645 highlightObjectOriginal.transform.position = fixedOriginalPosition;
646 highlightObjectOriginal.transform.eulerAngles = fixedOriginalRotation;
647 }
648
649
650 MatChange(highlightObjectOriginal);
651 HasHighlight = true;
652 }
653 protected void RemoveHighlight()
654 {
655 //StopCoroutine(ShowHighLight());
656 if (highlightObject) Destroy(highlightObject);
657 HasHighlight = false;
658
659 SetupCollisions(true);
660 SetupCollisionsV2(true);
661
662 }
663 protected void RemoveSelectedHighlight()
664 {
665 //StopCoroutine(ShowHighLight());
667
668
669 }
671 private void MatChange(GameObject go, bool changeMat = false)
672 {
673 var mrs = go.GetComponentsInChildren<MeshRenderer>();
674 var image = go.GetComponent<RawImage>();
675 if (image)
676 {
677 image.material = imageHighlight;
678 }
679
680 foreach (var meshRenderer in mrs)
681 {
682 var list = new List<Material>();
683 for (var i = 0; i < meshRenderer.materials.Length; i++) list.Add(changeMat ? originalHighlightMat : highlightMaterial);
684 meshRenderer.materials = list.ToArray();
685
686 }
687 }
688
689 public override void InputAdded(string id)
690 {
691 cachedGO = GetInputGO();
692 }
693
694 public void StartPosition()
695 {
696 if (!cachedGO)
697 cachedGO = GetInputGO();
698
699 if (cachedGO)
700 {
701#if DANA
702 if (useObjectPositioning)
703 {
704 if (originalParent) cachedGO.transform.SetParent(originalParent, true);
705 else cachedGO.transform.SetParent(pb_Scene.instance.transform);
706 }
707#endif
708 cachedGO.transform.localPosition = originalPosition;
709 cachedGO.transform.localEulerAngles = originalRotation;
710 }
711 }
712
713 public void FinalPosition()
714 {
715 if (!cachedGO)
716 cachedGO = GetInputGO();
717
718 if (cachedGO)
719 {
720#if DANA
721 if (useObjectPositioning)
722 {
723 originalParent = cachedGO.transform.parent;
724 if (!selectedLocalGo) selectedLocalGo = HashingManager.instance.GetGOFromHash(selectedLocalHash);
725 cachedGO.transform.SetParent(selectedLocalGo.transform, true);
726 }
727#endif
728 cachedGO.transform.localPosition = targetPosition;
729 cachedGO.transform.localEulerAngles = targetRotation;
730
731 }
732 }
733
734 public override void Start()
735 {
736 base.Start();
737 if (tolerance == 0)
738 tolerance = 0.05f;
739 //if (!cachedGO) cachedGO = GetInputGO();
740 //iris = GameObject.Find("iris_position_helper").transform;
741
742 handPrefab = Resources.Load("OffsetEditorHandAnim") as GameObject;
743 leftHandPrefab = Resources.Load("OffsetEditorLeftHand") as GameObject;
744 }
745 public override void OnPointerEnter(PointerEventData eventData)
746 {
747 if (!cachedGO) cachedGO = GetInputGO();
748
749 if (MiscLogicManager.instance.mode == MiscLogicManager.CurrentMode.Optimization && !SavedUser.instance.isEditor)
750 {
751 mouseOver = StartCoroutine(ShowHighLightOptimization());
752 mouseOver2 = StartCoroutine(ShowHighLightOriginalOptimization());
753 }
754 if (SavedUser.instance.isEditor && cachedGO)
755 {
756 mouseOver = StartCoroutine(ShowHighLight(cachedGO.GetComponent<ThrowableCanDisable>()));
757
758 //if (useObjectPositioning)
759 //{
760 // if(!selectedLocalGo) selectedLocalGo = HashingManager.instance.GetGOFromHash(selectedLocalHash);
761 // mouseOver = StartCoroutine(ShowSelectedHighLight(selectedLocalGo.GetComponent<ThrowableCanDisable>()));
762 //}
763 //else
764 //{
765
766 //}
767 }
768
769 }
770 public override void OnPointerExit(PointerEventData eventData)
771 {
772 if (cachedGO && (MiscLogicManager.instance.mode == MiscLogicManager.CurrentMode.Optimization) && !SavedUser.instance.isEditor)
773 {
774 StopCoroutine(mouseOver);
775 StopCoroutine(mouseOver2);
776 Destroy(highlightObject);
778#if !UNITY_WEBGL
780#endif
781 }
782 if (cachedGO && (SavedUser.instance.isEditor))
783 {
784 StopCoroutine(mouseOver);
785 Destroy(highlightObject);
786 Destroy(highlightSelected);
787#if !UNITY_WEBGL
789#endif
790 }
791 }
792
794 {
795 if (!cachedGO) cachedGO = GetInputGO();
796 if (!cachedGO) return;
797
798 posInputs[0].text = cachedGO.transform.localPosition[0].ToString("F5");
799 posInputs[1].text = cachedGO.transform.localPosition[1].ToString("F5");
800 posInputs[2].text = cachedGO.transform.localPosition[2].ToString("F5");
801
802
803 rotInputs[0].text = cachedGO.transform.localEulerAngles[0].ToString("F3");
804 rotInputs[1].text = cachedGO.transform.localEulerAngles[1].ToString("F3");
805 rotInputs[2].text = cachedGO.transform.localEulerAngles[2].ToString("F3");
806
807 onPosChanged("");
808 onRotChanged("");
809 }
810
812 internal bool useObjectPositioning = false;
813 private GameObject selectedLocalGo;
814 internal string selectedLocalHash;
815
816 [Button]
818 {
819 if (!cachedGO) cachedGO = GetInputGO();
820 if (!cachedGO) return;
821
823 selectedLocalGo = go;
824
825 if (go == null)
826 {
827 useObjectPositioning = false;
828 selectedLocalHash = "";
829 Debug.Log("clearing useObjectPositioning flag");
830 return;
831 }
832
833 selectedLocalHash = go.GetComponent<HashHolder>().Hash;
834
835 StartCoroutine(SlowLocalPosSave(go));
836 useObjectPositioning = true;
837
838 }
839
840 private IEnumerator SlowLocalPosSave(GameObject go)
841 {
842 var originalParent = cachedGO.transform.parent;
843 cachedGO.transform.SetParent(go.transform, true);
844 yield return null;
845 localpos = cachedGO.transform.localPosition;
846 fwdoffset = cachedGO.transform.forward;
847 upoffset = cachedGO.transform.up;
848 localrot = cachedGO.transform.localEulerAngles;
849
853
854 cachedGO.transform.SetParent(originalParent, true);
855 }
856
857 [Button]
858 private void SetObjectToPosition()
859 {
860 if (!cachedGO) cachedGO = GetInputGO();
861 if (!cachedGO) return;
862
864
865 var originalParent = go.transform.parent;
866
867 go.transform.SetParent(cachedGO.transform, true);
868
869 go.transform.localPosition = localpos;
870 go.transform.LookAt(go.transform.position + fwdoffset * 1000, go.transform.position + upoffset * 1000);
871
872 go.transform.SetParent(originalParent, true);
873
874 }
875
876 public void onPosChanged(string value)
877 {
878 try
879 {
880 // X
881 var ci = CultureInfo.CurrentCulture;
882 var nfi = ci.NumberFormat;
883 posInputs[0].text = posInputs[0].text.Replace(',', nfi.CurrencyDecimalSeparator[0]);
884 posInputs[0].text = posInputs[0].text.Replace('.', nfi.CurrencyDecimalSeparator[0]);
885 var single = Convert.ToSingle(posInputs[0].text, ci);
886 posInputs[0].text = single.ToString("F3");
887 targetPosition.x = single;
888
889 // Y
890 posInputs[1].text = posInputs[1].text.Replace(',', nfi.CurrencyDecimalSeparator[0]);
891 posInputs[1].text = posInputs[1].text.Replace('.', nfi.CurrencyDecimalSeparator[0]);
892 single = Convert.ToSingle(posInputs[1].text, ci);
893 posInputs[1].text = single.ToString("F3");
894 targetPosition.y = single;
895
896 // Z
897 posInputs[2].text = posInputs[2].text.Replace(',', nfi.CurrencyDecimalSeparator[0]);
898 posInputs[2].text = posInputs[2].text.Replace('.', nfi.CurrencyDecimalSeparator[0]);
899 single = Convert.ToSingle(posInputs[2].text, ci);
900 posInputs[2].text = single.ToString("F3");
901 targetPosition.z = single;
902
903 }
904 catch (Exception)
905 {
906 Debug.LogWarning("not parsable number(?) in Position inputfields!");
907
908 // restore last valid numbers
909 posInputs[0].text = targetPosition[0].ToString("F3");
910 posInputs[1].text = targetPosition[1].ToString("F3");
911 posInputs[2].text = targetPosition[2].ToString("F3");
912 }
913#if DANA
914 if (isLocal)
915 {
916 if (selectedGO)
917 {
918 targetPosition = selectedGO.transform.InverseTransformPoint(targetPosition);
919 }
920
921 }
922#endif
923 }
924
925 public void onRotChanged(string value)
926 {
927 try
928 {
929 // X
930 var ci = CultureInfo.CurrentCulture;
931 var nfi = ci.NumberFormat;
932 rotInputs[0].text = rotInputs[0].text.Replace(',', nfi.CurrencyDecimalSeparator[0]);
933 rotInputs[0].text = rotInputs[0].text.Replace('.', nfi.CurrencyDecimalSeparator[0]);
934 var single = Convert.ToSingle(rotInputs[0].text, ci);
935 rotInputs[0].text = single.ToString("F0");
936 targetRotation.x = single;
937
938 // Y
939 rotInputs[1].text = rotInputs[1].text.Replace(',', nfi.CurrencyDecimalSeparator[0]);
940 rotInputs[1].text = rotInputs[1].text.Replace('.', nfi.CurrencyDecimalSeparator[0]);
941 single = Convert.ToSingle(rotInputs[1].text, ci);
942 rotInputs[1].text = single.ToString("F0");
943 targetRotation.y = single;
944
945 // Z
946 rotInputs[2].text = rotInputs[2].text.Replace(',', nfi.CurrencyDecimalSeparator[0]);
947 rotInputs[2].text = rotInputs[2].text.Replace('.', nfi.CurrencyDecimalSeparator[0]);
948 single = Convert.ToSingle(rotInputs[2].text, ci);
949 rotInputs[2].text = single.ToString("F0");
950 targetRotation.z = single;
951 }
952 catch (Exception)
953 {
954 Debug.LogWarning("not parsable number(?) in Position inputfields!");
955
956 // restore last valid numbers
957 rotInputs[0].text = targetRotation[0].ToString("F0");
958 rotInputs[1].text = targetRotation[1].ToString("F0");
959 rotInputs[2].text = targetRotation[2].ToString("F0");
960 }
961#if DANA
962 if (isLocal)
963 {
964 if (selectedGO)
965 {
966 targetRotation = targetRotation + selectedGO.transform.eulerAngles;
967 }
968
969 }
970#endif
971 }
972
974 {
975 posInputs[0].text = targetPosition[0].ToString("F3");
976 posInputs[1].text = targetPosition[1].ToString("F3");
977 posInputs[2].text = targetPosition[2].ToString("F3");
978
979 rotInputs[0].text = targetRotation[0].ToString("F0");
980 rotInputs[1].text = targetRotation[1].ToString("F0");
981 rotInputs[2].text = targetRotation[2].ToString("F0");
982
983 toleranceField.text = tolerance.ToString("F2");
984 taktTimeInput.text = taktTime.ToString("F2");
985 HandToggle.SetIsOnWithoutNotify(oneHanded);
986 }
987
988 public void onToleranceChanged(string value)
989 {
990 try
991 {
992 // X
993 var ci = CultureInfo.CurrentCulture;
994 var nfi = ci.NumberFormat;
995 toleranceField.text = toleranceField.text.Replace(',', nfi.CurrencyDecimalSeparator[0]);
996 toleranceField.text = toleranceField.text.Replace('.', nfi.CurrencyDecimalSeparator[0]);
997 var single = Convert.ToSingle(toleranceField.text, ci);
998 toleranceField.text = single.ToString("F2");
999 tolerance = single;
1000 }
1001 catch (Exception)
1002 {
1003 Debug.LogWarning("not parsable number(?) in Tolerance inputfields!");
1004
1005 // restore last valid numbers
1006 toleranceField.text = tolerance.ToString("F2");
1007 }
1008 }
1009
1010 public void onTaktTimeChanged(string value)
1011 {
1012 try
1013 {
1014 var ci = CultureInfo.CurrentCulture;
1015 var nfi = ci.NumberFormat;
1016 taktTimeInput.text = taktTimeInput.text.Replace(',', nfi.CurrencyDecimalSeparator[0]);
1017 taktTimeInput.text = taktTimeInput.text.Replace('.', nfi.CurrencyDecimalSeparator[0]);
1018 var single = Convert.ToSingle(taktTimeInput.text, ci);
1019 taktTimeInput.text = single.ToString("F2");
1020 taktTime = single;
1021 taktTime = float.Parse(value, ci);
1022 }
1023 catch (Exception)
1024 {
1025 Debug.LogWarning("not parsable number(?) in holdTime inputfield!");
1026
1027 // restore last valid numbers
1028 taktTimeInput.text = taktTime.ToString("F2");
1029 }
1030 }
1031#if DANA
1032 public void onDropDownChanged(int value)
1033 {
1034 try
1035 {
1036 if (value == 0)
1037 {
1038 selectButton.SetActive(false);
1039 isLocal = false;
1040 }
1041 else
1042 {
1043 selectButton.SetActive(true);
1044 isLocal = true;
1045 }
1046 }
1047 catch (Exception)
1048 {
1049
1050 //exception
1051 }
1052 }
1053
1054 public void TriggerSelection()
1055 {
1056 if (!canvasSelector)
1057 canvasSelector = GameObject.Find(canvasSelectorName);
1058
1059 if (!canvasSelector)
1060 {
1061 Debug.LogError(canvasSelectorName + " not found!");
1062 return;
1063 }
1064
1065 GetComponentInParent<Canvas>().enabled = false;
1066 canvasSelector.transform.GetChild(0).GetComponent<Button>().onClick.AddListener(SetSelectedGO);
1067 canvasSelector.transform.GetChild(1).GetComponent<Button>().onClick.AddListener(CancelSelection);
1068 canvasSelector.GetComponent<Canvas>().enabled = true;
1069 pb_SelectionHandle.instance.SetTool(Tool.None);
1070
1071 canvas = GameObject.Find("Canvas");
1072 if (canvas == null)
1073 {
1074 Debug.LogError("canvas not found!");
1075 return;
1076 }
1077
1078 canvasHierarchy = GameObject.Find("Hierarchy");
1079 if (canvasHierarchy == null)
1080 {
1081 Debug.LogError("Hierarchy not found!");
1082 return;
1083 }
1084
1085 canvasHierarchy.transform.SetParent(canvasSelector.transform, false);
1086 }
1087
1088 public void SetSelectedGO()
1089 {
1090 SetGameObject(pb_Selection.activeGameObject);
1091 canvasSelector.GetComponent<Canvas>().enabled = false;
1092 GetComponentInParent<Canvas>().enabled = true;
1093 canvasSelector.transform.GetChild(0).GetComponent<Button>().onClick.RemoveListener(SetSelectedGO);
1094 canvasSelector.transform.GetChild(1).GetComponent<Button>().onClick.RemoveListener(CancelSelection);
1095
1097
1098 pb_SelectionHandle.instance.SetTool(Tool.Position);
1099
1100 canvasHierarchy.transform.SetParent(canvas.transform, false);
1101 }
1102
1103 public void CancelSelection()
1104 {
1105 canvasSelector.GetComponent<Canvas>().enabled = false;
1106 GetComponentInParent<Canvas>().enabled = true;
1107 canvasSelector.transform.GetChild(0).GetComponent<Button>().onClick.RemoveListener(SetSelectedGO);
1108 canvasSelector.transform.GetChild(1).GetComponent<Button>().onClick.RemoveListener(CancelSelection);
1109
1111
1112 pb_SelectionHandle.instance.SetTool(Tool.Position);
1113
1114 canvasHierarchy.transform.SetParent(canvas.transform, false);
1115 }
1116
1117 public IEnumerator SetGameObjectJob(string hash)
1118 {
1119 if (selectedHash == "")
1120 selectedHash = hash;
1121
1122 yield return new WaitForEndOfFrame();
1123 while (LoadingManager.instance.isLoading) yield return new WaitForEndOfFrame();
1124 SetGameObject(hash);
1125 }
1126
1127 public void SetGameObject(string hash)
1128 {
1129 if (hash == "") return;
1130 selectedGO = HashingManager.instance.GetGOFromHash(hash);
1131 }
1132 public void SetGameObject(GameObject go)
1133 {
1134 selectedGO = go;
1135 }
1136#endif
1137 protected bool InGoodPos(Transform t)
1138 {
1139#if !UNITY_WEBGL
1140 var hh = t.GetComponentInParent<HackedHand>();
1141 if (hh == null) { /*Debug.LogError("HackedHand is NULL!");*/ return false; }
1142
1143 if (!hh.currentAttachedObjectInfo.HasValue) { Debug.LogError("currentAttachedObjectInfo has no value!"); return false; }
1144 if (!hh.currentAttachedObjectInfo.Value.originalParent) { Debug.LogError("originalParent is NULL!"); return false; }
1145
1146
1147
1148 Vector3 local;
1149 if (useObjectPositioning)
1150 {
1151 local = selectedLocalGo.transform.InverseTransformPoint(t.position);
1152 }
1153 else
1154 {
1155 local = hh.currentAttachedObjectInfo.Value.originalParent.transform.InverseTransformPoint(t.position);
1156 }
1157 float modifiedTolerance = 0;
1158 if (useObjectPositioning && selectedLocalGo) modifiedTolerance = Math.Abs(tolerance / selectedLocalGo.transform.localScale.x);
1159 else modifiedTolerance = Math.Abs(tolerance / cachedGO.transform.lossyScale.x);
1160
1161 if (Math.Abs(local.x - targetPosition.x /* + iris.position.x*/) > modifiedTolerance) return false;
1162 if (Math.Abs(local.y - targetPosition.y /* + iris.position.y*/) > modifiedTolerance) return false;
1163 if (Math.Abs(local.z - targetPosition.z /* + iris.position.z*/) > modifiedTolerance) return false;
1164#endif
1165 return true;
1166 }
1167
1168 protected bool InGoodRot(Transform t)
1169 {
1170 return true;
1171 return Quaternion.Angle(t.localRotation, Quaternion.Euler(targetRotation)) < 25;
1172 }
1173
1174 private void GetAllSameGOs()
1175 {
1176 if (!cachedGO/* || allSame != null && allSame.Count > 0*/)
1177 return;
1178
1179 var allTcd = FindObjectsOfType<ThrowableCanDisable>();
1180
1181 var retval = new List<Transform>();
1182
1183 foreach (var tcd in allTcd)
1184 {
1185 if (tcd.name != cachedGO.name)
1186 continue;
1187 if (Math.Abs(tcd.transform.localScale.x - cachedGO.transform.localScale.x) > 0.001f)
1188 continue;
1189 if (Math.Abs(tcd.transform.localScale.y - cachedGO.transform.localScale.y) > 0.001f)
1190 continue;
1191 if (Math.Abs(tcd.transform.localScale.z - cachedGO.transform.localScale.z) > 0.001f)
1192 continue;
1193
1194 retval.Add(tcd.transform);
1195 }
1196
1197 allSame = retval;
1198
1200 //var allPositioner = FindObjectsOfType<PositionAction>();
1201 //
1202 //foreach (var positionAction in allPositioner)
1203 //{
1204 // if (!positionAction.cachedGO)
1205 // continue;
1206 //
1207 // if (!positionAction.cachedGO.GetComponent<ThrowableCanDisable>())
1208 // continue;
1209 //
1210 // var tcd = positionAction.cachedGO.GetComponent<ThrowableCanDisable>();
1211 //
1212 // if (tcd.name != cachedGO.name)
1213 // continue;
1214 // if (tcd.transform.localScale != cachedGO.transform.localScale)
1215 // continue;
1216 //
1217 // //POSSIBLE FIND?
1218 //}
1219 }
1220
1221 private void SetupCollisions(bool remove = false)
1222 {
1223 if (modifiedCollisions == null)
1224 modifiedCollisions = new List<GameObject>();
1225
1226 if (remove)
1227 {
1228 HandCollisionManager.instance?.ResetLayer(modifiedCollisions.ToArray());
1229 modifiedCollisions.Clear();
1230 return;
1231 }
1232 var tempobject = Instantiate(cachedGO, targetPosition, Quaternion.Euler(targetRotation),
1233 pb_Scene.instance.transform);
1234 tempobject.transform.localPosition = targetPosition;
1235 tempobject.transform.localEulerAngles = targetRotation;
1236
1237 var renderer = tempobject.GetComponentInChildren<Renderer>();
1238 if (renderer)
1239 {
1240 var collisions = Macro.CollidesWithWhat(Macro.GetBounds(tempobject));
1241 //var collisions = Macro.CollidesWithWhat(Macro.CollidesWithWhat(renderer.bounds), renderer, targetPosition, targetRotation);
1243 if (collisions != null)
1244 modifiedCollisions.AddRange(Array.ConvertAll(collisions, c => c.gameObject));
1245 }
1246
1247 Destroy(tempobject);
1248 }
1249 private void SetupCollisionsV2(bool remove = false)
1250 {
1251 if (!MiscLogicManager.instance.UseItemCollision) return;
1252
1253 if (modifiedColliders == null)
1254 modifiedColliders = new List<Collider>();
1255
1256 if (remove)
1257 {
1258 foreach (var coll in modifiedColliders)
1259 {
1260 if (coll)
1261 coll.enabled = true;
1262 }
1263 modifiedCollisions.Clear();
1264 return;
1265 }
1266 var tempobject = Instantiate(cachedGO, targetPosition, Quaternion.Euler(targetRotation),
1267 pb_Scene.instance.transform);
1268 tempobject.transform.localPosition = targetPosition;
1269 tempobject.transform.localEulerAngles = targetRotation;
1270
1271 var renderer = tempobject.GetComponentInChildren<Renderer>();
1272 if (renderer)
1273 {
1274 var collisions = Macro.CollidesWithWhat(Macro.GetBounds(tempobject));
1275 foreach (var coll in collisions)
1276 {
1277 coll.enabled = false;
1278 modifiedColliders.Add(coll);
1279 }
1280 }
1281
1282 Destroy(tempobject);
1283 }
1284
1285 public void OneHandToggle(bool value)
1286 {
1287 oneHanded = value;
1288 }
1289
1290 protected new void Update()
1291 {
1292 if (!actionStarted) return;
1293 base.Update();
1294 if (base.isInFieldOfView(cachedGO)) base.actionRecognized = true;
1295
1296 if (!cachedGO) cachedGO = GetInputGO();
1297 if (!cachedGO || !activated || deactivated) return;
1298 if (forceno) return;
1299 var t = cachedGO.transform;
1300 if (chill > 0)
1301 {
1302 chill -= Time.deltaTime;
1303 return;
1304 }
1305#if !UNITY_WEBGL
1306
1307 if (!canReturnNow && Vector3.Distance(t.position, originalPosition) > 0.12f)
1308 {
1309 canReturnNow = true;
1310 chill = 1f;
1311 }
1312 if (SavedUser.instance.courseType != SavedUser.CourseType.Quality)
1313 {
1314 if (canReturnNow && Vector3.Distance(t.position, originalPosition) < 0.06f)
1315 {
1316 canReturnNow = false;
1318 if (useObjectPositioning) RemoveSelectedHighlight();
1319 if (t.GetComponent<ThrowableCanDisable>())
1320 {
1321 var hands = FindObjectsOfType<HackedHand>();
1322 foreach (var hand in hands) hand.DetachObject(t.gameObject);
1323 }
1324
1325 StartPosition();
1326 chill = 1f;
1327 if (!highlightCurrentObject) StartCoroutine(ShowHighLightCurrent());
1328
1329 return;
1330 }
1331 }
1332 bool onlyOther = false;
1333#if DANA
1334 bool onlyOtherSelected = false;
1335 if (useObjectPositioning)
1336 {
1337 if(!selectedLocalGo) selectedLocalGo = HashingManager.instance.GetGOFromHash(selectedLocalHash);
1338 if (selectedLocalGo.GetComponent<ThrowableCanDisable>())
1339 {
1340 var tcdSelected = selectedLocalGo.GetComponent<ThrowableCanDisable>();
1341 if (!tcdSelected.IsAttachedToHand()) onlyOtherSelected = true;
1342 if (!onlyOtherSelected || HasSelectedHighlight)
1343 {
1344 if (!highlightSelected && useObjectPositioning && tcdSelected && selectedLocalGo.GetComponentInParent<HackedHand>())
1345 {
1347 //StartCoroutine(ShowSelectedHighLight(tcdSelected));
1348
1349 }
1350 }
1351
1352 }
1353
1354 }
1355#endif
1356 if (cachedGO.GetComponent<ThrowableCanDisable>())
1357 {
1358 var tcd = cachedGO.GetComponent<ThrowableCanDisable>();
1359#if DANA
1360
1361
1362 //bool isRunning = false;
1363 //if (cachedGO.GetComponent<TwoHandGrab>() == null) isRunning = false;
1364 //if (cachedGO.GetComponent<TwoHandGrab>() != null) isRunning = cachedGO.GetComponent<TwoHandGrab>().isRunning;
1365
1366 if (!tcd.IsAttachedToHand()/* && !isRunning*/) onlyOther = true;
1367 if (onlyOther && !HasHighlight) return;
1368#endif
1369
1370 if (!highlightObject && (tcd.GetHand()))
1371 if (tcd.GetHand().currentAttachedObject == cachedGO || cachedGO.GetComponentInParent<DobotGrabber>())
1372 {
1373 Destroy(highlightCurrentObject);
1375 {
1377 if (useObjectPositioning)
1378 {
1379 FollowMe.Instance?.StartFollowing(selectedLocalGo.transform.TransformPoint(localpos), selectedLocalGo);
1380 }
1381 else
1382 {
1383 FollowMe.Instance?.StartFollowing(tcd.GetHand().currentAttachedObjectInfo.Value.originalParent.transform.TransformPoint(targetPosition), cachedGO);
1384 }
1385 }
1386#if DANA
1387 if (useObjectPositioning && onlyOtherSelected) return;
1388#endif
1389 StartCoroutine(ShowHighLight(tcd));
1390
1391 SetupCollisions();
1392 SetupCollisionsV2();
1393 //Destroy(attachPoint.gameObject);
1394
1395
1396
1397 }
1398 //if (!highlightObject && cachedGO.GetComponent<TwoHandGrab>())
1399 // if (cachedGO.GetComponent<TwoHandGrab>().isRunning)
1400 // {
1401 // StartCoroutine(ShowHighLight(tcd));
1402 // SetupCollisions();
1403 // SetupCollisionsV2();
1404 // //Destroy(attachPoint.gameObject);
1405 // Destroy(highlightCurrentObject);
1406 // if (MiscLogicManager.instance.mode == MiscLogicManager.CurrentMode.Training)
1407 // {
1408 // PreviewHand.Instance?.hideHandPreview(cachedGO);
1409 // FollowMe.Instance?.StartFollowing(targetPosition, cachedGO);
1410 // }
1411
1412 // }
1413 }
1414 if (cachedGO.GetComponentInParent<DobotGrabber>())
1415 return;
1416 if (cachedGO.GetComponent<ThrowableCanDisable>() && cachedGO.GetComponent<ThrowableCanDisable>().IsSmall() && cachedGO.GetComponentInParent<HandCopyAvg>() && cachedGO.GetComponentInParent<HandCopyAvg>().release())
1417 {
1418 cachedGO.GetComponent<ThrowableCanDisable>().ForceDrop();
1419 }
1420 #region Auto Rotation
1421 var dist = Vector3.Distance(t.position, targetPosition);
1422 if (dist < 0.1f)
1423 {
1424 var tcd = cachedGO.GetComponent<ThrowableCanDisable>();
1425 //if (!cachedGO.GetComponent<TwoHandGrab>())
1426 //{
1427 //var connectedJoints = tcd.GetHand().GetComponentsInChildren<ConfigurableJoint>();
1428 //var connectedJoint = connectedJoints[0];
1429 //connectedJoint.connectedBody = null;
1430 //}
1431
1432 t.eulerAngles = Macro.LerpAngle(t.eulerAngles, targetRotation, 1 - dist * 10);
1433 }
1434 else
1435 {
1436 var tcd = cachedGO.GetComponent<ThrowableCanDisable>();
1437 //if (!cachedGO.GetComponent<TwoHandGrab>())
1438 //{
1439 //var connectedJoints = tcd.GetHand().GetComponentsInChildren<ConfigurableJoint>();
1440 //var connectedJoint = connectedJoints[0];
1441 //connectedJoint.connectedBody = cachedGO.GetComponentInChildren<Rigidbody>();
1442 //}
1443
1444 }
1445 #endregion
1446
1447
1448
1450 {
1451 GetAllSameGOs();
1452 if (allSame != null && allSame.Count > 0)
1453 foreach (var o in allSame)
1454 {
1455 var tcd = o.GetComponent<ThrowableCanDisable>();
1456 if (tcd && !o.GetComponent<StaticGO>() && tcd.IsAttachedToHand())
1457#if DANA
1459 {
1460 EndCheck(o);
1461 }
1462
1463#else
1464 EndCheck(o);
1465#endif
1466 }
1467 else if (!onlyOther)
1468 EndCheck(t);
1469 }
1470 else if (HasHighlight)
1471 {
1472 GetAllSameGOs();
1473 if (allSame != null && allSame.Count > 0)
1474 foreach (var o in allSame)
1475 {
1476 var tcd = o.GetComponent<ThrowableCanDisable>();
1477 if (tcd && !o.GetComponent<StaticGO>() && tcd.IsAttachedToHand())
1478 {
1479#if DANA
1481 {
1482 EndCheck(o);
1483 }
1484
1485#else
1486 EndCheck(o);
1487#endif
1488
1489 }
1490
1491 else if (tcd && !o.GetComponent<StaticGO>()/* && tcd.GetComponent<TwoHandGrab>() != null*/)
1492 {
1493#if DANA
1495 {
1496 EndCheck(o);
1497 }
1498
1499#else
1500 EndCheck(o);
1501#endif
1502 }
1503
1504 }
1505 else if (!onlyOther)
1506 EndCheck(t);
1507 }
1508 else if (!onlyOther)
1509 EndCheck(t);
1510
1511#endif
1512 }
1513
1514 public new void TriggerOutput(string id)
1515 {
1516 if (ogSaved)
1517 {
1518 var oh = cachedGO.GetComponent<OffsetHolder>();
1519 oh.Offset = origOHvalues[0];
1520 oh.Rotation = origOHvalues[1];
1521 oh.LeftOffset = origOHvalues[2];
1522 oh.LeftRotation = origOHvalues[3];
1523 origOHvalues = null;
1524 }
1525 base.TriggerOutput(id);
1526 }
1527
1528 private void EndCheck(Transform t)
1529 {
1530 if (InGoodPos(t) && InGoodRot(t))
1531 {
1532 var useFlyin = true;
1534 chill = 1.0f;
1535 if (triggerOnce) chill = float.MaxValue;
1537
1538 if (!useFlyin)
1539 TriggerOutput(outPuts[0].name);
1540#if !UNITY_WEBGL
1541 statusImg.color = Color.green;
1542#endif
1543#if !UNITY_WEBGL
1544 //if (t.GetComponent<TwoHandGrab>())
1545 //{
1546 // //t.GetComponent<TwoHandGrab>().detachGO();
1547 // t.GetComponent<TwoHandGrab>().enabled = false;
1548 // //StopAllCoroutines();
1549 //}
1550 if (t.GetComponent<ThrowableCanDisable>())
1551 {
1552 var hands = FindObjectsOfType<HackedHand>();
1553 foreach (var hand in hands) hand.DetachObject(t.gameObject);
1554 // make it static
1555 var isStatic = t.GetComponent<StaticGO>();
1556 var hasRigidbody = t.GetComponent<Rigidbody>();
1557 var hasInteractable = t.GetComponent<Interactable>();
1558 var hasThrowable = t.GetComponent<ThrowableCanDisable>();
1559
1560 if (!isStatic) t.gameObject.AddComponent<StaticGO>();
1561
1562 if (hasThrowable) Destroy(hasThrowable);
1563 if (hasInteractable) Destroy(hasInteractable);
1564 if (hasRigidbody)
1565 {
1566 hasRigidbody.isKinematic = true;
1567 Destroy(hasRigidbody);
1568 }
1569
1570 if (useFlyin)
1571 {
1572 StartCoroutine(FlyIn(t));
1573 }
1574 else
1575 {
1576 t.localPosition = targetPosition;
1577 t.localEulerAngles = targetRotation;
1578 TriggerOutput(outPuts[0].name);
1579 }
1580 }
1581
1582 Destroy(highlightCurrentObject);
1583 jobsDone = true;
1584#endif
1585 }
1586 else
1587 {
1588#if !UNITY_WEBGL
1589 statusImg.color = Color.red;
1590#endif
1591 }
1592 }
1593
1594 private IEnumerator FlyIn(Transform t)
1595 {
1596
1597 if (useObjectPositioning)
1598 t.SetParent(selectedLocalGo.transform, true);
1599
1600 yield return null;
1601
1602 for (float i = 0; i <= 1; i += 0.05f)
1603 {
1604 t.localPosition = Vector3.Lerp(t.localPosition, targetPosition, i);
1605 t.localRotation = Quaternion.Lerp(t.localRotation, Quaternion.Euler(targetRotation), i);
1606 yield return null;
1607 }
1608 TriggerOutput(outPuts[0].name);
1610 var action = Controller.Instance.GetActionByInOut(connection.fromId);
1611 if (action is GameObjectAction objectAction)
1612 {
1613 objectAction.IfNotTrigger();
1614 }
1615
1616 }
1617
1618 public bool GetHandOffsets(out Vector3 offset, out Vector3 rotation, out Vector3 leftoffset, out Vector3 leftrotation)
1619 {
1620 offset = Vector3.zero;
1621 rotation = Vector3.zero;
1622 leftoffset = Vector3.zero;
1623 leftrotation = Vector3.zero;
1624 if (gameObjectActionRefference == null) return false;
1625
1626 offset = gameObjectActionRefference.Offset;
1627 rotation = gameObjectActionRefference.Rotation;
1628 leftoffset = gameObjectActionRefference.LeftOffset;
1629 leftrotation = gameObjectActionRefference.LeftRotation;
1630 if (offset == Vector3.zero && rotation == Vector3.zero && leftoffset == Vector3.zero && leftrotation == Vector3.zero)
1631 {
1632 return false;
1633 }
1634 return true;
1635 }
1636
1637 [Button]
1638 [CanBeNull]
1639 internal GameObject GetInputGO()
1640 {
1641 try
1642 {
1644 var action = Controller.Instance.GetActionByInOut(connection.fromId);
1645 GameObject retval = null;
1646 if (action is GameObjectAction objectAction)
1647 {
1648 gameObjectActionRefference = objectAction;
1649 retval = objectAction.GetGameObject();
1650 }
1651 if (action is WeldAction weldAction) retval = weldAction.GetGameObject();
1652 if (action is ToolAction toolAction) retval = toolAction.GetGameObject();
1653
1654 if (originalPosition != default)
1655 {
1656 originalPosition = retval.transform.localPosition;
1657 originalRotation = retval.transform.localEulerAngles;
1658 }
1659
1660
1661 Debug.Log($"Positioner requested: \"{retval}\"");
1662
1663
1664 if (cachedGO && cachedGO.GetComponent<ThrowableCanDisable>())
1665 {
1666 var tcd = cachedGO.GetComponent<ThrowableCanDisable>();
1667 tcd.enabled = false;
1668 }
1669
1670 if (retval && !retval.GetComponent<OffsetHolder>())
1671 {
1672 retval.AddComponent<OffsetHolder>();
1673 retval.AddComponent<VisualOffset>();
1674 }
1675
1676 return retval;
1677 }
1678 catch (Exception)
1679 {
1680 return null;
1681 }
1682 }
1683
1684 public override void GetObjectData(SerializationInfo info, StreamingContext context)
1685 {
1686 base.GetObjectData(info, context);
1687 var convertOldSave = false;
1688 if (convertOldSave) targetPosition = targetPosition - new Vector3(0.4815754f, -0.324203f, -0.0164394f);
1689 info.AddValue("targetPosition", targetPosition, typeof(Vector3));
1690 info.AddValue("targetRotation", targetRotation, typeof(Vector3));
1691 if (tolerance == 0) tolerance = 0.05f;
1692 info.AddValue("tolerance", tolerance, typeof(float));
1693 info.AddValue("taktTime", taktTime, typeof(float));
1694 info.AddValue("useLocal", useObjectPositioning);
1695 if (useObjectPositioning)
1696 {
1697 info.AddValue("localpos", localpos);
1698 info.AddValue("localrot", localrot);
1699 info.AddValue("fwdoffset", fwdoffset);
1700 info.AddValue("upoffset", upoffset);
1701 info.AddValue("selectedLocalHash", selectedLocalHash);
1702 }
1703 info.AddValue("oneHand", oneHanded);
1704#if DANA
1705 info.AddValue("selectedGO", selectedGO, typeof(GameObject));
1706 info.AddValue("isLocal", isLocal, typeof(bool));
1707 info.AddValue("selectedHash", selectedHash, typeof(bool));
1708#endif
1709 }
1710
1711 public PositionAction(SerializationInfo info, StreamingContext context) : base(info, context)
1712 {
1713 targetPosition = (Vector3)info.GetValue("targetPosition", typeof(Vector3));
1714 targetRotation = (Vector3)info.GetValue("targetRotation", typeof(Vector3));
1715
1716 try
1717 {
1718 tolerance = (float)info.GetValue("tolerance", typeof(float));
1719 }
1720 catch (Exception)
1721 {
1722 tolerance = 0.05f;
1723 }
1724
1725 foreach (var s in info)
1726 {
1727 if (s.Name == "useLocal")
1728 useObjectPositioning = info.GetBoolean("useLocal");
1729
1730 if (s.Name == "localpos")
1731 localpos = (Vector3)info.GetValue("localpos", typeof(Vector3));
1732
1733 if (s.Name == "localrot")
1734 localrot = (Vector3)info.GetValue("localrot", typeof(Vector3));
1735
1736 if (s.Name == "fwdoffset")
1737 fwdoffset = (Vector3)info.GetValue("fwdoffset", typeof(Vector3));
1738
1739 if (s.Name == "upoffset")
1740 upoffset = (Vector3)info.GetValue("upoffset", typeof(Vector3));
1741
1742 if (s.Name == "selectedLocalHash")
1743 selectedLocalHash = info.GetString("selectedLocalHash");
1744 if (s.Name == "taktTime")
1745 taktTime = (float)info.GetValue("taktTime", typeof(float));
1746 if (s.Name == "oneHand")
1747 oneHanded = info.GetBoolean("oneHand");
1748
1749 }
1750 }
1751}
Es.InkPainter.Math Math
Definition: PaintTest.cs:7
UnityEngine.UI.Button Button
Definition: Pointer.cs:7
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
UnityEngine.Color Color
Definition: TestScript.cs:32
Image statusImg
Definition: ActionObject.cs:21
string action
Definition: ActionObject.cs:32
List< GameObject > outPuts
Definition: ActionObject.cs:19
string GetInput()
Connection GetConnectionByEndPointId(string id)
Definition: Controller.cs:857
ActionObject GetActionByInOut(string id)
Definition: Controller.cs:925
static Controller Instance
Definition: Controller.cs:16
void StartFollowing(Vector3 EndPosition, GameObject TargetObject)
Definition: FollowMe.cs:35
static FollowMe Instance
Definition: FollowMe.cs:19
static void Clear()
Definition: pb_Selection.cs:61
static GameObject activeGameObject
Definition: pb_Selection.cs:82
GameObject GetGameObject()
void ResetLayer(GameObject[] gameobjects)
static HandCollisionManager instance
void SetLayer(GameObject[] gameobjects)
bool release()
Definition: HandCopyAvg.cs:300
static HandInventory instance
bool IsInInventory(ThrowableCanDisable tcd)
Definition: Macro.cs:12
static Bounds GetBounds(GameObject go)
Definition: Macro.cs:482
static Collider[] CollidesWithWhat(Bounds bounds, bool skipHand=true)
Definition: Macro.cs:569
static Vector3 LerpAngle(Vector3 from, Vector3 to, float t)
Definition: Macro.cs:298
Vector3 Offset
Definition: OffsetHolder.cs:7
Vector3 LeftRotation
Definition: OffsetHolder.cs:10
Vector3 Rotation
Definition: OffsetHolder.cs:8
Vector3 LeftOffset
Definition: OffsetHolder.cs:9
override void Start()
void FillCurrentTransform()
GameObject followGo
void onTaktTimeChanged(string value)
bool GetHandOffsets(out Vector3 offset, out Vector3 rotation, out Vector3 leftoffset, out Vector3 leftrotation)
bool InGoodRot(Transform t)
new void Update()
void RefreshTargetDisplay()
GameObject highlightObject
void RemoveSelectedHighlight()
override void OnPointerExit(PointerEventData eventData)
override void Deactivate()
InputField[] posInputs
InputField toleranceField
Object highlightCurrentObject
void onToleranceChanged(string value)
IEnumerator ShowHighLightOriginalOptimization()
override void Triggered(string id)
InputField taktTimeInput
bool InGoodPos(Transform t)
IEnumerator ShowSelectedHighLight(ThrowableCanDisable tcd)
Material originalHighlightMat
List< Transform > allSame
Vector3 targetRotation
InputField[] rotInputs
override void GetObjectData(SerializationInfo info, StreamingContext context)
void onPosChanged(string value)
PositionAction(SerializationInfo info, StreamingContext context)
Vector3 originalPosition
void RemoveHighlight()
GameObject highlightObjectOriginal
Vector3 originalRotation
IEnumerator ShowHighLightOriginal()
Material imageHighlight
Material highlightMaterial
new void TriggerOutput(string id)
GameObject highlightSelected
void onRotChanged(string value)
IEnumerator ShowHighLightOptimization()
Object highlightCurrentSelectedObject
void SelectObjectToPosition()
Vector3 targetPosition
override void InputAdded(string id)
override void OnPointerEnter(PointerEventData eventData)
void OneHandToggle(bool value)
IEnumerator ShowHighLight(ThrowableCanDisable tcd)
void hideHandPreview(GameObject objectToGrab)
Definition: PreviewHand.cs:73
void EnterOffsetEditor(GameObject objectToGrab, ActionObject action, Vector3 TargetPos, Vector3 TargetRot)
Definition: PreviewHand.cs:40
static PreviewHand Instance
Definition: PreviewHand.cs:16
static SoundManager instance
Definition: SoundManager.cs:8
void PlaySuccessSound()
Definition: SoundManager.cs:33
Tool
Definition: pb_Enum.cs:24
UnityEngine.Object Object