-
Notifications
You must be signed in to change notification settings - Fork 0
/
QRCODEHM.cs
363 lines (329 loc) · 13.9 KB
/
QRCODEHM.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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using TMPro;
using Microsoft.MixedReality.Toolkit.Input;
using Microsoft.MixedReality.Toolkit.UI;
public class QRCODEHM : MonoBehaviour
{
public static bool Location;
public static int Points = 1;
public static GameObject PointA;
public static GameObject PointB;
public static GameObject PointC;
public static GameObject PointD;
public static GameObject thismdll;
private static Vector3 Vba;
private static Vector3 Vac;
private static Vector3 Vbd;
private static Vector3 record;
private static float Lac;
private static float Lbd;
private static float angle;
private RaycastHit hitInf;
private float distance;
//public static int ii = 0;
public static GameObject QRimage;
public static Text TEXTTTTT;
// Use this for initialization
void Awake()
{
}
public void Ianhsu()
{
GameObject a = GameObject.Find("1fv1(Clone)");
Debug.Log("00000");
//Box = Resources.Load("po1") as GameObject;
//Box1 = Resources.Load("po2") as GameObject;
foreach (Transform child in a.transform)
{
if (null == child)
continue;
if (child.gameObject.name == "getCKEditorImage") //找到QRCODE
{
GameObject.Find("Textguide").GetComponent<Text>().enabled = true;
/*a.GetComponent<NearInteractionGrabbable>().enabled = false;
PointA = Instantiate(GameObject.Find("po3").gameObject);
PointB = Instantiate(GameObject.Find("po3").gameObject);
PointC = Instantiate(GameObject.Find("po3").gameObject);
PointD = Instantiate(GameObject.Find("po3").gameObject);
PointA.transform.position = Bundle_Test.QRpose + new Vector3(0.05f, 0.05f, 0f);
PointB.transform.position = QRimage.transform.position + new Vector3(0.05f, 0.05f, 0f);
PointC.transform.position = Bundle_Test.QRpose + new Vector3(-0.05f, -0.05f, 0f);
PointD.transform.position = QRimage.transform.position + new Vector3(-0.05f, -0.05f, 0f);
CaculateAndRotate();
openmesh(GameObject.Find("1fv1(Clone)"));
openrenderer(GameObject.Find("1fv1(Clone)"));
ModelMaganer.Loadobj = 2;*/
Instantiate(GameObject.Find("po1").gameObject, Bundle_Test.QRpose + new Vector3(0.05f, 0.05f, 0f), new Quaternion(0, 0, 0, 0));
//Box = Instantiate(GameObject.Find("LocationManager").transform.GetChild(1).gameObject, Ian.transform.position + new Vector3(0.05f, 0.05f, 0f), new Quaternion(0, 0, 0, 0));
}
}
}
public static void ModelLocation()
{
GameObject QRimage = GameObject.Find("getCKEditorImage").gameObject;
Debug.Log(QRimage.name);
RaycastHit hitInfo;
if (Physics.Raycast(
Camera.main.transform.position,
Camera.main.transform.forward,
out hitInfo,
20.0f,
Physics.DefaultRaycastLayers))
{
if (Points == 1)
{
Debug.Log("1");
PointA = Instantiate(GameObject.Find("LocationManager").transform.GetChild(0).gameObject);
PointA.SetActive(true);
PointA.transform.position = hitInfo.point;
PointA.transform.parent = GameObject.Find("LocationManager").transform;
/* foreach (Transform child in thismdll.transform)
{
foreach (Transform childin in child.transform)
{
if (childin.gameObject.GetComponent<MeshCollider>() == true)
{
childin.gameObject.GetComponent<MeshCollider>().enabled = true;
}
}
}*/
openmesh(GameObject.Find("1fv1(Clone)"));
openrenderer(GameObject.Find("1fv1(Clone)"));
Debug.Log("QQ");
Instantiate(GameObject.Find("po2").gameObject, QRimage.transform.position + new Vector3(0.05f, 0.05f, 0f), new Quaternion(0, 0, 0, 0));
Points++;
return;
}
if (Points == 2)
{
Debug.Log("2");
PointB = Instantiate(GameObject.Find("LocationManager").transform.GetChild(0).gameObject);
PointB.SetActive(true);
PointB.transform.position = hitInfo.point;
PointB.transform.parent = GameObject.Find("LocationManager").transform;
/* foreach (Transform child in thismdll.transform)
{
foreach (Transform childin in child.transform)
{
if (childin.gameObject.GetComponent<MeshCollider>() == true)
{
childin.gameObject.GetComponent<MeshCollider>().enabled = false;
}
}
}*/
closemesh(GameObject.Find("1fv1(Clone)"));
closerenderer(GameObject.Find("1fv1(Clone)"));
Instantiate(GameObject.Find("po1").gameObject, Bundle_Test.QRpose + new Vector3(-0.05f, -0.05f, 0f), new Quaternion(0, 0, 0, 0));
Points++;
return;
}
if (Points == 3)
{
Debug.Log("3");
PointC = Instantiate(GameObject.Find("LocationManager").transform.GetChild(0).gameObject);
PointC.SetActive(true);
PointC.transform.position = hitInfo.point;
PointC.transform.parent = GameObject.Find("LocationManager").transform;
Instantiate(GameObject.Find("po2").gameObject, QRimage.transform.position + new Vector3(-0.05f, -0.05f, 0f), new Quaternion(0, 0, 0, 0));
openmesh(GameObject.Find("1fv1(Clone)"));
openrenderer(GameObject.Find("1fv1(Clone)"));
Points++;
return;
}
if (Points == 4)
{
Debug.Log("4");
PointD = Instantiate(GameObject.Find("LocationManager").transform.GetChild(0).gameObject);
PointD.SetActive(true);
PointD.transform.position = hitInfo.point;
PointD.transform.parent = GameObject.Find("LocationManager").transform;
//RecordAllPoints(thismdll);
//GameObject.Find("Button_Location").transform.GetChild(5).gameObject.SetActive(false);
CaculateAndRotate();
GameObject.Find("Textguide").GetComponent<Text>().enabled= false;
//RecordAllPoints(thismdll);
Debug.Log(ModelMaganer.mdlobjList);
ModelMaganer.Loadobj = 2;
return;
}
}
}
public static void CaculateAndRotate()
{
Vba = PointA.transform.position - PointB.transform.position;
//Vab[1] = 0;
PointB.transform.position = PointB.transform.position + Vba;
PointD.transform.position = PointD.transform.position + Vba;
Vac = PointC.transform.position - PointA.transform.position;
Vbd = PointD.transform.position - PointB.transform.position;
Vac.y = 0;
Vbd.y = 0;
Debug.Log(Vac + " , " + Vbd);
angle = Vector3.Angle(Vbd, Vac);
GameObject ModelBox = new GameObject();
ModelBox.transform.position = PointA.transform.position;
GameObject BIM = GameObject.Find("1fv1(Clone)");
BIM.transform.parent = ModelBox.transform;
BIM.transform.position = BIM.transform.position + Vba;
Vector3 bdcrossac = Vector3.Cross(Vbd, Vac);
float Crossresult = Vector3.Dot(bdcrossac, Vector3.up);
Debug.Log(Crossresult);
if (Crossresult >= 0)
{
ModelBox.transform.eulerAngles = new Vector3(ModelBox.transform.eulerAngles.x, ModelBox.transform.eulerAngles.y + angle, ModelBox.transform.eulerAngles.z);
}
else
{
ModelBox.transform.eulerAngles = new Vector3(ModelBox.transform.eulerAngles.x, ModelBox.transform.eulerAngles.y - angle, ModelBox.transform.eulerAngles.z);
}
BIM.transform.parent = null;
CleanAllPoints();
GameObject.Find("QRCODE").SendMessage("Locater");
GameObject.Destroy(ModelBox);
}
public static void CleanAllPoints()
{
foreach (GameObject CountBall in GameObject.FindGameObjectsWithTag("LocatePoint"))
{
Destroy(CountBall);
}
Points = 1;
foreach (GameObject CountB in GameObject.FindGameObjectsWithTag("po"))
{
Destroy(CountB);
}
//Destroy(GameObject.Find("po2(Clone)"));
}
public static void openmesh(GameObject abc)
{
if (null == abc)
return;
foreach (Transform child in abc.transform)
{
if (null == abc)
continue;
if (child.gameObject.GetComponent<MeshCollider>() == true)
{
child.gameObject.GetComponent<MeshCollider>().enabled = true;
}
openmesh(child.gameObject);
}
}
public static void openrenderer(GameObject abc)
{
if (null == abc)
return;
foreach (Transform child in abc.transform)
{
if (null == abc)
continue;
if (child.gameObject.GetComponent<MeshRenderer>() == true)
{
child.gameObject.GetComponent<MeshRenderer>().enabled = true;
}
if (child.gameObject.GetComponent<SpriteRenderer>() == true)
{
child.gameObject.GetComponent<SpriteRenderer>().enabled = true;
}
openrenderer(child.gameObject);
}
}
public static void closemesh(GameObject abc)
{
if (null == abc)
return;
foreach (Transform child in abc.transform)
{
if (null == abc)
continue;
if (child.gameObject.GetComponent<MeshCollider>() == true)
{
child.gameObject.GetComponent<MeshCollider>().enabled = false;
}
closemesh(child.gameObject);
}
}
public static void closerenderer(GameObject abc)
{
if (null == abc)
return;
foreach (Transform child in abc.transform)
{
if (null == abc)
continue;
if (child.gameObject.GetComponent<MeshRenderer>() == true)
{
child.gameObject.GetComponent<MeshRenderer>().enabled = false;
}
if (child.gameObject.GetComponent<SpriteRenderer>() == true)
{
child.gameObject.GetComponent<SpriteRenderer>().enabled = false;
}
closerenderer(child.gameObject);
}
}
public void Locater()
{
if (Location.Equals(false))
{
//transform.GetChild(0).GetComponent<MeshRenderer>().material.color = new Color(0.6f, 0.6f, 0.6f, 0.6f);
//LuisManager.instance.LUISFeedback.text = "LUIS:OK,I already turn on Location Function";
Location = true;
GameObject.Find("MainCamera").transform.GetChild(0).gameObject.SetActive(true);
closerenderer(GameObject.Find("1fv1(Clone)"));
foreach (Transform child in GameObject.Find("1fv1(Clone)").transform)
{
foreach (Transform childin in child.transform)
{
if (childin.gameObject.GetComponent<MeshCollider>() == true)
{
childin.gameObject.GetComponent<MeshCollider>().enabled = false;
}
}
}
return;
}
if (Location.Equals(true))
{
//transform.GetChild(0).GetComponent<MeshRenderer>().material = GameObject.Find("Material").transform.GetChild(0).GetComponent<MeshRenderer>().material;
Set_Model.CleanAllPoints();
GameObject.Find("MainCamera").transform.GetChild(0).gameObject.SetActive(false);
//LuisManager.instance.LUISFeedback.text = "The Location Function is off";
Location = false;
return;
}
}
public void Update()
{
if (Location.Equals(true))
{
if (Physics.Raycast(
Camera.main.transform.position,
Camera.main.transform.forward,
out hitInf,
20.0f,
Physics.DefaultRaycastLayers))
{
GameObject.Find("MainCamera").transform.GetChild(0).gameObject.transform.position = hitInf.point;
distance = (Camera.main.transform.position - hitInf.point).magnitude;
if (distance < 0.8f)
{
GameObject.Find("MainCamera").transform.GetChild(0).gameObject.transform.localScale = new Vector3(0.01f, 0.01f, 0.01f);
}
else if (distance > 0.8f)
{
GameObject.Find("MainCamera").transform.GetChild(0).gameObject.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
}
}
}
}
// Start is called before the first frame update
void Start()
{
}
}