Skip to content

Commit 4d24f9e

Browse files
committed
Adding saving and loading of UUIDs to PlayerPrefs
1 parent a48f23b commit 4d24f9e

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

Assets/Scripts/TrajectoryPlanner/TrajectoryPlannerManager.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,15 @@ public async void CheckForSavedProbes(Task annotationDatasetLoadTask)
262262

263263
private void LoadSavedProbes()
264264
{
265-
var savedProbes = localPrefs.LoadSavedProbes();
265+
var savedProbes = localPrefs.LoadSavedProbeData();
266266

267267
foreach (var savedProbe in savedProbes)
268268
{
269269
var probeInsertion = new ProbeInsertion(savedProbe.apmldv, savedProbe.angles,
270270
coordinateSpaceOpts[savedProbe.coordinateSpaceName], coordinateTransformOpts[savedProbe.coordinateTransformName]);
271271
AddNewProbeTransformed(savedProbe.type, probeInsertion,
272272
savedProbe.manipulatorId, savedProbe.zeroCoordinateOffset, savedProbe.brainSurfaceOffset,
273-
savedProbe.dropToSurfaceWithDepth);
273+
savedProbe.dropToSurfaceWithDepth, savedProbe.uuid);
274274
}
275275

276276
UpdateQuickSettings();
@@ -488,9 +488,14 @@ public ProbeManager AddNewProbe(int probeType)
488488
}
489489

490490
public ProbeManager AddNewProbeTransformed(int probeType, ProbeInsertion insertion,
491-
int manipulatorId, Vector4 zeroCoordinateOffset, float brainSurfaceOffset, bool dropToSurfaceWithDepth)
491+
int manipulatorId, Vector4 zeroCoordinateOffset, float brainSurfaceOffset, bool dropToSurfaceWithDepth,
492+
string uuid = null)
492493
{
493494
ProbeManager probeManager = AddNewProbe(probeType);
495+
496+
if (uuid != null)
497+
probeManager.OverrideUUID(uuid);
498+
494499
if (!PlayerPrefs.IsLinkDataExpired())
495500
{
496501
probeManager.SetZeroCoordinateOffset(zeroCoordinateOffset);
@@ -1085,7 +1090,8 @@ private void OnApplicationQuit()
10851090
new (Vector3 apmldv, Vector3 angles,
10861091
int type, int manipulatorId,
10871092
string coordinateSpace, string coordinateTransform,
1088-
Vector4 zeroCoordinateOffset, float brainSurfaceOffset, bool dropToSurfaceWithDepth)[allProbeManagers.Count];
1093+
Vector4 zeroCoordinateOffset, float brainSurfaceOffset, bool dropToSurfaceWithDepth,
1094+
string uuid)[allProbeManagers.Count];
10891095

10901096
for (int i =0; i< allProbeManagers.Count; i++)
10911097
{
@@ -1095,7 +1101,8 @@ private void OnApplicationQuit()
10951101
probeInsertion.angles,
10961102
probe.ProbeType, probe.GetManipulatorId(),
10971103
probeInsertion.CoordinateSpace.Name, probeInsertion.CoordinateTransform.Name,
1098-
probe.GetZeroCoordinateOffset(), probe.GetBrainSurfaceOffset(), probe.IsSetToDropToSurfaceWithDepth());
1104+
probe.GetZeroCoordinateOffset(), probe.GetBrainSurfaceOffset(), probe.IsSetToDropToSurfaceWithDepth(),
1105+
probe.UUID);
10991106
}
11001107
localPrefs.SaveCurrentProbeData(probeCoordinates);
11011108
}

Assets/Scripts/TrajectoryPlanner/Utilities/PlayerPrefs.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,15 +405,17 @@ private void SaveVector3Pref(string prefStr, Vector3 value)
405405
public (Vector3 apmldv, Vector3 angles,
406406
int type, int manipulatorId,
407407
string coordinateSpaceName, string coordinateTransformName,
408-
Vector4 zeroCoordinateOffset, float brainSurfaceOffset, bool dropToSurfaceWithDepth)[] LoadSavedProbes()
408+
Vector4 zeroCoordinateOffset, float brainSurfaceOffset, bool dropToSurfaceWithDepth,
409+
string uuid)[] LoadSavedProbeData()
409410
{
410411
int probeCount = UnityEngine.PlayerPrefs.GetInt("probecount", 0);
411412

412413
var savedProbes =
413414
new (Vector3 apmldv, Vector3 angles,
414415
int type, int manipulatorId,
415416
string coordinateSpaceName, string coordinateTransformName,
416-
Vector4 zeroCoordinateOffset, float brainSurfaceOffset, bool dropToSurfaceWithDepth)[probeCount];
417+
Vector4 zeroCoordinateOffset, float brainSurfaceOffset, bool dropToSurfaceWithDepth,
418+
string uuid)[probeCount];
417419

418420
for (int i = 0; i < probeCount; i++)
419421
{
@@ -433,11 +435,13 @@ private void SaveVector3Pref(string prefStr, Vector3 value)
433435
var d = UnityEngine.PlayerPrefs.GetFloat("d" + i);
434436
var brainSurfaceOffset = UnityEngine.PlayerPrefs.GetFloat("brain_surface_offset" + i);
435437
var dropToSurfaceWithDepth = UnityEngine.PlayerPrefs.GetInt("drop_to_surface_with_depth" + i) == 1;
438+
string uuid = UnityEngine.PlayerPrefs.GetString("uuid" + i);
436439

437440
savedProbes[i] = (new Vector3(ap, ml, dv), new Vector3(phi, theta, spin),
438441
type, manipulatorId,
439442
coordSpaceName, coordTransName,
440-
new Vector4(x, y, z, d), brainSurfaceOffset, dropToSurfaceWithDepth);
443+
new Vector4(x, y, z, d), brainSurfaceOffset, dropToSurfaceWithDepth,
444+
uuid);
441445
}
442446

443447
return savedProbes;
@@ -451,7 +455,8 @@ public void SaveCurrentProbeData(
451455
(Vector3 apmldv, Vector3 angles,
452456
int type, int manipulatorId,
453457
string coordinateSpace, string coordinateTransform,
454-
Vector4 zeroCoordinateOffset, float brainSurfaceOffset, bool dropToSurfaceWithDepth)[] allProbeData)
458+
Vector4 zeroCoordinateOffset, float brainSurfaceOffset, bool dropToSurfaceWithDepth,
459+
string uuid)[] allProbeData)
455460
{
456461
for (int i = 0; i < allProbeData.Length; i++)
457462
{
@@ -474,6 +479,7 @@ public void SaveCurrentProbeData(
474479
UnityEngine.PlayerPrefs.SetFloat("brain_surface_offset" + i, allProbeData[i].brainSurfaceOffset);
475480
UnityEngine.PlayerPrefs.SetInt("drop_to_surface_with_depth" + i,
476481
allProbeData[i].dropToSurfaceWithDepth ? 1 : 0);
482+
UnityEngine.PlayerPrefs.SetString("uuid" + i, allProbeData[i].uuid);
477483
}
478484
UnityEngine.PlayerPrefs.SetInt("probecount", allProbeData.Length);
479485
UnityEngine.PlayerPrefs.SetString("timestamp",

0 commit comments

Comments
 (0)