This repository has been archived by the owner on Oct 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
/
GameLogicWorkerConnector.cs
77 lines (64 loc) · 2.52 KB
/
GameLogicWorkerConnector.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
using Fps.Config;
using Fps.Guns;
using Fps.Health;
using Fps.Metrics;
using Improbable.Gdk.Core;
using Improbable.Gdk.Core.Representation;
using Improbable.Gdk.GameObjectCreation;
using Improbable.Gdk.PlayerLifecycle;
using Improbable.Worker.CInterop;
using UnityEngine;
namespace Fps.WorkerConnectors
{
public class GameLogicWorkerConnector : WorkerConnectorBase
{
public bool DisableRenderers = true;
[SerializeField] private EntityRepresentationMapping entityRepresentationMapping;
protected async void Start()
{
Application.targetFrameRate = 60;
await Connect(GetConnectionHandlerBuilder(), new ForwardingDispatcher());
await LoadWorld();
if (DisableRenderers)
{
foreach (var childRenderer in LevelInstance.GetComponentsInChildren<Renderer>())
{
childRenderer.enabled = false;
}
}
}
private IConnectionHandlerBuilder GetConnectionHandlerBuilder()
{
IConnectionFlow connectionFlow;
ConnectionParameters connectionParameters;
var workerId = CreateNewWorkerId(WorkerUtils.UnityGameLogic);
if (Application.isEditor)
{
connectionFlow = new ReceptionistFlow(workerId);
connectionParameters = CreateConnectionParameters(WorkerUtils.UnityGameLogic);
}
else
{
connectionFlow = new ReceptionistFlow(workerId, new CommandLineConnectionFlowInitializer());
connectionParameters = CreateConnectionParameters(WorkerUtils.UnityGameLogic,
new CommandLineConnectionParameterInitializer());
}
return new SpatialOSConnectionHandlerBuilder()
.SetConnectionFlow(connectionFlow)
.SetConnectionParameters(connectionParameters);
}
protected override void HandleWorkerConnectionEstablished()
{
var world = Worker.World;
PlayerLifecycleHelper.AddServerSystems(world);
GameObjectCreationHelper.EnableStandardGameObjectCreation(world, entityRepresentationMapping);
// Shooting
world.GetOrCreateSystem<ServerShootingSystem>();
// Metrics
world.GetOrCreateSystem<MetricSendSystem>();
// Health
world.GetOrCreateSystem<ServerHealthModifierSystem>();
world.GetOrCreateSystem<HealthRegenSystem>();
}
}
}