-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathInvitationAcceptanceHandlerMotif.cs
91 lines (81 loc) · 3.06 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* Licensed under the Oculus SDK License Agreement (the "License");
* you may not use the Oculus SDK except in compliance with the License,
* which is provided at the time of installation or download, or which
* otherwise accompanies this software in either electronic or hard copy form.
*
* You may obtain a copy of the License at
*
* https://developer.oculus.com/licenses/oculussdk/
*
* Unless required by applicable law or agreed to in writing, the Oculus SDK
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System.Collections.Generic;
using UnityEngine;
using Oculus.Platform;
using Oculus.Platform.BuildingBlocks;
using UnityEngine.SceneManagement;
/// <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> _apiToSceneMap;
private void Awake()
{
entitlementCheck.UserPassedEntitlementCheck += HandleDeepLinkInvitation;
InitializeApiToSceneMap();
}
private void InitializeApiToSceneMap()
{
_apiToSceneMap = new Dictionary<string, string>();
foreach (var mapping in apiToSceneMappings)
{
if (!_apiToSceneMap.ContainsKey(mapping.apiName))
{
_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 (_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;
}