Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit da81d11

Browse files
authored
Entity representation (#1393)
* Move assets out of Resources folder * Add code changes for implementing Entity representation mapping * Add Editor UI integration * Fix tests * Upgrade UI Builder package * Add Entity representation mapping assets for clients and gamelogic * Update upgrade guide * Use XML and USS for EntityRepresentationMappingEditor
1 parent 201b31d commit da81d11

File tree

109 files changed

+915
-376
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+915
-376
lines changed

.github/ClientPrefabMapping.PNG

25.4 KB
Loading

.github/ResourcesNew.PNG

5.31 KB
Loading

.github/ResourcesOld.PNG

5.09 KB
Loading

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- All generated C# enums will now start from 0, being shifted to schema values on serialization and shifted back to C# values on deserialization. [#1412](https://github.com/spatialos/gdk-for-unity/pull/1412)
88
- A warning will be generated when enums defined in schema do not start from 0.
9+
- GameObjectCreation feature module now links entity types with prefabs through EntityRepresentationMapping assets. [#1393](https://github.com/spatialos/gdk-for-unity/pull/1393)
10+
- See the [upgrade guide](UPGRADE_GUIDE.md) for detailed upgrade instructions for this breaking change.
11+
- `IEntityGameObjectCreator.PopulateEntityTypeExpectations` now only needs to specify what SpatialOS components it needs for spawning an entity, such as `Position`.
12+
- `GameObjectCreationHelper.EnableStandardGameObjectCreation` now requires a non-null `EntityRepresentationMapping` to be passed in.
913

1014
### Added
1115

@@ -16,6 +20,7 @@
1620
- Added `Scripting Backend` option dropdown to the Build Configuration UI. [#1411](https://github.com/spatialos/gdk-for-unity/pull/1411)
1721
- Added `Allow Debug` toggle to the Build Configuration UI. [#1413](https://github.com/spatialos/gdk-for-unity/pull/1413)
1822
- Enabling the option allows .NET debuggers (Rider/Visual Studio) to use breakpoints while in the Unity Player.
23+
- Added `Authority` type field to `IComponentMetaclass`. [#1393](https://github.com/spatialos/gdk-for-unity/pull/1393)
1924

2025
### Changed
2126

UPGRADE_GUIDE.md

+37-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,34 @@
22

33
## From `0.3.7` to `0.3.8`
44

5+
### Asset based entity representation
6+
7+
The methods for mapping a Prefab to a type of entity have been changed since 0.3.8.
8+
9+
To upgrade to the new method, please do the following steps for every worker type you have in your Unity project:
10+
11+
1. Create an `Entity Representation Mapping` asset through the `Create > SpatialOS > Entity Representation Mapping` context menu.
12+
1. Name the asset accordingly, for example `ClientPrefabMapping` or `GamelogicPrefabMapping`.
13+
1. Select the asset in the Unity Inspector.
14+
1. For each entity type that needs to have a GameObject spawned for them.:
15+
1. Select `New Entity Type`, and select the type of resolver you'd like to use:
16+
* `SimpleEntityResolver` is a 1 to 1 mapping between entity type and prefab.
17+
* `AuthoritativeEntityResolver` lets you map 2 prefabs, and picks the "Owned Prefab" based on your worker's authority over the given component ID.
18+
* `OwningWorkerEntityResolver` lets you map 2 prefabs, and picks the "Owned Prefab" if the entity's `OwningWorker` component contains your worker's id. This uses the Player Lifecycle Feature Module.
19+
1. Fill in the `Entity Type`, ensuring it matches the string used for the `Metadata` component.
20+
1. Select the prefab(s) you'd like to use for this entity type.
21+
1. Update your `WorkerConnector` script to pass the `Entity Representation Mapping` asset along to `GameObjectCreationHelper.EnableStandardGameObjectCreation`.
22+
23+
For example, the `ClientPrefabMapping` in our playground project looks like:
24+
25+
![Prefab mapping for Client worker](.github/ClientPrefabMapping.PNG)
26+
27+
With this change, you can now put prefabs for entities anywhere in your Unity project, instead of being restricted to the `Resources` folder.
28+
29+
| Old project prefab layout | New project prefab layout |
30+
| :--------------------------------------------- | :--------------------------------------------- |
31+
| ![Old prefab folder](.github/ResourcesOld.PNG) | ![New prefab folder](.github/ResourcesNew.PNG) |
32+
533
### Scripting Backend in Project Settings is now overwritten by the Build Configuration
634

735
The Scripting Backend defined in the Unity Project Settings is now overwritten by the Build Configuration Asset. More information can be found on the [Build Configuration UI](https://documentation.improbable.io/gdk-for-unity/v0.3.8/docs/build-configuration#section-build-configuration-ui) wiki page.
@@ -439,14 +467,14 @@ The equality operators `==` and `!=` have also been implemented for the `EdgeLen
439467
New methods are exposed for conversion of `Coordinates`, `EdgeLength`, `FixedPointVector3` and `CompressedQuaternion` to and from native Unity `Vector3` and `Quaternion` types.
440468

441469
| Static Method | Result Type | Module Dependency |
442-
|----------------------------------------------------------|------------------------|-------------------|
470+
| -------------------------------------------------------- | ---------------------- | ----------------- |
443471
| `Coordinates.FromUnityVector(Vector3 v)` | `Coordinates` | - |
444472
| `EdgeLength.FromUnityVector(Vector3 v)` | `EdgeLength` | - |
445473
| `FixedPointVector3.FromUnityVector(Vector3 v)` | `FixedPointVector3` | Transform Sync |
446474
| `CompressedQuaternion.FromUnityQuaternion(Quaternion q)` | `CompressedQuaternion` | Transform Sync |
447475

448476
| Type | Method | Result Type | Module Dependency |
449-
|------------------------|-----------------------------|------------------------|-------------------|
477+
| ---------------------- | --------------------------- | ---------------------- | ----------------- |
450478
| `Vector3` | `.ToCoordinates()` | `Coordinates` | Transform Sync |
451479
| `Vector3` | `.ToFixedPointVector3()` | `FixedPointVector3` | Transform Sync |
452480
| `Vector3` | `.ToEdgeLength()` | `EdgeLength` | QBI Helper |
@@ -629,13 +657,13 @@ In order to replicate the `DefaultWorkerConnector` behaviour exactly:
629657

630658
Previously, there were a set of virtual methods on the `WorkerConnector` class that changed the behaviour of some of the connection flows. These methods now live in their respective connection flow objects (and are still virtual). You can inherit from the flow object and override the methods to achieve the same behaviour. See the table below for a mapping of where these methods currently exist.
631659

632-
| Method | Class |
633-
| --- | --- |
634-
| `SelectDeploymentName(DeploymentList deployments)` | `LocatorFlow` |
635-
| `GetPlayerId()` | `AlphaLocatorFlow` |
636-
| `GetDisplayName()` | `AlphaLocatorFlow` |
637-
| `string SelectLoginToken(List<LoginTokenDetails> loginTokens)` | `AlphaLocatorFlow` |
638-
| `string GetDevelopmentPlayerIdentityToken(string authToken, string playerId, string displayName)` | `AlphaLocatorFlow` |
660+
| Method | Class |
661+
| -------------------------------------------------------------------------------------------------- | ------------------ |
662+
| `SelectDeploymentName(DeploymentList deployments)` | `LocatorFlow` |
663+
| `GetPlayerId()` | `AlphaLocatorFlow` |
664+
| `GetDisplayName()` | `AlphaLocatorFlow` |
665+
| `string SelectLoginToken(List<LoginTokenDetails> loginTokens)` | `AlphaLocatorFlow` |
666+
| `string GetDevelopmentPlayerIdentityToken(string authToken, string playerId, string displayName)` | `AlphaLocatorFlow` |
639667
| `List<LoginTokenDetails> GetDevelopmentLoginTokens(string workerType, string playerIdentityToken)` | `AlphaLocatorFlow` |
640668

641669
#### Mobile setup
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: f0598980a22146e5bb63df7b024cf2b0, type: 3}
13+
m_Name: ClientPrefabMapping
14+
m_EditorClassIdentifier:
15+
EntityRepresentationResolvers:
16+
- id: 0
17+
- id: 1
18+
- id: 2
19+
references:
20+
version: 1
21+
00000000:
22+
type: {class: SimpleEntityResolver, ns: Improbable.Gdk.Core.Representation.Types,
23+
asm: Improbable.Gdk.Core}
24+
data:
25+
entityType: Cube
26+
prefab: {fileID: 1119241936791015974, guid: 3095f262424c6314a9a2487e12d1e1e2,
27+
type: 3}
28+
requiredComponents:
29+
00000001:
30+
type: {class: SimpleEntityResolver, ns: Improbable.Gdk.Core.Representation.Types,
31+
asm: Improbable.Gdk.Core}
32+
data:
33+
entityType: Character
34+
prefab: {fileID: 1292271339760838, guid: 34f6f8ff026facf49bbc20f4663b8209,
35+
type: 3}
36+
requiredComponents:
37+
00000002:
38+
type: {class: SimpleEntityResolver, ns: Improbable.Gdk.Core.Representation.Types,
39+
asm: Improbable.Gdk.Core}
40+
data:
41+
entityType: Spinner
42+
prefab: {fileID: 1198430049189278, guid: 913515e03e128a0489711fdead38a227,
43+
type: 3}
44+
requiredComponents:

workers/unity/Assets/Playground/Config/ClientPrefabMapping.asset.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: f0598980a22146e5bb63df7b024cf2b0, type: 3}
13+
m_Name: GamelogicPrefabMapping
14+
m_EditorClassIdentifier:
15+
EntityRepresentationResolvers:
16+
- id: 0
17+
- id: 1
18+
- id: 2
19+
references:
20+
version: 1
21+
00000000:
22+
type: {class: SimpleEntityResolver, ns: Improbable.Gdk.Core.Representation.Types,
23+
asm: Improbable.Gdk.Core}
24+
data:
25+
entityType: Cube
26+
prefab: {fileID: 5737430427132324103, guid: b59182166209b9b4b80225bae2aadf2d,
27+
type: 3}
28+
requiredComponents:
29+
00000001:
30+
type: {class: SimpleEntityResolver, ns: Improbable.Gdk.Core.Representation.Types,
31+
asm: Improbable.Gdk.Core}
32+
data:
33+
entityType: Character
34+
prefab: {fileID: 1292271339760838, guid: 34f6f8ff026facf49bbc20f4663b8209,
35+
type: 3}
36+
requiredComponents:
37+
00000002:
38+
type: {class: SimpleEntityResolver, ns: Improbable.Gdk.Core.Representation.Types,
39+
asm: Improbable.Gdk.Core}
40+
data:
41+
entityType: Spinner
42+
prefab: {fileID: 1198430049189278, guid: 913515e03e128a0489711fdead38a227,
43+
type: 3}
44+
requiredComponents:

workers/unity/Assets/Playground/Config/GamelogicPrefabMapping.asset.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

workers/unity/Assets/Playground/Config/WorkerUtils.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Improbable.Gdk.Core;
2+
using Improbable.Gdk.Core.Representation;
23
using Improbable.Gdk.GameObjectCreation;
34
using Improbable.Gdk.PlayerLifecycle;
45
using Improbable.Gdk.TransformSynchronization;
@@ -12,12 +13,12 @@ public static class WorkerUtils
1213
public const string UnityGameLogic = "UnityGameLogic";
1314
public const string MobileClient = "MobileClient";
1415

15-
public static void AddClientSystems(World world)
16+
public static void AddClientSystems(World world, EntityRepresentationMapping entityRepresentationMapping)
1617
{
1718
AddLifecycleSystems(world);
1819
TransformSynchronizationHelper.AddClientSystems(world);
1920
PlayerLifecycleHelper.AddClientSystems(world);
20-
GameObjectCreationHelper.EnableStandardGameObjectCreation(world);
21+
GameObjectCreationHelper.EnableStandardGameObjectCreation(world, entityRepresentationMapping);
2122
world.GetOrCreateSystem<ProcessColorChangeSystem>();
2223
world.GetOrCreateSystem<LocalPlayerInputSync>();
2324
world.GetOrCreateSystem<MoveLocalPlayerSystem>();
@@ -28,12 +29,12 @@ public static void AddClientSystems(World world)
2829
world.GetOrCreateSystem<MetricSendSystem>();
2930
}
3031

31-
public static void AddGameLogicSystems(World world)
32+
public static void AddGameLogicSystems(World world, EntityRepresentationMapping entityRepresentationMapping)
3233
{
3334
AddLifecycleSystems(world);
3435
TransformSynchronizationHelper.AddServerSystems(world);
3536
PlayerLifecycleHelper.AddServerSystems(world);
36-
GameObjectCreationHelper.EnableStandardGameObjectCreation(world);
37+
GameObjectCreationHelper.EnableStandardGameObjectCreation(world, entityRepresentationMapping);
3738

3839
world.GetOrCreateSystem<TriggerColorChangeSystem>();
3940
world.GetOrCreateSystem<ProcessLaunchCommandSystem>();
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

workers/unity/Assets/Playground/Resources.meta renamed to workers/unity/Assets/Playground/Prefabs/Entities.meta

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

workers/unity/Assets/Playground/Resources/Prefabs.meta renamed to workers/unity/Assets/Playground/Prefabs/Entities/Client.meta

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!1001 &1120208426435537710
4+
PrefabInstance:
5+
m_ObjectHideFlags: 0
6+
serializedVersion: 2
7+
m_Modification:
8+
m_TransformParent: {fileID: 0}
9+
m_Modifications:
10+
- target: {fileID: 1019506993461512, guid: a29ccfb5b715bd844a4a424e137bdfed, type: 3}
11+
propertyPath: m_Name
12+
value: CubeClient
13+
objectReference: {fileID: 0}
14+
- target: {fileID: 4711983361604210, guid: a29ccfb5b715bd844a4a424e137bdfed, type: 3}
15+
propertyPath: m_RootOrder
16+
value: 0
17+
objectReference: {fileID: 0}
18+
- target: {fileID: 4711983361604210, guid: a29ccfb5b715bd844a4a424e137bdfed, type: 3}
19+
propertyPath: m_LocalEulerAnglesHint.x
20+
value: 0
21+
objectReference: {fileID: 0}
22+
- target: {fileID: 4711983361604210, guid: a29ccfb5b715bd844a4a424e137bdfed, type: 3}
23+
propertyPath: m_LocalEulerAnglesHint.y
24+
value: 0
25+
objectReference: {fileID: 0}
26+
- target: {fileID: 4711983361604210, guid: a29ccfb5b715bd844a4a424e137bdfed, type: 3}
27+
propertyPath: m_LocalEulerAnglesHint.z
28+
value: 0
29+
objectReference: {fileID: 0}
30+
- target: {fileID: 23914295514298150, guid: a29ccfb5b715bd844a4a424e137bdfed,
31+
type: 3}
32+
propertyPath: m_Materials.Array.data[0]
33+
value:
34+
objectReference: {fileID: 2100000, guid: 3609e6235e10ee04c89865c54f3b1fce, type: 2}
35+
- target: {fileID: 54117405590287678, guid: a29ccfb5b715bd844a4a424e137bdfed,
36+
type: 3}
37+
propertyPath: m_IsKinematic
38+
value: 1
39+
objectReference: {fileID: 0}
40+
- target: {fileID: 54117405590287678, guid: a29ccfb5b715bd844a4a424e137bdfed,
41+
type: 3}
42+
propertyPath: m_UseGravity
43+
value: 0
44+
objectReference: {fileID: 0}
45+
- target: {fileID: 114079472425749956, guid: a29ccfb5b715bd844a4a424e137bdfed,
46+
type: 3}
47+
propertyPath: ReceiveStrategies.Array.size
48+
value: 2
49+
objectReference: {fileID: 0}
50+
- target: {fileID: 114079472425749956, guid: a29ccfb5b715bd844a4a424e137bdfed,
51+
type: 3}
52+
propertyPath: ReceiveStrategies.Array.data[0]
53+
value:
54+
objectReference: {fileID: 11400000, guid: 7e00873dd53438245919187ebd00e937,
55+
type: 2}
56+
- target: {fileID: 114079472425749956, guid: a29ccfb5b715bd844a4a424e137bdfed,
57+
type: 3}
58+
propertyPath: ReceiveStrategies.Array.data[1]
59+
value:
60+
objectReference: {fileID: 11400000, guid: d3eeea3be1ea96949b63c46a6353d4d1,
61+
type: 2}
62+
m_RemovedComponents: []
63+
m_SourcePrefab: {fileID: 100100000, guid: a29ccfb5b715bd844a4a424e137bdfed, type: 3}

workers/unity/Assets/Playground/Resources/Prefabs/UnityGameLogic/Cube.prefab.meta renamed to workers/unity/Assets/Playground/Prefabs/Entities/Client/CubeClient.prefab.meta

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

workers/unity/Assets/Playground/Resources/Prefabs/Common.meta renamed to workers/unity/Assets/Playground/Prefabs/Entities/Gamelogic.meta

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)