2using System.Collections;
3using System.Collections.Generic;
4using System.Runtime.Serialization;
6using NaughtyAttributes;
9using System.Globalization;
15 internal float holdTime = 2.0f;
16 private float currTime;
17 private float realTime = 0.0f;
19 internal float tolerance = 0.05f;
20 private bool isGoodPos =
false;
21 private bool inProgress=
false;
22 private GameObject ProgressCanvas;
24 private Camera VRCamera;
25 internal GameObject aiRParticle;
26 private Vector3 originalEuler;
28 bool clecoInGoodPos =
false;
29 internal bool isPenalty =
false;
30 internal bool low =
false;
31 internal bool high =
false;
33 bool alreadyTriggerOut =
false;
34 Vector3 targetEndLocalEuler = Vector3.zero;
39 currTime = holdTime*2;
42 ProgressCanvas = GameObject.Find(
"Canvas_ProgressBar").gameObject;
44 VRCamera = GameObject.Find(
"VRCamera")?.GetComponent<Camera>();
46 VRCamera = Camera.current;
55 ProgressCanvas.GetComponentInChildren<
Image>(
true).fillAmount = 0;
56 var tool = GetToolObject();
57 if ((Tool)
drop.value == Tool.ClecoNutrunner)
72 if (tcd.onDetachFromHand ==
null)
75 tcd.onDetachFromHand.AddListener(OnToolPutDown);
78 if((Tool)
drop.value == Tool.ClecoNutrunner && !alreadyTriggerOut)
80 tool.GetComponentInParent<
ManipulatorArm>().onDetach.AddListener(OnToolPutDown);
81 alreadyTriggerOut =
true;
86 private void OnToolPutDown()
89 ProgressCanvas?.transform.SetParent(
null,
true);
92 var t = GetToolObject().transform;
94 t.localEulerAngles = originalEuler;
95 var rb = GetToolObject().GetComponentInChildren<Rigidbody>();
98 rb.isKinematic =
true;
99 rb.useGravity =
false;
100 rb.velocity = Vector3.zero;
103 if (currTime != holdTime*2)
107 penaltyTime = Mathf.Abs(holdTime - realTime);
120 if ((
Tool)
drop.value !=
Tool.ClecoNutrunner && !nextActionIsTheSame())
122 if (GetToolObject() ==
null)
135 if (aiRParticle !=
null)
137 aiRParticle.GetComponent<ParticleSystem>().Stop();
138 aiRParticle.SetActive(
false);
145 Destroy(highlightTool);
146 Destroy(highlightObject);
152 var tool = GetToolObject();
157 tcd.onDetachFromHand.RemoveListener(OnToolPutDown);
161 tool.GetComponentInParent<
ManipulatorArm>().onDetach.RemoveListener(OnToolPutDown);
179 if (base.isInFieldOfView(GetToolObject())) base.actionRecognized =
true;
180 if (!activated || done)
return;
185 var tool = GetToolObject();
200 StartCoroutine(ShowHighLight());
215 var t = tool.transform;
219 if (tcd && !tcd.IsAttachedToHand() )
return;
220 time += Time.deltaTime;
221 if (tool.GetComponentInParent<
HandCopyAvg>() && tool.GetComponentInParent<
HandCopyAvg>().release() && time >= 2.0f)
223 StartCoroutine(hideProgressBar());
233 if (!highlightObject && !executed)
235 if ((
Tool)
drop.value !=
Tool.ClecoNutrunner) StartCoroutine(ShowHighLight());
256 targetEndLocalEuler = t.localEulerAngles;
259 var dist =
Vector3.Distance(t.position, targetPosition);
263 var targetLocalEuler =
Vector3.zero;
266 originalEuler = t.localEulerAngles;
280 t.eulerAngles = targetRotation;
281 targetLocalEuler = t.localEulerAngles;
282 t.localEulerAngles =
Macro.
LerpAngle(originalEuler, targetLocalEuler, Mathf.Max(0, 1f - Mathf.Max(0, dist - 0.05f) * 10));
297 aiRParticle = t.GetComponentInChildren<ParticleSystem>(
true).gameObject;
302 Transform OriginalParent = ProgressCanvas.transform.parent;
303 Image Progress = ProgressCanvas.GetComponentInChildren<
Image>(
true);
305 StartCoroutine(LookAtCanvas());
310 currTime -= Time.deltaTime;
311 if ((
Tool)
drop.value ==
Tool.LevegosPisztoly && !isGoodPos)
313 aiRParticle = t.GetComponentInChildren<ParticleSystem>(
true).gameObject;
323 ProgressCanvas.transform.SetParent(t ,
true);
327 ProgressCanvas.transform.localPosition =
new Vector3(0,0,0);
328 ProgressCanvas.transform.position = ProgressCanvas.transform.position +
new Vector3(0,0.1f,0);
333 StartCoroutine(ProgressBar(holdTime, Progress, ProgressCanvas));
334 StartCoroutine(AirBlow(aiRParticle));
338 if (overload && !stopped)
345 ProgressCanvas.transform.SetParent(t,
true);
350 ProgressCanvas.transform.localPosition =
new Vector3(0, 0, 0);
351 ProgressCanvas.transform.position = ProgressCanvas.transform.position +
new Vector3(0, 0.1f, 0);
358 if (savedCustomTool.name.Contains(
"desoutter") || savedCustomTool.name.Contains(
"Csavarbehajto"))
363 if (savedCustomTool.name.Contains(
"pneumatikus") || savedCustomTool.name.Contains(
"airImpactWrench"))
370 StartCoroutine(ProgressBar(holdTime, Progress, ProgressCanvas));
407 else if ((
Tool)
drop.value ==
Tool.ClecoNutrunner && clecoInGoodPos)
411 currTime -= Time.deltaTime;
414 var clecoTrigger = GameObject.FindObjectsOfType<
ClecoTrigger>();
415 var cleco = clecoTrigger[0].transform.parent;
416 ProgressCanvas.transform.SetParent(cleco,
true);
420 ProgressCanvas.transform.localPosition =
new Vector3(0, 0, 0);
421 ProgressCanvas.transform.position = ProgressCanvas.transform.position +
new Vector3(0, 0.1f, 0);
432 ProgressCanvas.transform.localPosition =
new Vector3(0, 0, 0);
433 ProgressCanvas.transform.position = ProgressCanvas.transform.position +
new Vector3(0, 0.1f, 0);
438 StartCoroutine(ProgressBar(holdTime, Progress, ProgressCanvas));
449 ProgressCanvas.transform.SetParent(OriginalParent,
true);
451 ProgressCanvas.transform.GetChild(0).gameObject.SetActive(
false);
452 if (aiRParticle !=
null)
454 aiRParticle.GetComponent<ParticleSystem>().Stop();
455 aiRParticle.SetActive(
false);
465 if (currTime != holdTime*2)
467 if (nextActionIsTheSame()) OnToolPutDown();
490 if (currTime <= 0.0f)
493 ProgressCanvas.transform.SetParent(OriginalParent,
true);
501 Destroy(highlightTool);
503 Destroy(highlightObject);
510 wrench.transform.eulerAngles = targetRotation;
511 wrench.transform.position = targetPosition;
526 smolwrench.transform.eulerAngles = targetRotation;
527 smolwrench.transform.position = targetPosition;
578 Destroy(highlightObject);
582 void selectedTriggerEnter(Collider other)
584 if (other.gameObject ==
selectedGO || isInChildren(other))
586 clecoInGoodPos =
true;
590 void selectedTriggerExit(Collider other)
592 if (other.gameObject ==
selectedGO || isInChildren(other))
594 clecoInGoodPos =
false;
597 bool isInChildren(Collider other)
599 var GOInChildren =
selectedGO.GetComponentsInChildren<Collider>();
600 foreach (var GO
in GOInChildren)
609 internal GameObject GetToolObject()
613 tool = savedCustomTool;
617 case Tool.Screwdriver:
626 case Tool.SmolWrench:
629 case Tool.DigitalTorqueWrench:
632 case Tool.SeegerPlier:
638 case Tool.GreaseBrush:
639 case Tool.ClecoNutrunner:
640 var clecoTrigger = GameObject.FindObjectsOfType<
ClecoTrigger>();
641 tool = clecoTrigger[0].transform.gameObject;
646 case Tool.LevegosPisztoly:
649 case Tool.CustomTool:
655 tool = savedCustomTool;
665 private IEnumerator LookAtCanvas()
669 ProgressCanvas.transform.LookAt(VRCamera.transform);
674 private IEnumerator PlaySound()
685 private IEnumerator AirBlow(GameObject ParticleSystem)
687 ParticleSystem.gameObject.SetActive(
true);
688 ParticleSystem.GetComponent<ParticleSystem>().Play();
692 private IEnumerator ProgressBar(
float value,
Image progressImage, GameObject progressCanvas)
694 float time = realTime;
697 progressCanvas.transform.GetChild(0).gameObject.SetActive(
true);
699 Color yellow =
new Color(250/255f, 250/255f, 6/255f);
700 Color red =
new Color(250/255f, 13/255f, 6/255f);
701 Color green =
new Color(11/255f, 250/255f, 6/255f);
703 while (inProgress && progressImage.fillAmount < 1)
705 time += Time.deltaTime;
706 if (progressImage.fillAmount <= 0.30f)
708 progressImage.color = yellow;
715 fill = progressImage.fillAmount - 0.3f;
716 if (progressImage.fillAmount >= 0.30f && progressImage.fillAmount <= 0.36f)
718 progressImage.color =
Color.Lerp(yellow, green, fill / 0.06f);
723 fill = progressImage.fillAmount - 0.58f;
724 if (progressImage.fillAmount >= 0.58f && progressImage.fillAmount <= 0.64f)
726 progressImage.color =
Color.Lerp(green, red, fill / 0.06f);
733 if (progressImage.fillAmount <= 0.36f)
735 progressImage.fillAmount = Mathf.Lerp(0, 0.36f, time/((value)*0.9f));
738 deltaTime = time - ((value) * 0.9f);
739 if (progressImage.fillAmount >= 0.36f && progressImage.fillAmount <= 0.64f)
741 progressImage.fillAmount = Mathf.Lerp(0.36f, 0.64f, deltaTime/(value*2*0.1f));
743 deltaTime = time - ((value) * 1.1f);
744 if (progressImage.fillAmount >= 0.64f)
746 progressImage.fillAmount = Mathf.Lerp(0.64f, 1, deltaTime / ((value*2) - (value*1.1f)));
755 private IEnumerator hideProgressBar()
758 ProgressCanvas.transform.GetChild(0).gameObject.SetActive(
false);
759 if (aiRParticle !=
null)
761 aiRParticle.GetComponent<ParticleSystem>().Stop();
762 aiRParticle.SetActive(
false);
770 var ci = CultureInfo.CurrentCulture;
771 var nfi = ci.NumberFormat;
774 var single = Convert.ToSingle(
holdInput.text, ci);
777 holdTime =
float.Parse(value, ci);
781 Debug.LogWarning(
"not parsable number(?) in holdTime inputfield!");
784 holdInput.text = holdTime.ToString(
"F2");
803 public override void GetObjectData(SerializationInfo info, StreamingContext context)
805 base.GetObjectData(info, context);
806 if (holdTime ==
default || holdTime == 0) holdTime = 2.0f;
807 info.AddValue(
"holdTime", holdTime, typeof(
float));
811 base.RefreshTargetDisplay();
813 holdInput.text = holdTime.ToString(
"F2");
815 public HoldToolAction(SerializationInfo info, StreamingContext context) : base(info, context)
817 toolIndex = (int)info.GetValue(
"toolIndex", typeof(
int));
818 targetPosition = (Vector3)info.GetValue(
"targetPosition", typeof(Vector3));
819 targetRotation = (Vector3)info.GetValue(
"targetRotation", typeof(Vector3));
824 foreach (var e
in info)
826 if (e.Name ==
"selectedGO")
selectedGO = (GameObject)info.GetValue(
"selectedGO", typeof(GameObject));
827 if (e.Name ==
"customTool")
828 savedCustomTool = (GameObject)info.GetValue(
"customTool", typeof(GameObject));
829 if (e.Name ==
"selectedGOHash")
selectedHash = info.GetString(
"selectedGOHash");
830 if (e.Name ==
"customToolHash")
customToolHash = info.GetString(
"customToolHash");
831 if (e.Name ==
"torqueNm") torqueNm = info.GetInt32(
"torqueNm");
832 if (e.Name ==
"taktTime") taktTime = (float)info.GetValue(
"taktTime", typeof(
float));
834 holdTime = info.GetSingle(
"holdTime");
System.Drawing.Image Image
void TriggerOutput(string id)
List< GameObject > outPuts
static ClecoTrigger instance
UnityEvent< Collider > triggerExit
UnityEvent< Collider > triggerEnter
Connection GetConnectionByEndPointId(string id)
ActionObject GetActionByInOut(string id)
static Controller Instance
void StartFollowing(Vector3 EndPosition, GameObject TargetObject)
static Vector3 LerpAngle(Vector3 from, Vector3 to, float t)
static PenaltyCounter Instance
void hideHandPreview(GameObject objectToGrab)
static PreviewHand Instance
static SeegerHelper instance
static SoundManager instance
void PlayElectricScrewdriverSound()
static TorqueWrenchDigital instance
static TorqueWrench instance
static TorqueWrenchSmol instance