-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathInvitationAcceptanceHandlerMotif.cs
77 lines (67 loc) · 2.61 KB
/
InvitationAcceptanceHandlerMotif.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
// Copyright (c) Meta Platforms, Inc. and affiliates.
using System.Collections.Generic;
using UnityEngine;
using Oculus.Platform;
using Oculus.Platform.BuildingBlocks;
using UnityEngine.SceneManagement;
namespace MRMotifs.SharedActivities.QuestPlatform
{
/// <summary>
/// The InvitationAcceptanceHandlerMotif class handles deep link invitations using the Oculus Platform SDK.
/// When the application is launched via a deep link (e.g., an invitation from a friend), it checks the launch
/// details to determine if the user should be directed to a specific destination.
/// </summary>
public class InvitationAcceptanceHandlerMotif : MonoBehaviour
{
[SerializeField] private EntitlementCheck entitlementCheck;
[Header("Destination API Names and their Scenes")]
[Tooltip("A list of API to Scene mappings.")]
[SerializeField]
private List<ApiToSceneMapping> apiToSceneMappings = new();
private Dictionary<string, string> m_apiToSceneMap;
private void Awake()
{
entitlementCheck.UserPassedEntitlementCheck += HandleDeepLinkInvitation;
InitializeApiToSceneMap();
}
private void InitializeApiToSceneMap()
{
m_apiToSceneMap = new Dictionary<string, string>();
foreach (var mapping in apiToSceneMappings)
{
if (!m_apiToSceneMap.ContainsKey(mapping.apiName))
{
m_apiToSceneMap.Add(mapping.apiName, mapping.sceneName);
}
}
}
private void HandleDeepLinkInvitation()
{
var launchDetails = ApplicationLifecycle.GetLaunchDetails();
if (launchDetails.LaunchType == LaunchType.Deeplink)
{
Debug.Log("App was launched via a deep link invitation.");
var destinationApiName = launchDetails.DestinationApiName;
if (m_apiToSceneMap.TryGetValue(destinationApiName, out var sceneName))
{
SceneManager.LoadSceneAsync(sceneName);
Debug.Log($"Connecting to {sceneName} session automatically via Auto-matchmaking.");
}
else
{
Debug.LogWarning("Unknown destination for deep link: " + destinationApiName);
}
}
else
{
Debug.Log("No deep link invitation detected.");
}
}
}
[System.Serializable]
public class ApiToSceneMapping
{
public string apiName;
public string sceneName;
}
}