Tanoda
HoldPositionAction.cs
Go to the documentation of this file.
1using System;
2using System.Globalization;
3using System.Runtime.Serialization;
4using UnityEngine;
5using UnityEngine.UI;
6
8{
9 public InputField holdInput;
10
11 internal float holdTime = 2.0f;
12 private float currTime;
13 private bool done;
14
15 public override void Start()
16 {
17 base.Start();
18 currTime = holdTime;
19 forceno = true;
20 }
21
22 //void baseofbaseUpdate()
23 //{
24 // var ptr = typeof(ActionObject).GetMethod("Update").MethodHandle.GetFunctionPointer();
25 // var baseUpdate = (Action)Activator.CreateInstance(typeof(Action), this, ptr);
26 // baseUpdate();
27 //}
28
29 // Update is called once per frame
30 new void Update()
31 {
32 base.Update();
33 if (base.isInFieldOfView(cachedGO)) base.actionRecognized = true;
34 if (!cachedGO || !activated || done) return;
35 var t = cachedGO.transform;
36
37 if (!actionStarted) {
38
39#if !UNITY_WEBGL
40 if (canReturnNow && Vector3.Distance(t.position, originalPosition) < 0.06f)
41 {
42 canReturnNow = false;
44 if (t.GetComponent<ThrowableCanDisable>())
45 {
46 var hands = FindObjectsOfType<HackedHand>();
47 foreach (var hand in hands) hand.DetachObject(t.gameObject);
48 }
49
51 chill = 1f;
52 Macro.SetStatic(cachedGO);
53
54 return;
55 }
56#endif
57 return;
58 }
59 spentTimeOnAction += Time.deltaTime;
60
61
62 if (chill > 0)
63 {
64 chill -= Time.deltaTime;
65 return;
66 }
67
68 if (!canReturnNow && Vector3.Distance(t.position, originalPosition) > 0.12f)
69 {
70 canReturnNow = true;
71 chill = 1f;
72 }
73#if !UNITY_WEBGL
74 if (canReturnNow && Vector3.Distance(t.position, originalPosition) < 0.06f)
75 {
76 canReturnNow = false;
78 if (t.GetComponent<ThrowableCanDisable>())
79 {
80 var hands = FindObjectsOfType<HackedHand>();
81 foreach (var hand in hands) hand.DetachObject(t.gameObject);
82 }
83
85 chill = 1f;
86
87 return;
88 }
89
90 if (cachedGO.GetComponent<ThrowableCanDisable>())
91 {
92 var tcd = cachedGO.GetComponent<ThrowableCanDisable>();
93#if DANA
94 if (!tcd.IsAttachedToHand()) return;
95#endif
96
97 if (!highlightObject && tcd.GetHand())
98 if (tcd.GetHand().currentAttachedObject == cachedGO)
99 {
100 StartCoroutine(ShowHighLight(tcd));
101
102 Destroy(highlightCurrentObject);
104 }
105 }
106#endif
107 if (InGoodPos(t) && InGoodRot(t))
108 {
109 currTime -= Time.deltaTime;
110 }
111 else
112 {
113 currTime = holdTime;
114#if !UNITY_WEBGL
115 statusImg.color = Color.red;
116#endif
117 return;
118 }
119
120 if (currTime <= 0.0f)
121 {
122 if (highlightObject)
123 Destroy(highlightObject);
124
125 TriggerOutput(outPuts[0].name);
127 var action = Controller.Instance.GetActionByInOut(connection.fromId);
128 if (action is GameObjectAction objectAction)
129 {
130 objectAction.IfNotTrigger();
131 }
132#if !UNITY_WEBGL
133 statusImg.color = Color.green;
134#endif
136 //#if !UNITY_WEBGL
137 if (t.GetComponent<ThrowableCanDisable>())
138 {
139 //var hands = FindObjectsOfType<HackedHand>();
140 //foreach (var hand in hands) hand.DetachObject(t.gameObject);
141 StartCoroutine(ShowHighLightOriginal());
142 }
143 //#endif
144
145 //StartPosition();
146 //chill = 1f;
147 //done = true;
148 }
149 }
150
151
152 public void onHoldTimeChanged(string value)
153 {
154 try
155 {
156 var ci = CultureInfo.CurrentCulture;
157 var nfi = ci.NumberFormat;
158 holdInput.text = holdInput.text.Replace(',', nfi.CurrencyDecimalSeparator[0]);
159 holdInput.text = holdInput.text.Replace('.', nfi.CurrencyDecimalSeparator[0]);
160 var single = Convert.ToSingle(holdInput.text, ci);
161 holdInput.text = single.ToString("F2");
162 tolerance = single;
163 holdTime = float.Parse(value, ci);
164 }
165 catch (Exception)
166 {
167 Debug.LogWarning("not parsable number(?) in holdTime inputfield!");
168
169 // restore last valid numbers
170 holdInput.text = holdTime.ToString("F2");
171 }
172 }
173
174
175 public new void RefreshTargetDisplay()
176 {
177 base.RefreshTargetDisplay();
178
179 holdInput.text = holdTime.ToString("F2");
180 }
181
182 public new void StartPosition()
183 {
184 base.StartPosition();
186
187 }
188
189 public override void GetObjectData(SerializationInfo info, StreamingContext context)
190 {
191 base.GetObjectData(info, context);
192 if (holdTime == default || holdTime == 0) holdTime = 2.0f;
193 info.AddValue("holdTime", holdTime, typeof(float));
194 }
195
196 public HoldPositionAction(SerializationInfo info, StreamingContext context) : base(info, context)
197 {
198 targetPosition = (Vector3) info.GetValue("targetPosition", typeof(Vector3));
199 targetRotation = (Vector3) info.GetValue("targetRotation", typeof(Vector3));
200 holdTime = info.GetSingle("holdTime");
201 foreach (var s in info)
202 {
203 if (s.Name == "taktTime")
204 taktTime = (float)info.GetValue("taktTime", typeof(float));
205 }
206 }
207}
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
HoldPositionAction(SerializationInfo info, StreamingContext context)
override void Start()
override void GetObjectData(SerializationInfo info, StreamingContext context)
void onHoldTimeChanged(string value)
new void RefreshTargetDisplay()
Definition: Macro.cs:12
static void SetStatic(GameObject go)
Definition: Macro.cs:388
bool InGoodRot(Transform t)
GameObject highlightObject
Object highlightCurrentObject
bool InGoodPos(Transform t)
Vector3 targetRotation
Vector3 originalPosition
void RemoveHighlight()
IEnumerator ShowHighLightOriginal()
new void TriggerOutput(string id)
Vector3 targetPosition
IEnumerator ShowHighLight(ThrowableCanDisable tcd)
void hideHandPreview(GameObject objectToGrab)
Definition: PreviewHand.cs:73
static PreviewHand Instance
Definition: PreviewHand.cs:16