Skip to content

Commit b9abf1e

Browse files
author
David Kline
authored
Merge pull request #2985 from keveleigh/QRCodeNonWSABuild
Added #if blocks to QR code preview feature
2 parents 2c52acb + f520b57 commit b9abf1e

File tree

5 files changed

+80
-65
lines changed

5 files changed

+80
-65
lines changed

Assets/HoloToolkit-Preview/QRTracker/Scripts/AttachToQRCode.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
using System.Collections;
54
using System.Collections.Generic;
65
using UnityEngine;
7-
using QRCodesTrackerPlugin;
86

97
namespace HoloToolkit.Unity.QRTracking
108
{
@@ -18,6 +16,7 @@ public class AttachToQRCode : MonoBehaviour
1816
private bool updatedId = false;
1917

2018
private SpatialGraphCoordinateSystem coordSystem = null;
19+
2120
/// <summary>
2221
/// Data of the QR code to which we want to attach the game object."
2322
/// </summary>
@@ -39,9 +38,11 @@ public string QRCodeData
3938
{
4039
qRCodeData = string.Empty;
4140
}
42-
41+
42+
#if UNITY_EDITOR || UNITY_WSA
4343
qrCodeId = QRCodesManager.Instance.GetIdForQRCode(qRCodeData);
4444
updatedId = true;
45+
#endif // UNITY_EDITOR || UNITY_WSA
4546
}
4647
}
4748
}
@@ -50,9 +51,11 @@ public string QRCodeData
5051

5152
private void Awake()
5253
{
54+
#if UNITY_EDITOR || UNITY_WSA
5355
QRCodesManager.Instance.QRCodeAdded += Instance_QRCodeAdded;
5456
QRCodesManager.Instance.QRCodeUpdated += Instance_QRCodeUpdated;
5557
QRCodesManager.Instance.QRCodeRemoved += Instance_QRCodeRemoved;
58+
#endif // UNITY_EDITOR || UNITY_WSA
5659
}
5760

5861
private void Start()
@@ -62,10 +65,14 @@ private void Start()
6265
// default use the scripts object
6366
gameObjectToAttach = gameObject;
6467
}
68+
69+
#if UNITY_EDITOR || UNITY_WSA
6570
qrCodeId = QRCodesManager.Instance.GetIdForQRCode(qRCodeData);
6671
updatedId = true;
72+
#endif // UNITY_EDITOR || UNITY_WSA
6773
}
6874

75+
#if UNITY_EDITOR || UNITY_WSA
6976
private void Instance_QRCodeAdded(object sender, QRCodeEventArgs<QRCodesTrackerPlugin.QRCode> e)
7077
{
7178
if (qrCodeId == System.Guid.Empty)
@@ -115,5 +122,6 @@ private void Update()
115122
updatedId = false;
116123
}
117124
}
125+
#endif // UNITY_EDITOR || UNITY_WSA
118126
}
119127
}

Assets/HoloToolkit-Preview/QRTracker/Scripts/QRCode.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
using System.Collections;
5-
using System.Collections.Generic;
64
using UnityEngine;
75

8-
#if WINDOWS_UWP
9-
using Windows.Perception.Spatial;
10-
#endif
11-
126
namespace HoloToolkit.Unity.QRTracking
137
{
14-
[RequireComponent(typeof(HoloToolkit.Unity.SpatialGraphCoordinateSystem))]
8+
[RequireComponent(typeof(SpatialGraphCoordinateSystem))]
159
public class QRCode : MonoBehaviour
1610
{
11+
#if UNITY_EDITOR || UNITY_WSA
1712
public QRCodesTrackerPlugin.QRCode qrCode;
18-
private GameObject qrCodeCube;
19-
13+
#endif // UNITY_EDITOR || UNITY_WSA
2014
public float PhysicalSize;
2115
public string CodeText { get; set; }
2216

@@ -26,13 +20,16 @@ public class QRCode : MonoBehaviour
2620
private TextMesh QRTimeStamp;
2721
private TextMesh QRSize;
2822
private GameObject QRInfo;
23+
private GameObject qrCodeCube;
2924

3025
private long lastTimeStamp = 0;
3126

3227
private void Start()
3328
{
3429
PhysicalSize = 0.1f;
3530
CodeText = "Dummy";
31+
32+
#if UNITY_EDITOR || UNITY_WSA
3633
if (qrCode == null)
3734
{
3835
throw new System.Exception("QR Code Empty");
@@ -55,7 +52,15 @@ private void Start()
5552
QRSize.text = "Size:" + qrCode.PhysicalSizeMeters.ToString("F04") + "m";
5653
QRTimeStamp.text = "Time:" + qrCode.LastDetectedQPCTicks;
5754
Debug.Log("Id= " + qrCode.Id + " PhysicalSize = " + PhysicalSize + " TimeStamp = " + qrCode.LastDetectedQPCTicks + " QRVersion = " + qrCode.Version + " QRData = " + CodeText);
55+
#endif // UNITY_EDITOR || UNITY_WSA
56+
}
57+
58+
private void Update()
59+
{
60+
#if UNITY_EDITOR || UNITY_WSA
61+
UpdatePropertiesDisplay();
5862
}
63+
5964
private void UpdatePropertiesDisplay()
6065
{
6166
// Update properties that change
@@ -79,11 +84,7 @@ private void UpdatePropertiesDisplay()
7984
lastTimeStamp = qrCode.LastDetectedQPCTicks;
8085
QRInfo.transform.localScale = new Vector3(PhysicalSize/0.2f, PhysicalSize / 0.2f, PhysicalSize / 0.2f);
8186
}
82-
}
83-
84-
private void Update()
85-
{
86-
UpdatePropertiesDisplay();
87+
#endif // UNITY_EDITOR || UNITY_WSA
8788
}
8889
}
8990
}

Assets/HoloToolkit-Preview/QRTracker/Scripts/QRCodesManager.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using System;
5-
using System.Collections;
6-
75
using System.Collections.Generic;
8-
96
using UnityEngine;
107

8+
#if UNITY_EDITOR || UNITY_WSA
119
using QRCodesTrackerPlugin;
10+
#endif // UNITY_EDITOR || UNITY_WSA
11+
1212
namespace HoloToolkit.Unity.QRTracking
1313
{
1414
public static class QRCodeEventArgs
@@ -36,18 +36,19 @@ public class QRCodesManager : Singleton<QRCodesManager>
3636
public bool AutoStartQRTracking = true;
3737

3838
public bool IsTrackerRunning { get; private set; }
39-
public QRCodesTrackerPlugin.QRTrackerStartResult StartResult { get; private set; }
4039

40+
#if UNITY_EDITOR || UNITY_WSA
41+
public QRTrackerStartResult StartResult { get; private set; }
4142

4243
public event EventHandler<QRCodeEventArgs<QRCodesTrackerPlugin.QRCode>> QRCodeAdded;
4344
public event EventHandler<QRCodeEventArgs<QRCodesTrackerPlugin.QRCode>> QRCodeUpdated;
4445
public event EventHandler<QRCodeEventArgs<QRCodesTrackerPlugin.QRCode>> QRCodeRemoved;
4546

46-
private System.Collections.Generic.SortedDictionary<System.Guid, QRCodesTrackerPlugin.QRCode> qrCodesList = new SortedDictionary<System.Guid, QRCodesTrackerPlugin.QRCode>();
47+
private SortedDictionary<Guid, QRCodesTrackerPlugin.QRCode> qrCodesList = new SortedDictionary<Guid, QRCodesTrackerPlugin.QRCode>();
4748

4849
private QRTracker qrTracker;
4950

50-
public System.Guid GetIdForQRCode(string qrCodeData)
51+
public Guid GetIdForQRCode(string qrCodeData)
5152
{
5253
lock (qrCodesList)
5354
{
@@ -59,16 +60,17 @@ public System.Guid GetIdForQRCode(string qrCodeData)
5960
}
6061
}
6162
}
62-
return System.Guid.Empty;
63+
return Guid.Empty;
6364
}
6465

65-
public System.Collections.Generic.IList<QRCodesTrackerPlugin.QRCode> GetList()
66+
public IList<QRCodesTrackerPlugin.QRCode> GetList()
6667
{
6768
lock (qrCodesList)
6869
{
6970
return new List<QRCodesTrackerPlugin.QRCode>(qrCodesList.Values);
7071
}
7172
}
73+
#endif // UNITY_EDITOR || UNITY_WSA
7274

7375
protected override void Awake()
7476
{
@@ -78,6 +80,7 @@ protected override void Awake()
7880

7981
protected virtual void Start()
8082
{
83+
#if UNITY_EDITOR || UNITY_WSA
8184
qrTracker = new QRTracker();
8285
qrTracker.Added += QrTracker_Added;
8386
qrTracker.Updated += QrTracker_Updated;
@@ -87,8 +90,10 @@ protected virtual void Start()
8790
{
8891
StartQRTracking();
8992
}
93+
#endif // UNITY_EDITOR || UNITY_WSA
9094
}
9195

96+
#if UNITY_EDITOR || UNITY_WSA
9297
public QRTrackerStartResult StartQRTracking()
9398
{
9499
if (!IsTrackerRunning)
@@ -150,7 +155,6 @@ private void QrTracker_Added(QRCodeAddedEventArgs args)
150155
handlers(this, QRCodeEventArgs.Create(args.Code));
151156
}
152157
}
153-
158+
#endif // UNITY_EDITOR || UNITY_WSA
154159
}
155-
156160
}

Assets/HoloToolkit-Preview/QRTracker/Scripts/QRCodesVisualizer.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
using System.Collections;
5-
64
using System.Collections.Generic;
7-
85
using UnityEngine;
96

10-
using QRCodesTrackerPlugin;
117
namespace HoloToolkit.Unity.QRTracking
128
{
139
public class QRCodesVisualizer : MonoBehaviour
1410
{
1511
public GameObject qrCodePrefab;
1612

1713
private SortedDictionary<System.Guid, GameObject> qrCodesObjectsList;
18-
19-
struct ActionData
14+
15+
#if UNITY_EDITOR || UNITY_WSA
16+
private struct ActionData
2017
{
2118
public enum Type
2219
{
@@ -35,12 +32,16 @@ public ActionData(Type type, QRCodesTrackerPlugin.QRCode qRCode) : this()
3532
}
3633

3734
private Queue<ActionData> pendingActions = new Queue<ActionData>();
35+
#endif // UNITY_EDITOR || UNITY_WSA
36+
3837
private void Awake()
3938
{
39+
#if UNITY_EDITOR || UNITY_WSA
4040
qrCodesObjectsList = new SortedDictionary<System.Guid, GameObject>();
4141
QRCodesManager.Instance.QRCodeAdded += Instance_QRCodeAdded;
4242
QRCodesManager.Instance.QRCodeUpdated += Instance_QRCodeUpdated;
4343
QRCodesManager.Instance.QRCodeRemoved += Instance_QRCodeRemoved;
44+
#endif // UNITY_EDITOR || UNITY_WSA
4445
}
4546

4647
private void Start()
@@ -51,6 +52,12 @@ private void Start()
5152
}
5253
}
5354

55+
#if UNITY_EDITOR || UNITY_WSA
56+
private void Update()
57+
{
58+
HandleEvents();
59+
}
60+
5461
private void Instance_QRCodeAdded(object sender, QRCodeEventArgs<QRCodesTrackerPlugin.QRCode> e)
5562
{
5663
lock (pendingActions)
@@ -105,11 +112,6 @@ private void HandleEvents()
105112
}
106113
}
107114
}
108-
109-
private void Update()
110-
{
111-
HandleEvents();
112-
}
115+
#endif // UNITY_EDITOR || UNITY_WSA
113116
}
114-
115117
}

0 commit comments

Comments
 (0)