Skip to content
This repository was archived by the owner on Oct 20, 2021. It is now read-only.

Commit 6f4b2b8

Browse files
author
Paul Balaji
authored
Better gameobject initialization (#261)
1 parent f7a13fb commit 6f4b2b8

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

CHANGELOG.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
## Unreleased
44

5-
## `0.3.4` - 2020-03-16
6-
7-
### Changed
8-
9-
- Upgraded to GDK for Unity version `0.3.4`
105
## Breaking Changes
116

127
- The FPS starter project now uses [query-based interest](https://docs.improbable.io/reference/14.4/shared/authority-and-interest/interest/query-based-interest-qbi) instead of [chunk-based interest](https://docs.improbable.io/reference/14.4/shared/authority-and-interest/interest/chunk-based-interest-cbi). [#253](https://github.com/spatialos/gdk-for-unity-fps-starter-project/pull/253)
138
- You must now pass in an `EntityId` to create a player `EntityTemplate`. [#254](https://github.com/spatialos/gdk-for-unity-fps-starter-project/pull/254)
149

10+
## Changed
11+
12+
- Added the new `PopulateEntityTypeExpectations` method required by `IEntityGameObjectCreator` to the `AdvancedEntityPipeline`. [#261](https://github.com/spatialos/gdk-for-unity-fps-starter-project/pull/261)
13+
1514
## `0.3.3` - 2020-02-14
1615

1716
### Breaking Changes

gdk.pinned

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
develop 96405d6404cd94bf1681c24512058dfc9a25e4d6
1+
develop 9c0b93fddff03ba8610fc1d08410a95cd1a5408b

workers/unity/Assets/Fps/Scripts/Config/AdvancedEntityPipeline.cs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using Fps.Movement;
44
using Fps.SchemaExtensions;
5-
using Improbable;
65
using Improbable.Gdk.Core;
76
using Improbable.Gdk.GameObjectCreation;
87
using Improbable.Gdk.PlayerLifecycle;
@@ -31,8 +30,7 @@ public class AdvancedEntityPipeline : IEntityGameObjectCreator
3130

3231
private readonly Type[] componentsToAdd =
3332
{
34-
typeof(Transform),
35-
typeof(Rigidbody)
33+
typeof(Transform), typeof(Rigidbody)
3634
};
3735

3836
public AdvancedEntityPipeline(WorkerInWorld worker, string authPlayer, string nonAuthPlayer)
@@ -46,30 +44,34 @@ public AdvancedEntityPipeline(WorkerInWorld worker, string authPlayer, string no
4644
cachedNonAuthPlayer = Resources.Load<GameObject>(nonAuthPlayer);
4745
}
4846

49-
public void OnEntityCreated(SpatialOSEntity entity, EntityGameObjectLinker linker)
47+
public void PopulateEntityTypeExpectations(EntityTypeExpectations entityTypeExpectations)
5048
{
51-
if (!entity.TryGetComponent<Metadata.Component>(out var metadata))
49+
entityTypeExpectations.RegisterEntityType(PlayerEntityType, new[]
5250
{
53-
return;
54-
}
55-
56-
if (metadata.EntityType == PlayerEntityType)
57-
{
58-
CreatePlayerGameObject(entity, linker);
59-
return;
60-
}
51+
typeof(OwningWorker.Component), typeof(ServerMovement.Component)
52+
});
6153

62-
fallback.OnEntityCreated(entity, linker);
54+
fallback.PopulateEntityTypeExpectations(entityTypeExpectations);
6355
}
6456

65-
private void CreatePlayerGameObject(SpatialOSEntity entity, EntityGameObjectLinker linker)
57+
public void OnEntityCreated(string entityType, SpatialOSEntity entity, EntityGameObjectLinker linker)
6658
{
67-
if (!entity.TryGetComponent<OwningWorker.Component>(out var owningWorker))
59+
switch (entityType)
6860
{
69-
throw new InvalidOperationException("Player entity does not have the OwningWorker component");
61+
case PlayerEntityType:
62+
CreatePlayerGameObject(entity, linker);
63+
break;
64+
default:
65+
fallback.OnEntityCreated(entityType, entity, linker);
66+
break;
7067
}
68+
}
7169

70+
private void CreatePlayerGameObject(SpatialOSEntity entity, EntityGameObjectLinker linker)
71+
{
72+
var owningWorker = entity.GetComponent<OwningWorker.Component>();
7273
var serverPosition = entity.GetComponent<ServerMovement.Component>();
74+
7375
var position = serverPosition.Latest.Position.ToVector3() + workerOrigin;
7476

7577
var prefab = owningWorker.WorkerId == workerId ? cachedAuthPlayer : cachedNonAuthPlayer;

0 commit comments

Comments
 (0)