Skip to content

Commit

Permalink
Merge pull request #8 from realitycollective/feature/arfoundation6
Browse files Browse the repository at this point in the history
Updating for ARFoundation 6 support
  • Loading branch information
SimonDarksideJ authored Jun 13, 2024
2 parents 26f6d69 + 580521e commit ce8d982
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class ARFoundationSpatialPersistenceServiceImageTrackingModule : BaseSpat
private bool isStarted = false;
private bool isStarting = false;

private bool hasValidTrackingProfile => profile.IsNotNull() && profile.TrackedImagesLibrary.IsNotNull();

private ARTrackedImageManager TrackedImageManager
{
get
Expand Down Expand Up @@ -107,7 +109,12 @@ public override Task StartSpatialPersistenceModule()
runtimeImageLibrary = TrackedImageManager.referenceLibrary as MutableRuntimeReferenceImageLibrary;
DynamicLibraryManager.OnImageLoaded += OnImageLoaded;
DynamicLibraryManager.OnImageLoadFailed += OnImageLoadFailed;

#if ARFOUNDATION_6
TrackedImageManager.trackablesChanged.AddListener(OnTrackedImagesChanged);
#else
TrackedImageManager.trackedImagesChanged += OnTrackedImagesChanged;
#endif
if (profile.TrackedImagesLibrary.IsNotNull() && profile.TrackedImagesLibrary.TrackedImages != null)
{
DynamicLibraryManager.ProcessImages(runtimeImageLibrary, profile.TrackedImagesLibrary.TrackedImages);
Expand All @@ -125,7 +132,11 @@ public override void StopSpatialPersistenceModule()
{
if (TrackedImageManager != null)
{
#if ARFOUNDATION_6
TrackedImageManager.trackablesChanged.RemoveListener(OnTrackedImagesChanged);
#else
TrackedImageManager.trackedImagesChanged -= OnTrackedImagesChanged;
#endif
}
OnSessionEnded();
}
Expand Down Expand Up @@ -172,7 +183,7 @@ private IEnumerator AddToLibrary(MutableRuntimeReferenceImageLibrary mutableLibr
{
if (mutableLibrary is null)
{
OnSpatialPersistenceError($"Library is inaccessble.");
OnSpatialPersistenceError($"Library is inaccessible.");
yield return null;
}
if (trackedImageIds.Contains(anchorGuid))
Expand All @@ -194,7 +205,11 @@ private IEnumerator AddToLibrary(MutableRuntimeReferenceImageLibrary mutableLibr
dynamicLibraryManager.ProcessImage(mutableLibrary, anchorGuid, texture, url);
}

#if ARFOUNDATION_6
private void OnTrackedImagesChanged(ARTrackablesChangedEventArgs<ARTrackedImage> trackedImage)
#else
private void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs trackedImage)
#endif
{
foreach (var newImage in trackedImage.added)
{
Expand Down Expand Up @@ -223,7 +238,7 @@ private void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs trackedImage
if (trackedImageIds.Contains(updatedImage.referenceImage.guid))
{
Guid refGuid = updatedImage.referenceImage.guid;
if(trackedImageReferences.TryGetValue(updatedImage.referenceImage.guid, out var trackedGuid))
if (trackedImageReferences.TryGetValue(updatedImage.referenceImage.guid, out var trackedGuid))
{
refGuid = trackedGuid;
}
Expand All @@ -235,7 +250,11 @@ private void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs trackedImage
}
}

#if ARFOUNDATION_6
foreach (var (id, removedImage) in trackedImage.removed)
#else
foreach (var removedImage in trackedImage.removed)
#endif
{
if (trackedImageIds.Contains(removedImage.referenceImage.guid))
{
Expand All @@ -256,7 +275,7 @@ private void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs trackedImage

private void OnImageLoaded(ARFoundationTrackedImageData data)
{
if(profile.TrackedImagesLibrary.GetTrackedImageByName(data.Name) == null)
if (hasValidTrackingProfile && profile.TrackedImagesLibrary.GetTrackedImageByName(data.Name) == null)
{
profile.TrackedImagesLibrary.AddTrackedImageData(data);
}
Expand Down
16 changes: 14 additions & 2 deletions Runtime/RealityToolkit.SpatialPersistence.ARFoundation.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"GUID:b2d046948d6452a4b8485efc9ce0f88c",
"GUID:c148ca4f0506aba4bb7c9e15a44bf2e3",
"GUID:a9420e37d7990b54abdef6688edbe313",
"GUID:92703082f92b41ba80f0d6912de66115"
"GUID:92703082f92b41ba80f0d6912de66115",
"GUID:dc960734dc080426fa6612f1c5fe95f3"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand All @@ -16,6 +17,17 @@
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"versionDefines": [
{
"name": "com.unity.xr.arfoundation",
"expression": "6.0.0",
"define": "ARFOUNDATION_6"
},
{
"name": "com.unity.xr.arfoundation",
"expression": "[4.0.0,5.2.0]",
"define": "ARFOUNDATION_4"
}
],
"noEngineReferences": false
}

0 comments on commit ce8d982

Please sign in to comment.