This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
/
MobileClientWorkerConnector.cs
83 lines (68 loc) · 2.67 KB
/
MobileClientWorkerConnector.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
using System;
using Improbable.Gdk.Core;
using Improbable.Gdk.Mobile;
using UnityEngine;
namespace Playground
{
public class MobileClientWorkerConnector : WorkerConnector, MobileConnectionFlowInitializer.IMobileSettingsProvider
{
#pragma warning disable 649
[SerializeField] private GameObject level;
[SerializeField] private string ipAddress;
#pragma warning restore 649
private GameObject levelInstance;
public async void Start()
{
var connParams = CreateConnectionParameters(WorkerUtils.MobileClient, new MobileConnectionParametersInitializer());
var flowInitializer = new MobileConnectionFlowInitializer(
new MobileConnectionFlowInitializer.CommandLineSettingsProvider(),
new MobileConnectionFlowInitializer.PlayerPrefsSettingsProvider(),
this);
var builder = new SpatialOSConnectionHandlerBuilder()
.SetConnectionParameters(connParams);
switch (flowInitializer.GetConnectionService())
{
case ConnectionService.Receptionist:
builder.SetConnectionFlow(new ReceptionistFlow(CreateNewWorkerId(WorkerUtils.MobileClient),
flowInitializer));
break;
case ConnectionService.Locator:
builder.SetConnectionFlow(new LocatorFlow(flowInitializer));
break;
default:
throw new ArgumentException("Received unsupported connection service.");
}
await Connect(builder, new ForwardingDispatcher()).ConfigureAwait(false);
}
protected override void HandleWorkerConnectionEstablished()
{
WorkerUtils.AddClientSystems(Worker.World);
if (level == null)
{
return;
}
levelInstance = Instantiate(level, transform.position, transform.rotation);
}
public override void Dispose()
{
if (levelInstance != null)
{
Destroy(levelInstance);
}
base.Dispose();
}
public Option<string> GetReceptionistHostIp()
{
return string.IsNullOrEmpty(ipAddress) ? Option<string>.Empty : new Option<string>(ipAddress);
}
public Option<string> GetDevAuthToken()
{
var token = Resources.Load<TextAsset>("DevAuthToken")?.text.Trim();
return token ?? Option<string>.Empty;
}
public Option<ConnectionService> GetConnectionService()
{
return Option<ConnectionService>.Empty;
}
}
}