-
Notifications
You must be signed in to change notification settings - Fork 0
/
CloudHandler.cs
79 lines (72 loc) · 2.58 KB
/
CloudHandler.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
using Vuforia;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CloudHandler : MonoBehaviour, ICloudRecoEventHandler {
private CloudRecoBehaviour mCloudRecoBehaviour;
private bool mIsScanning = false;
private string mTargetMetadata = "";
public ImageTargetBehaviour ImageTargetTemplate;
public BlockMove B;
public GameObject welcome;
// Use this for initialization
void Start () {
// register this event handler at the cloud reco behaviour
mCloudRecoBehaviour = GetComponent<CloudRecoBehaviour>();
if (mCloudRecoBehaviour)
{
mCloudRecoBehaviour.RegisterEventHandler(this);
}
welcome.SetActive (false);
}
public void OnInitialized() {
Debug.Log ("Cloud Reco initialized");
}
public void OnInitError(TargetFinder.InitState initError) {
Debug.Log ("Cloud Reco init error " + initError.ToString());
}
public void OnUpdateError(TargetFinder.UpdateState updateError) {
Debug.Log ("Cloud Reco update error " + updateError.ToString());
}
public void OnStateChanged(bool scanning) {
mIsScanning = scanning;
if (scanning)
{
welcome.SetActive (false);
// clear all known trackables
var tracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
tracker.TargetFinder.ClearTrackables(false);
}
}
// Here we handle a cloud target recognition event
public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult) {
// do something with the target metadata
mTargetMetadata = targetSearchResult.MetaData;
// stop the target finder (i.e. stop scanning the cloud)
mCloudRecoBehaviour.CloudRecoEnabled = false;
if (ImageTargetTemplate) {
// enable the new result with the same ImageTargetBehaviour:
ObjectTracker tracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
ImageTargetBehaviour imageTargetBehaviour =
(ImageTargetBehaviour)tracker.TargetFinder.EnableTracking(
targetSearchResult, ImageTargetTemplate.gameObject);
}
B.targetFound (mTargetMetadata);
//UAuth Au = GameObject.Find("Auth").GetComponent<UAuth>();
}
void OnGUI() {
// Display current 'scanning' status
// GUI.Box (new Rect(100,100,200,50), mIsScanning ? "Scanning" : "Not scanning");
// Display metadata of latest detected cloud-target
welcome.SetActive(true);
//GUI.Box (new Rect(100,200,200,50), "Metadata: " + mTargetMetadata);
// If not scanning, show button
// so that user can restart cloud scanning
// if (!mIsScanning) {
// if (GUI.Button(new Rect(100,300,200,50), "Restart Scanning")) {
// // Restart TargetFinder
// mCloudRecoBehaviour.CloudRecoEnabled = true;
// }
// }
}
}