From 8a3997dcf693bda05c8cf4fa27a38995dd1e6098 Mon Sep 17 00:00:00 2001 From: John Strine Date: Wed, 5 Apr 2017 18:14:34 +0100 Subject: [PATCH] Upgraded to SpatialOS 10.2.0 --- default_launch.json | 36 +- .../improbable/general/WorldTransform.schema | 10 - .../global/ClientAuthorityCheck.schema | 6 + .../improbable/global/PlayerCreation.schema | 12 + .../improbable/global/WorldTransform.schema | 10 + .../improbable/player/ClientConnection.schema | 19 + .../improbable/player/PlayerLifecycle.schema | 31 - schema/improbable/player/Spawner.schema | 21 - schema/improbable/ship/ShipControls.schema | 2 +- schema/improbable/terrain/Terrain.schema | 4 +- snapshots/default.snapshot | Bin 154 -> 144 bytes spatialos.json | 6 +- workers/unity/Assets/ClientScene.unity | 214 ++- workers/unity/Assets/Editor/SnapshotMenu.cs | 59 +- .../Assets/EntityPrefabs/PirateShip.prefab | 295 +--- ...yerSpawner.prefab => PlayerCreator.prefab} | 26 +- ....prefab.meta => PlayerCreator.prefab.meta} | 2 +- .../Assets/EntityPrefabs/PlayerShip.prefab | 391 +---- .../PlayerShipEntityTemplate.cs | 33 - .../PlayerSpawnerEntityTemplate.cs | 29 - .../EntityTemplates/TerrainEntityTemplate.cs | 26 - .../{ => Gamelogic}/EntityTemplates.meta | 0 .../EntityTemplates/EntityTemplateFactory.cs | 71 + .../EntityTemplateFactory.cs.meta} | 4 +- workers/unity/Assets/Gamelogic/Global.meta | 9 + .../Assets/Gamelogic/Global/Bootstrap.cs | 80 + .../Global/Bootstrap.cs.meta} | 4 +- .../Global/PlayerCreatingBehaviour.cs | 61 + .../Global/PlayerCreatingBehaviour.cs.meta} | 4 +- .../Gamelogic/Global/SimulationSettings.cs | 35 + .../Global/SimulationSettings.cs.meta} | 4 +- workers/unity/Assets/Gamelogic/Pirates.meta | 6 +- .../Behaviours/CameraEnablerVisualizer.cs | 22 +- .../Pirates/Behaviours/DecrementHealth.cs | 3 +- .../PlayerEntityLifecycleManager.cs | 93 - .../Behaviours/PlayerHeartbeatSender.cs | 76 - .../Behaviours/PlayerHeartbeatSender.cs.meta | 12 - .../Behaviours/PlayerInputController.cs | 13 +- .../Pirates/Behaviours/PlayerSpawnManager.cs | 53 - .../Gamelogic/Pirates/Behaviours/ScoreGUI.cs | 7 +- .../Pirates/Behaviours/ShipController.cs | 41 - .../Pirates/Behaviours/ShipMovement.cs | 97 +- .../Pirates/Behaviours/SinkingBehaviour.cs | 5 +- .../Pirates/Behaviours/TransformReceiver.cs | 15 +- .../Assets/Gamelogic/Pirates/Bootstrap.cs | 89 - .../Gamelogic/Pirates/Bootstrap.cs.meta | 8 - .../Pirates/Camera/CameraVisualizer.cs | 26 - .../Pirates/Camera/CameraVisualizer.cs.meta | 12 - .../Gamelogic/Pirates/Camera/LagRotation.cs | 28 - .../Pirates/Camera/LagRotation.cs.meta | 12 - .../Gamelogic/Pirates/Camera/ShipCamera.cs | 34 - .../Pirates/Camera/ShipCamera.cs.meta | 12 - .../Gamelogic/Pirates/Cannons/CannonFirer.cs | 9 +- .../Pirates/Cannons/DestroyCannonball.cs | 2 +- .../Pirates/Water/RepositionWater.cs | 10 +- .../Assets/Gamelogic/Pirates/Water/Water.cs | 18 +- workers/unity/Assets/Gamelogic/Player.meta | 9 + .../Player/HandleClientConnection.cs | 70 + .../HandleClientConnection.cs.meta} | 4 +- .../Gamelogic/Player/SendClientConnection.cs | 44 + .../SendClientConnection.cs.meta} | 4 +- .../Gamelogic/{Pirates => }/Shaders.meta | 0 .../{Pirates => }/Shaders/ReapplyShaders.cs | 2 +- .../Shaders/ReapplyShaders.cs.meta | 0 .../{Pirates/Camera.meta => UI.meta} | 4 +- .../Assets/Gamelogic/UI/CursorHoverEffect.cs | 33 + .../Gamelogic/UI/CursorHoverEffect.cs.meta | 12 + .../Gamelogic/UI/SplashScreenController.cs | 68 + .../UI/SplashScreenController.cs.meta | 12 + workers/unity/Assets/Gamelogic/Utils.meta | 9 + .../Assets/Gamelogic/Utils/TimerUtils.cs | 24 + .../Assets/Gamelogic/Utils/TimerUtils.cs.meta | 12 + workers/unity/Assets/PhysicsServerScene.unity | 10 +- workers/unity/Assets/Plugins.meta | 4 +- .../unity/Assets/Resources/EntityPrefabs.meta | 4 +- .../EntityPrefabs/FireAnim.prefab | 1531 +++++++++++++---- .../EntityPrefabs/FireAnim.prefab.meta | 0 workers/unity/Assets/Resources/UI.meta | 9 + .../unity/Assets/Resources/UI/CursorHand.png | Bin 0 -> 913 bytes .../Assets/Resources/UI/CursorHand.png.meta | 76 + .../Assets/Resources/UI/SplashScreen.prefab | 597 +++++++ .../Resources/UI/SplashScreen.prefab.meta | 8 + .../Assets/Resources/UI/splash-screen.png | Bin 0 -> 3542527 bytes .../Resources/UI/splash-screen.png.meta | 76 + .../ProjectSettings/QualitySettings.asset | 2 +- .../unity/spatialos.UnityClient.worker.json | 4 +- .../unity/spatialos.UnityWorker.worker.json | 10 +- 87 files changed, 3083 insertions(+), 1762 deletions(-) delete mode 100644 schema/improbable/general/WorldTransform.schema create mode 100644 schema/improbable/global/ClientAuthorityCheck.schema create mode 100644 schema/improbable/global/PlayerCreation.schema create mode 100644 schema/improbable/global/WorldTransform.schema create mode 100644 schema/improbable/player/ClientConnection.schema delete mode 100644 schema/improbable/player/PlayerLifecycle.schema delete mode 100644 schema/improbable/player/Spawner.schema rename workers/unity/Assets/EntityPrefabs/{PlayerSpawner.prefab => PlayerCreator.prefab} (66%) rename workers/unity/Assets/EntityPrefabs/{PlayerSpawner.prefab.meta => PlayerCreator.prefab.meta} (78%) delete mode 100644 workers/unity/Assets/EntityTemplates/PlayerShipEntityTemplate.cs delete mode 100644 workers/unity/Assets/EntityTemplates/PlayerSpawnerEntityTemplate.cs delete mode 100644 workers/unity/Assets/EntityTemplates/TerrainEntityTemplate.cs rename workers/unity/Assets/{ => Gamelogic}/EntityTemplates.meta (100%) create mode 100644 workers/unity/Assets/Gamelogic/EntityTemplates/EntityTemplateFactory.cs rename workers/unity/Assets/Gamelogic/{Pirates/Behaviours/PlayerEntityLifecycleManager.cs.meta => EntityTemplates/EntityTemplateFactory.cs.meta} (75%) create mode 100644 workers/unity/Assets/Gamelogic/Global.meta create mode 100644 workers/unity/Assets/Gamelogic/Global/Bootstrap.cs rename workers/unity/Assets/{EntityTemplates/PlayerShipEntityTemplate.cs.meta => Gamelogic/Global/Bootstrap.cs.meta} (75%) create mode 100644 workers/unity/Assets/Gamelogic/Global/PlayerCreatingBehaviour.cs rename workers/unity/Assets/{EntityTemplates/PlayerSpawnerEntityTemplate.cs.meta => Gamelogic/Global/PlayerCreatingBehaviour.cs.meta} (75%) create mode 100644 workers/unity/Assets/Gamelogic/Global/SimulationSettings.cs rename workers/unity/Assets/{EntityTemplates/TerrainEntityTemplate.cs.meta => Gamelogic/Global/SimulationSettings.cs.meta} (75%) delete mode 100644 workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerEntityLifecycleManager.cs delete mode 100644 workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerHeartbeatSender.cs delete mode 100644 workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerHeartbeatSender.cs.meta delete mode 100644 workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerSpawnManager.cs delete mode 100644 workers/unity/Assets/Gamelogic/Pirates/Behaviours/ShipController.cs delete mode 100644 workers/unity/Assets/Gamelogic/Pirates/Bootstrap.cs delete mode 100644 workers/unity/Assets/Gamelogic/Pirates/Bootstrap.cs.meta delete mode 100644 workers/unity/Assets/Gamelogic/Pirates/Camera/CameraVisualizer.cs delete mode 100644 workers/unity/Assets/Gamelogic/Pirates/Camera/CameraVisualizer.cs.meta delete mode 100644 workers/unity/Assets/Gamelogic/Pirates/Camera/LagRotation.cs delete mode 100644 workers/unity/Assets/Gamelogic/Pirates/Camera/LagRotation.cs.meta delete mode 100644 workers/unity/Assets/Gamelogic/Pirates/Camera/ShipCamera.cs delete mode 100644 workers/unity/Assets/Gamelogic/Pirates/Camera/ShipCamera.cs.meta create mode 100644 workers/unity/Assets/Gamelogic/Player.meta create mode 100644 workers/unity/Assets/Gamelogic/Player/HandleClientConnection.cs rename workers/unity/Assets/Gamelogic/{Pirates/Behaviours/PlayerSpawnManager.cs.meta => Player/HandleClientConnection.cs.meta} (76%) create mode 100644 workers/unity/Assets/Gamelogic/Player/SendClientConnection.cs rename workers/unity/Assets/Gamelogic/{Pirates/Behaviours/ShipController.cs.meta => Player/SendClientConnection.cs.meta} (76%) rename workers/unity/Assets/Gamelogic/{Pirates => }/Shaders.meta (100%) rename workers/unity/Assets/Gamelogic/{Pirates => }/Shaders/ReapplyShaders.cs (96%) rename workers/unity/Assets/Gamelogic/{Pirates => }/Shaders/ReapplyShaders.cs.meta (100%) rename workers/unity/Assets/Gamelogic/{Pirates/Camera.meta => UI.meta} (67%) create mode 100644 workers/unity/Assets/Gamelogic/UI/CursorHoverEffect.cs create mode 100644 workers/unity/Assets/Gamelogic/UI/CursorHoverEffect.cs.meta create mode 100644 workers/unity/Assets/Gamelogic/UI/SplashScreenController.cs create mode 100644 workers/unity/Assets/Gamelogic/UI/SplashScreenController.cs.meta create mode 100644 workers/unity/Assets/Gamelogic/Utils.meta create mode 100644 workers/unity/Assets/Gamelogic/Utils/TimerUtils.cs create mode 100644 workers/unity/Assets/Gamelogic/Utils/TimerUtils.cs.meta rename workers/unity/Assets/{ => Resources}/EntityPrefabs/FireAnim.prefab (60%) rename workers/unity/Assets/{ => Resources}/EntityPrefabs/FireAnim.prefab.meta (100%) create mode 100644 workers/unity/Assets/Resources/UI.meta create mode 100644 workers/unity/Assets/Resources/UI/CursorHand.png create mode 100644 workers/unity/Assets/Resources/UI/CursorHand.png.meta create mode 100644 workers/unity/Assets/Resources/UI/SplashScreen.prefab create mode 100644 workers/unity/Assets/Resources/UI/SplashScreen.prefab.meta create mode 100644 workers/unity/Assets/Resources/UI/splash-screen.png create mode 100644 workers/unity/Assets/Resources/UI/splash-screen.png.meta diff --git a/default_launch.json b/default_launch.json index 4357ea6..80c2a2d 100644 --- a/default_launch.json +++ b/default_launch.json @@ -19,31 +19,27 @@ } ], "load_balancing": { - "dynamic_loadbalancer": { - "worker_scaler_config": { - "constant_config": { - "num_workers": 2 - } - }, - "worker_placer_config": { - "random_params": {} - }, - "loadbalancer_config": { - "min_range_meters": 500.0, - "max_range_meters": 5000.0, - "speed_meters_per_second": 100.0, - "expansion_time_millis": 60000 - } - } + "auto_hex_grid": { + "num_workers": 1 + } } }, { "worker_type": "UnityClient", - "permissions": [ - { - "all": {} + "permissions": [{ + "entity_creation": { + "allow": false + }, + "entity_deletion": { + "allow": false + }, + "entity_query": { + "allow": true, + "components": [ + "*" + ] } - ] + }] } ] } diff --git a/schema/improbable/general/WorldTransform.schema b/schema/improbable/general/WorldTransform.schema deleted file mode 100644 index 9b0da31..0000000 --- a/schema/improbable/general/WorldTransform.schema +++ /dev/null @@ -1,10 +0,0 @@ -package improbable.general; - -component WorldTransform { - // Schema file ID, unique within the project - id = 1003; - - // Entity's true transform within the simulation - EntityPosition position = 1; - uint32 rotation = 2; -} diff --git a/schema/improbable/global/ClientAuthorityCheck.schema b/schema/improbable/global/ClientAuthorityCheck.schema new file mode 100644 index 0000000..82e2794 --- /dev/null +++ b/schema/improbable/global/ClientAuthorityCheck.schema @@ -0,0 +1,6 @@ +package improbable.global; + +component ClientAuthorityCheck { + // Component ID, unique within the project + id = 1002; +} diff --git a/schema/improbable/global/PlayerCreation.schema b/schema/improbable/global/PlayerCreation.schema new file mode 100644 index 0000000..1eaa382 --- /dev/null +++ b/schema/improbable/global/PlayerCreation.schema @@ -0,0 +1,12 @@ +package improbable.global; + +type CreatePlayerRequest {} +type CreatePlayerResponse {} + +component PlayerCreation { + // Component ID, unique within the project + id = 1001; + + // Command the client sends to the PlayerCreator entity to request a Player entity is created + command CreatePlayerResponse create_player(CreatePlayerRequest); +} diff --git a/schema/improbable/global/WorldTransform.schema b/schema/improbable/global/WorldTransform.schema new file mode 100644 index 0000000..f979b37 --- /dev/null +++ b/schema/improbable/global/WorldTransform.schema @@ -0,0 +1,10 @@ +package improbable.global; + +component WorldTransform { + // Component ID, unique within the project + id = 1004; + + // Entity's true transform within the project + EntityPosition position = 1; + uint32 rotation = 2; +} diff --git a/schema/improbable/player/ClientConnection.schema b/schema/improbable/player/ClientConnection.schema new file mode 100644 index 0000000..81976b6 --- /dev/null +++ b/schema/improbable/player/ClientConnection.schema @@ -0,0 +1,19 @@ +package improbable.player; + +type ClientDisconnectRequest{} +type ClientDisconnectResponse{} + +type HeartbeatRequest{} +type HeartbeatResponse{} + +component ClientConnection { + // Component ID, unique within the project + id = 1003; + + // Number of client pings that can be missed before the client is assumed disconnected and the Player is deleted + uint32 timeout_beats_remaining = 1; + // Command the client uses to ping the server to indicate its connectivity + command HeartbeatResponse heartbeat(HeartbeatRequest); + // Command the client uses to indicated the user has exited the application + command ClientDisconnectResponse disconnect_client(ClientDisconnectRequest); +} diff --git a/schema/improbable/player/PlayerLifecycle.schema b/schema/improbable/player/PlayerLifecycle.schema deleted file mode 100644 index 4588d4e..0000000 --- a/schema/improbable/player/PlayerLifecycle.schema +++ /dev/null @@ -1,31 +0,0 @@ -package improbable.player; - -type DeletePlayerRequest { - // ID of player entity to be deleted - EntityId player_entity_id = 1; -} - -type DeletePlayerResponse {} - -type HeartbeatRequest { - // ID of player entity sending a heartbeat - EntityId sender_entity_id = 1; -} - -type HeartbeatResponse {} - -component PlayerLifecycle { - // Schema file ID, unique within the project - id = 1006; - - // Facilitate player entity deletion after a timeout (e.g. client has crashed) - uint32 current_missed_heartbeats = 1; - uint32 max_missed_heartbeats = 2; - uint32 player_heartbeat_interval = 3; - - // Allow clients to request deletion of their entity when they exit - command DeletePlayerResponse delete_player(DeletePlayerRequest); - - // Used by clients to indicate they are still connected - command HeartbeatResponse heartbeat(HeartbeatRequest); -} diff --git a/schema/improbable/player/Spawner.schema b/schema/improbable/player/Spawner.schema deleted file mode 100644 index 46667a4..0000000 --- a/schema/improbable/player/Spawner.schema +++ /dev/null @@ -1,21 +0,0 @@ -package improbable.player; - -type SpawnPlayerRequest { - // ID of client to whom spawned entity should be delegated - string client_id = 1; - // Initial position requested for new player entity - Coordinates initial_position = 2; -} - -type SpawnPlayerResponse { - // ID of entity spawned for player - EntityId entity_id = 1; -} - -component Spawner { - // Schema file ID, unique within the project - id = 1002; - - // Used by clients on connection to request a ship is spawned for the player - command SpawnPlayerResponse spawn_player(SpawnPlayerRequest); -} diff --git a/schema/improbable/ship/ShipControls.schema b/schema/improbable/ship/ShipControls.schema index c4dbea8..a5d3a29 100644 --- a/schema/improbable/ship/ShipControls.schema +++ b/schema/improbable/ship/ShipControls.schema @@ -1,7 +1,7 @@ package improbable.ship; component ShipControls { - // Schema file ID, unique within the project + // Component ID, unique within the project id = 1000; // Exclude this component from spatial finds diff --git a/schema/improbable/terrain/Terrain.schema b/schema/improbable/terrain/Terrain.schema index b7fcbc0..e0892ff 100644 --- a/schema/improbable/terrain/Terrain.schema +++ b/schema/improbable/terrain/Terrain.schema @@ -1,6 +1,6 @@ package improbable.terrain; component Terrain { - // Schema file ID, unique within the project - id = 1001; + // Component ID, unique within the project + id = 1005; } diff --git a/snapshots/default.snapshot b/snapshots/default.snapshot index b57a9956cc85bdffdb20b89ad460f279bca1f001..25088d8de8bb698301c3d7c71c645774331d1ad3 100644 GIT binary patch literal 144 zcmb2|=3oE=?&KAMs~#nYB=LLdYI&VGGx=0)>hTXJ{N{Pjn#{<>lE~vJ;oOiYv{`$) zinzJBx_GstTWVoik)gP_IJo^2%M{~6M4e>vFC3jE*(xPrIisb5 vxkyMmxO+}_kg)fs?j=Q>yB|!EHS9aEK|tf1P;5_Uvmir54ZkuQBLf2fcPB8l literal 154 zcmV;L0A>FliwFP!0000017oNWs^VZ2Vh>3zDoV`Elgd41$8gI|o=cjO0SrVO1R0<} z62=f@nwTS`!6n4;l3j=wRfQ18Yjm+@ zMxh2q4kjVqfSkn2)S}>m#PYn(); + var currentEntityId = 1; - [MenuItem("Improbable/Snapshots/Generate Snapshot Programmatically")] - [UsedImplicitly] - private static void GenerateSnapshotProgrammatically() - { - var snapshotEntities = new Dictionary(); - var currentEntityId = 1; + snapshotEntities.Add(new EntityId(currentEntityId++), EntityTemplateFactory.CreateTerrainTemplate()); + snapshotEntities.Add(new EntityId(currentEntityId++), EntityTemplateFactory.CreatePlayerCreatorTemplate()); - snapshotEntities.Add(new EntityId(currentEntityId++), TerrainEntityTemplate.GenerateTerrainSnapshotEntityTemplate()); - snapshotEntities.Add(new EntityId(currentEntityId++), PlayerSpawnerEntityTemplate.GeneratePlayerSpawnerSnapshotEntityTemplate()); + SaveSnapshot(snapshotEntities); + } - SaveSnapshot(snapshotEntities); - } + private static void SaveSnapshot(IDictionary snapshotEntities) + { + File.Delete(SimulationSettings.DefaultSnapshotPath); + var maybeError = Snapshot.Save(SimulationSettings.DefaultSnapshotPath, snapshotEntities); - private static void SaveSnapshot(IDictionary snapshotEntities) - { - File.Delete(InitialWorldSnapshotPath); - var maybeError = Snapshot.Save(InitialWorldSnapshotPath, snapshotEntities); - - if (maybeError.HasValue) - { - Debug.LogErrorFormat("Failed to generate initial world snapshot: {0}", maybeError.Value); - } - else - { - Debug.LogFormat("Successfully generated initial world snapshot at {0}", InitialWorldSnapshotPath); - } - } + if (maybeError.HasValue) + { + Debug.LogErrorFormat("Failed to generate initial world snapshot: {0}", maybeError.Value); + } + else + { + Debug.LogFormat("Successfully generated initial world snapshot at {0}", SimulationSettings.DefaultSnapshotPath); + } + } + } } diff --git a/workers/unity/Assets/EntityPrefabs/PirateShip.prefab b/workers/unity/Assets/EntityPrefabs/PirateShip.prefab index 7819673..86c0f0b 100644 --- a/workers/unity/Assets/EntityPrefabs/PirateShip.prefab +++ b/workers/unity/Assets/EntityPrefabs/PirateShip.prefab @@ -5,12 +5,12 @@ GameObject: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - serializedVersion: 4 + serializedVersion: 5 m_Component: - - 4: {fileID: 442014} - - 33: {fileID: 3331058} - - 23: {fileID: 2395246} - - 64: {fileID: 6478688} + - component: {fileID: 442014} + - component: {fileID: 3331058} + - component: {fileID: 2395246} + - component: {fileID: 6478688} m_Layer: 0 m_Name: Ship m_TagString: Untagged @@ -23,14 +23,13 @@ GameObject: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - serializedVersion: 4 + serializedVersion: 5 m_Component: - - 4: {fileID: 421518} - - 54: {fileID: 5458276} - - 114: {fileID: 114000014128938252} - - 114: {fileID: 114000014179605780} - - 114: {fileID: 114000012938219408} - - 114: {fileID: 114000012598071580} + - component: {fileID: 421518} + - component: {fileID: 5458276} + - component: {fileID: 114000014128938252} + - component: {fileID: 114000014179605780} + - component: {fileID: 114000012598071580} m_Layer: 0 m_Name: PirateShip m_TagString: Untagged @@ -43,11 +42,11 @@ GameObject: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - serializedVersion: 4 + serializedVersion: 5 m_Component: - - 4: {fileID: 467550} - - 33: {fileID: 3355236} - - 23: {fileID: 2397078} + - component: {fileID: 467550} + - component: {fileID: 3355236} + - component: {fileID: 2397078} m_Layer: 0 m_Name: Sails m_TagString: Untagged @@ -55,48 +54,15 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!1 &126470 -GameObject: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - serializedVersion: 4 - m_Component: - - 4: {fileID: 446462} - - 114: {fileID: 11423402} - m_Layer: 8 - m_Name: Viewpoint - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!1 &154558 -GameObject: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - serializedVersion: 4 - m_Component: - - 4: {fileID: 499136} - - 20: {fileID: 2086014} - - 45: {fileID: 4581324} - m_Layer: 0 - m_Name: Main Camera - m_TagString: MainCamera - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 --- !u!1 &155304 GameObject: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - serializedVersion: 4 + serializedVersion: 5 m_Component: - - 4: {fileID: 454740} - - 108: {fileID: 10873974} + - component: {fileID: 454740} + - component: {fileID: 10873974} m_Layer: 0 m_Name: Directional light m_TagString: Untagged @@ -104,37 +70,6 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!1 &192006 -GameObject: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - serializedVersion: 4 - m_Component: - - 4: {fileID: 459558} - m_Layer: 8 - m_Name: LookAt - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!1 &192842 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - serializedVersion: 4 - m_Component: - - 4: {fileID: 427688} - - 114: {fileID: 11492632} - m_Layer: 8 - m_Name: Camera Node - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 --- !u!4 &421518 Transform: m_ObjectHideFlags: 1 @@ -144,26 +79,11 @@ Transform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_Children: - - {fileID: 427688} - {fileID: 4000012850611204} m_Father: {fileID: 0} m_RootOrder: 0 ---- !u!4 &427688 -Transform: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 192842} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_Children: - - {fileID: 459558} - m_Father: {fileID: 421518} - m_RootOrder: 0 --- !u!4 &442014 Transform: m_ObjectHideFlags: 1 @@ -173,24 +93,10 @@ Transform: m_LocalRotation: {x: 0.000000115202326, y: -0.7071067, z: -0.7071068, w: -0.00000011520231} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_Children: [] m_Father: {fileID: 4000012850611204} m_RootOrder: 1 ---- !u!4 &446462 -Transform: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 126470} - m_LocalRotation: {x: 0.20364179, y: 0, z: 0, w: 0.97904545} - m_LocalPosition: {x: 0, y: 3.987522, z: -9.1706705} - m_LocalScale: {x: 1, y: 1, z: 1} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_Children: - - {fileID: 499136} - m_Father: {fileID: 459558} - m_RootOrder: 0 --- !u!4 &454740 Transform: m_ObjectHideFlags: 1 @@ -200,24 +106,10 @@ Transform: m_LocalRotation: {x: 0.21609046, y: -0.055434007, z: 0.012289424, w: 0.974721} m_LocalPosition: {x: -0.44, y: 2.38, z: -3.253273} m_LocalScale: {x: 1, y: 1, z: 1} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_Children: [] m_Father: {fileID: 4000012850611204} m_RootOrder: 2 ---- !u!4 &459558 -Transform: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 192006} - m_LocalRotation: {x: 7.288624e-13, y: -1.09343036e-13, z: 7.969603e-26, w: 1} - m_LocalPosition: {x: 0, y: 2.5, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_Children: - - {fileID: 446462} - m_Father: {fileID: 427688} - m_RootOrder: 0 --- !u!4 &467550 Transform: m_ObjectHideFlags: 1 @@ -227,57 +119,10 @@ Transform: m_LocalRotation: {x: 0.000000115202326, y: -0.7071067, z: -0.7071068, w: -0.00000011520231} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_Children: [] m_Father: {fileID: 4000012850611204} m_RootOrder: 0 ---- !u!4 &499136 -Transform: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 154558} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: -0.00000021864416, z: 0.00000009506919} - m_LocalScale: {x: 0.99999994, y: 1, z: 0.9999999} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_Children: [] - m_Father: {fileID: 446462} - m_RootOrder: 0 ---- !u!20 &2086014 -Camera: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 154558} - m_Enabled: 0 - serializedVersion: 2 - m_ClearFlags: 1 - m_BackGroundColor: {r: 0.76221883, g: 0.9256449, b: 0.97794116, a: 0.019607844} - m_NormalizedViewPortRect: - serializedVersion: 2 - x: 0 - y: 0 - width: 1 - height: 1 - near clip plane: 1 - far clip plane: 500 - field of view: 45 - orthographic: 0 - orthographic size: 100 - m_Depth: 0 - m_CullingMask: - serializedVersion: 2 - m_Bits: 4294967295 - m_RenderingPath: -1 - m_TargetTexture: {fileID: 0} - m_TargetDisplay: 0 - m_TargetEye: 3 - m_HDR: 0 - m_OcclusionCulling: 0 - m_StereoConvergence: 10 - m_StereoSeparation: 0.022 - m_StereoMirrorMode: 0 --- !u!23 &2395246 MeshRenderer: m_ObjectHideFlags: 1 @@ -292,7 +137,9 @@ MeshRenderer: m_ReflectionProbeUsage: 1 m_Materials: - {fileID: 2100000, guid: 81a9aa07470ad6241b4507ed9579d6d5, type: 2} - m_SubsetIndices: + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 m_StaticBatchRoot: {fileID: 0} m_ProbeAnchor: {fileID: 0} m_LightProbeVolumeOverride: {fileID: 0} @@ -300,7 +147,7 @@ MeshRenderer: m_PreserveUVs: 0 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 - m_SelectedWireframeHidden: 0 + m_SelectedEditorRenderState: 3 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 m_AutoUVMaxAngle: 89 @@ -321,7 +168,9 @@ MeshRenderer: m_ReflectionProbeUsage: 1 m_Materials: - {fileID: 2100000, guid: 4504564fc227bb4459eb19bd417e3e95, type: 2} - m_SubsetIndices: + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 m_StaticBatchRoot: {fileID: 0} m_ProbeAnchor: {fileID: 0} m_LightProbeVolumeOverride: {fileID: 0} @@ -329,7 +178,7 @@ MeshRenderer: m_PreserveUVs: 0 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 - m_SelectedWireframeHidden: 0 + m_SelectedEditorRenderState: 3 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 m_AutoUVMaxAngle: 89 @@ -350,14 +199,6 @@ MeshFilter: m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 113582} m_Mesh: {fileID: 4300002, guid: 280316578a4a60e47a6dc738dfec034d, type: 3} ---- !u!45 &4581324 -Skybox: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 154558} - m_Enabled: 1 - m_CustomSkybox: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} --- !u!54 &5458276 Rigidbody: m_ObjectHideFlags: 1 @@ -384,6 +225,8 @@ MeshCollider: m_Enabled: 1 serializedVersion: 2 m_Convex: 1 + m_InflateMesh: 0 + m_SkinWidth: 0.01 m_Mesh: {fileID: 4300000, guid: 280316578a4a60e47a6dc738dfec034d, type: 3} --- !u!108 &10873974 Light: @@ -419,62 +262,6 @@ Light: m_BounceIntensity: 1.77 m_ShadowRadius: 0 m_ShadowAngle: 0 ---- !u!114 &11423402 -MonoBehaviour: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 126470} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: b53c46c7523602648bd276013ac5bea0, type: 3} - m_Name: - m_EditorClassIdentifier: - Controller: {fileID: 0} - Distance: - serializedVersion: 2 - m_Curve: - - time: -0.03543919 - value: 9.998096 - inSlope: 2 - outSlope: 2 - tangentMode: 0 - - time: 0.9274411 - value: 15 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - Angle: - serializedVersion: 2 - m_Curve: - - time: 0 - value: 23 - inSlope: 1 - outSlope: 1 - tangentMode: 10 - - time: 1 - value: 24 - inSlope: 1 - outSlope: 1 - tangentMode: 10 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 ---- !u!114 &11492632 -MonoBehaviour: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 192842} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 8ea6f4f49fb8f5c40a7ce3ea0e208bae, type: 3} - m_Name: - m_EditorClassIdentifier: - Speed: 10 --- !u!1001 &100100000 Prefab: m_ObjectHideFlags: 1 @@ -491,10 +278,10 @@ GameObject: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - serializedVersion: 4 + serializedVersion: 5 m_Component: - - 4: {fileID: 4000012850611204} - - 111: {fileID: 111000011923920842} + - component: {fileID: 4000012850611204} + - component: {fileID: 111000011923920842} m_Layer: 0 m_Name: ShipAssets m_TagString: Untagged @@ -511,13 +298,13 @@ Transform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_Children: - {fileID: 467550} - {fileID: 442014} - {fileID: 454740} m_Father: {fileID: 421518} - m_RootOrder: 1 + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!111 &111000011923920842 Animation: m_ObjectHideFlags: 1 @@ -544,19 +331,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: ab192514fb9dfbd4da22687f43b0369d, type: 3} m_Name: m_EditorClassIdentifier: - MovementSpeed: 7 - TurningSpeed: 50 ---- !u!114 &114000012938219408 -MonoBehaviour: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 107220} - m_Enabled: 0 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: d9e8cb129b8451f44aa7182ee5ffb3e1, type: 3} - m_Name: - m_EditorClassIdentifier: + myRigidbody: {fileID: 5458276} + MovementSpeed: 60 + TurningSpeed: 120 --- !u!114 &114000014128938252 MonoBehaviour: m_ObjectHideFlags: 1 diff --git a/workers/unity/Assets/EntityPrefabs/PlayerSpawner.prefab b/workers/unity/Assets/EntityPrefabs/PlayerCreator.prefab similarity index 66% rename from workers/unity/Assets/EntityPrefabs/PlayerSpawner.prefab rename to workers/unity/Assets/EntityPrefabs/PlayerCreator.prefab index 3aef5cb..47f3967 100644 --- a/workers/unity/Assets/EntityPrefabs/PlayerSpawner.prefab +++ b/workers/unity/Assets/EntityPrefabs/PlayerCreator.prefab @@ -16,13 +16,12 @@ GameObject: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - serializedVersion: 4 + serializedVersion: 5 m_Component: - - 4: {fileID: 4000011685550342} - - 114: {fileID: 114000010826269726} - - 114: {fileID: 114000010943465334} + - component: {fileID: 4000011685550342} + - component: {fileID: 114114534973254802} m_Layer: 0 - m_Name: PlayerSpawner + m_Name: PlayerCreator m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -37,22 +36,11 @@ Transform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_Children: [] m_Father: {fileID: 0} m_RootOrder: 0 ---- !u!114 &114000010826269726 -MonoBehaviour: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 1000011294143100} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 052a4a222c049714f9c266a6b483aa16, type: 3} - m_Name: - m_EditorClassIdentifier: ---- !u!114 &114000010943465334 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &114114534973254802 MonoBehaviour: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} @@ -60,6 +48,6 @@ MonoBehaviour: m_GameObject: {fileID: 1000011294143100} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 8117a0eb02e39d44fa9e44bf82146586, type: 3} + m_Script: {fileID: 11500000, guid: c2f084e4d9b056044aac654ad447ad51, type: 3} m_Name: m_EditorClassIdentifier: diff --git a/workers/unity/Assets/EntityPrefabs/PlayerSpawner.prefab.meta b/workers/unity/Assets/EntityPrefabs/PlayerCreator.prefab.meta similarity index 78% rename from workers/unity/Assets/EntityPrefabs/PlayerSpawner.prefab.meta rename to workers/unity/Assets/EntityPrefabs/PlayerCreator.prefab.meta index 716485d..ef4c803 100644 --- a/workers/unity/Assets/EntityPrefabs/PlayerSpawner.prefab.meta +++ b/workers/unity/Assets/EntityPrefabs/PlayerCreator.prefab.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 58c046ce2e486164a943e71e61ce1db4 +guid: 43298fe8be1ad6f4ca15857e9955e47b timeCreated: 1480507094 licenseType: Pro NativeFormatImporter: diff --git a/workers/unity/Assets/EntityPrefabs/PlayerShip.prefab b/workers/unity/Assets/EntityPrefabs/PlayerShip.prefab index 6b83aa5..ab42369 100644 --- a/workers/unity/Assets/EntityPrefabs/PlayerShip.prefab +++ b/workers/unity/Assets/EntityPrefabs/PlayerShip.prefab @@ -5,12 +5,12 @@ GameObject: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - serializedVersion: 4 + serializedVersion: 5 m_Component: - - 4: {fileID: 442014} - - 33: {fileID: 3331058} - - 23: {fileID: 2395246} - - 64: {fileID: 6478688} + - component: {fileID: 442014} + - component: {fileID: 3331058} + - component: {fileID: 2395246} + - component: {fileID: 64668297200445138} m_Layer: 0 m_Name: Ship m_TagString: Untagged @@ -23,22 +23,21 @@ GameObject: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - serializedVersion: 4 + serializedVersion: 5 m_Component: - - 4: {fileID: 421518} - - 54: {fileID: 5458276} - - 114: {fileID: 11441326} - - 114: {fileID: 11410120} - - 114: {fileID: 114000011511276432} - - 114: {fileID: 11432558} - - 114: {fileID: 114000014020662416} - - 114: {fileID: 11436858} - - 114: {fileID: 11492204} - - 114: {fileID: 11426928} - - 114: {fileID: 11437332} - - 114: {fileID: 114000011675452572} - - 114: {fileID: 114000013195787224} - - 114: {fileID: 114000013824945544} + - component: {fileID: 421518} + - component: {fileID: 5458276} + - component: {fileID: 11441326} + - component: {fileID: 11410120} + - component: {fileID: 114000011511276432} + - component: {fileID: 11432558} + - component: {fileID: 11437332} + - component: {fileID: 11492204} + - component: {fileID: 114000014020662416} + - component: {fileID: 11426928} + - component: {fileID: 114000013824945544} + - component: {fileID: 114595786743323458} + - component: {fileID: 114240029386091736} m_Layer: 0 m_Name: PlayerShip m_TagString: Untagged @@ -51,11 +50,11 @@ GameObject: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - serializedVersion: 4 + serializedVersion: 5 m_Component: - - 4: {fileID: 467550} - - 33: {fileID: 3355236} - - 23: {fileID: 2397078} + - component: {fileID: 467550} + - component: {fileID: 3355236} + - component: {fileID: 2397078} m_Layer: 0 m_Name: Sails m_TagString: Untagged @@ -63,48 +62,15 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!1 &126470 -GameObject: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - serializedVersion: 4 - m_Component: - - 4: {fileID: 446462} - - 114: {fileID: 11423402} - m_Layer: 8 - m_Name: Viewpoint - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!1 &154558 -GameObject: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - serializedVersion: 4 - m_Component: - - 4: {fileID: 499136} - - 20: {fileID: 2086014} - - 45: {fileID: 4581324} - m_Layer: 0 - m_Name: Main Camera - m_TagString: MainCamera - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 --- !u!1 &155304 GameObject: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - serializedVersion: 4 + serializedVersion: 5 m_Component: - - 4: {fileID: 454740} - - 108: {fileID: 10873974} + - component: {fileID: 454740} + - component: {fileID: 10873974} m_Layer: 0 m_Name: Directional light m_TagString: Untagged @@ -112,37 +78,6 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!1 &192006 -GameObject: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - serializedVersion: 4 - m_Component: - - 4: {fileID: 459558} - m_Layer: 8 - m_Name: LookAt - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!1 &192842 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - serializedVersion: 4 - m_Component: - - 4: {fileID: 427688} - - 114: {fileID: 11492632} - m_Layer: 8 - m_Name: Camera Node - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 --- !u!4 &421518 Transform: m_ObjectHideFlags: 1 @@ -152,26 +87,11 @@ Transform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_Children: - - {fileID: 427688} - {fileID: 4000014180436830} m_Father: {fileID: 0} m_RootOrder: 0 ---- !u!4 &427688 -Transform: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 192842} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_Children: - - {fileID: 459558} - m_Father: {fileID: 421518} - m_RootOrder: 0 --- !u!4 &442014 Transform: m_ObjectHideFlags: 1 @@ -181,51 +101,23 @@ Transform: m_LocalRotation: {x: 0.000000115202326, y: -0.7071067, z: -0.7071068, w: -0.00000011520231} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_Children: [] m_Father: {fileID: 4000014180436830} m_RootOrder: 1 ---- !u!4 &446462 -Transform: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 126470} - m_LocalRotation: {x: 0.20364179, y: 0, z: 0, w: 0.97904545} - m_LocalPosition: {x: 0, y: 3.987522, z: -9.1706705} - m_LocalScale: {x: 1, y: 1, z: 1} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_Children: - - {fileID: 499136} - m_Father: {fileID: 459558} - m_RootOrder: 0 --- !u!4 &454740 Transform: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 155304} - m_LocalRotation: {x: 0.21609046, y: -0.055434007, z: 0.012289424, w: 0.974721} - m_LocalPosition: {x: -0.44, y: 2.38, z: -3.253273} + m_LocalRotation: {x: 0.047887564, y: 0.8420308, z: 0.5364329, w: 0.030507736} + m_LocalPosition: {x: 0.44000107, y: -3.2532728, z: 2.3799992} m_LocalScale: {x: 1, y: 1, z: 1} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_Children: [] - m_Father: {fileID: 4000014180436830} - m_RootOrder: 2 ---- !u!4 &459558 -Transform: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 192006} - m_LocalRotation: {x: 7.288624e-13, y: -1.09343036e-13, z: 7.969603e-26, w: 1} - m_LocalPosition: {x: 0, y: 2.5, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_Children: - - {fileID: 446462} - m_Father: {fileID: 427688} + m_Father: {fileID: 467550} m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!4 &467550 Transform: m_ObjectHideFlags: 1 @@ -235,57 +127,11 @@ Transform: m_LocalRotation: {x: 0.000000115202326, y: -0.7071067, z: -0.7071068, w: -0.00000011520231} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_Children: [] + m_Children: + - {fileID: 454740} m_Father: {fileID: 4000014180436830} m_RootOrder: 0 ---- !u!4 &499136 -Transform: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 154558} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: -0.00000021864416, z: 0.00000009506919} - m_LocalScale: {x: 0.99999994, y: 1, z: 0.9999999} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_Children: [] - m_Father: {fileID: 446462} - m_RootOrder: 0 ---- !u!20 &2086014 -Camera: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 154558} - m_Enabled: 0 - serializedVersion: 2 - m_ClearFlags: 1 - m_BackGroundColor: {r: 0.76221883, g: 0.9256449, b: 0.97794116, a: 0.019607844} - m_NormalizedViewPortRect: - serializedVersion: 2 - x: 0 - y: 0 - width: 1 - height: 1 - near clip plane: 1 - far clip plane: 500 - field of view: 45 - orthographic: 0 - orthographic size: 100 - m_Depth: 0 - m_CullingMask: - serializedVersion: 2 - m_Bits: 4294967295 - m_RenderingPath: -1 - m_TargetTexture: {fileID: 0} - m_TargetDisplay: 0 - m_TargetEye: 3 - m_HDR: 0 - m_OcclusionCulling: 0 - m_StereoConvergence: 10 - m_StereoSeparation: 0.022 - m_StereoMirrorMode: 0 --- !u!23 &2395246 MeshRenderer: m_ObjectHideFlags: 1 @@ -300,7 +146,9 @@ MeshRenderer: m_ReflectionProbeUsage: 1 m_Materials: - {fileID: 2100000, guid: 81a9aa07470ad6241b4507ed9579d6d5, type: 2} - m_SubsetIndices: + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 m_StaticBatchRoot: {fileID: 0} m_ProbeAnchor: {fileID: 0} m_LightProbeVolumeOverride: {fileID: 0} @@ -308,7 +156,7 @@ MeshRenderer: m_PreserveUVs: 0 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 - m_SelectedWireframeHidden: 0 + m_SelectedEditorRenderState: 3 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 m_AutoUVMaxAngle: 89 @@ -329,7 +177,9 @@ MeshRenderer: m_ReflectionProbeUsage: 1 m_Materials: - {fileID: 2100000, guid: 1065668543b946f4790a1e433c948ca4, type: 2} - m_SubsetIndices: + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 m_StaticBatchRoot: {fileID: 0} m_ProbeAnchor: {fileID: 0} m_LightProbeVolumeOverride: {fileID: 0} @@ -337,7 +187,7 @@ MeshRenderer: m_PreserveUVs: 0 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 - m_SelectedWireframeHidden: 0 + m_SelectedEditorRenderState: 3 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 m_AutoUVMaxAngle: 89 @@ -358,14 +208,6 @@ MeshFilter: m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 113582} m_Mesh: {fileID: 4300002, guid: 280316578a4a60e47a6dc738dfec034d, type: 3} ---- !u!45 &4581324 -Skybox: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 154558} - m_Enabled: 1 - m_CustomSkybox: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} --- !u!54 &5458276 Rigidbody: m_ObjectHideFlags: 1 @@ -373,26 +215,14 @@ Rigidbody: m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 107220} serializedVersion: 2 - m_Mass: 1000 + m_Mass: 20 m_Drag: 1 - m_AngularDrag: 0.05 + m_AngularDrag: 0.5 m_UseGravity: 0 m_IsKinematic: 0 m_Interpolate: 1 - m_Constraints: 116 + m_Constraints: 84 m_CollisionDetection: 1 ---- !u!64 &6478688 -MeshCollider: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 101646} - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_Enabled: 1 - serializedVersion: 2 - m_Convex: 1 - m_Mesh: {fileID: 4300000, guid: 280316578a4a60e47a6dc738dfec034d, type: 3} --- !u!108 &10873974 Light: m_ObjectHideFlags: 1 @@ -438,57 +268,13 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: cd33d4d65b1514d3b960bcfc7fdb73f9, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!114 &11423402 -MonoBehaviour: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 126470} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: b53c46c7523602648bd276013ac5bea0, type: 3} - m_Name: - m_EditorClassIdentifier: - Controller: {fileID: 0} - Distance: - serializedVersion: 2 - m_Curve: - - time: -0.03543919 - value: 9.998096 - inSlope: 2 - outSlope: 2 - tangentMode: 0 - - time: 0.9274411 - value: 15 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - Angle: - serializedVersion: 2 - m_Curve: - - time: 0 - value: 23 - inSlope: 1 - outSlope: 1 - tangentMode: 10 - - time: 1 - value: 24 - inSlope: 1 - outSlope: 1 - tangentMode: 10 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 --- !u!114 &11426928 MonoBehaviour: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 107220} - m_Enabled: 0 + m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: a1b04f56ad1bfcf43ad356a7d124ade1, type: 3} m_Name: @@ -500,30 +286,19 @@ MonoBehaviour: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 107220} - m_Enabled: 0 + m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: c4f7e8754fe525144a87d5d569753670, type: 3} m_Name: m_EditorClassIdentifier: - OurCamera: {fileID: 2086014} ---- !u!114 &11436858 -MonoBehaviour: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 107220} - m_Enabled: 0 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: d9e8cb129b8451f44aa7182ee5ffb3e1, type: 3} - m_Name: - m_EditorClassIdentifier: + CameraOffset: {x: 0, y: 4, z: -9} --- !u!114 &11437332 MonoBehaviour: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 107220} - m_Enabled: 0 + m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 9f221b8acd2567c4dbd5c333b4fda9b0, type: 3} m_Name: @@ -546,25 +321,14 @@ MonoBehaviour: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 107220} - m_Enabled: 0 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: ab192514fb9dfbd4da22687f43b0369d, type: 3} - m_Name: - m_EditorClassIdentifier: - MovementSpeed: 7 - TurningSpeed: 50 ---- !u!114 &11492632 -MonoBehaviour: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 192842} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 8ea6f4f49fb8f5c40a7ce3ea0e208bae, type: 3} + m_Script: {fileID: 11500000, guid: ab192514fb9dfbd4da22687f43b0369d, type: 3} m_Name: m_EditorClassIdentifier: - Speed: 10 + myRigidbody: {fileID: 5458276} + MovementSpeed: 50 + TurningSpeed: 100 --- !u!1001 &100100000 Prefab: m_ObjectHideFlags: 1 @@ -581,12 +345,12 @@ GameObject: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - serializedVersion: 4 + serializedVersion: 5 m_Component: - - 4: {fileID: 4000014180436830} - - 111: {fileID: 111000010247042210} + - component: {fileID: 4000014180436830} + - component: {fileID: 111000010247042210} m_Layer: 0 - m_Name: ShipAssets + m_Name: Model m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -601,13 +365,26 @@ Transform: m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_Children: - {fileID: 467550} - {fileID: 442014} - - {fileID: 454740} m_Father: {fileID: 421518} - m_RootOrder: 1 + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!64 &64668297200445138 +MeshCollider: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 101646} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Convex: 1 + m_InflateMesh: 1 + m_SkinWidth: 0.01 + m_Mesh: {fileID: 4300000, guid: 280316578a4a60e47a6dc738dfec034d, type: 3} --- !u!111 &111000010247042210 Animation: m_ObjectHideFlags: 1 @@ -629,52 +406,52 @@ MonoBehaviour: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 107220} - m_Enabled: 0 + m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 4bd65058a0d21174fbeda699c27c4733, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!114 &114000011675452572 +--- !u!114 &114000013824945544 MonoBehaviour: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 107220} - m_Enabled: 0 + m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 051f197ef5f2da645a97fd94bf1a5a66, type: 3} + m_Script: {fileID: 11500000, guid: ab317b2a3a7a4534283417773793ca8f, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!114 &114000013195787224 +--- !u!114 &114000014020662416 MonoBehaviour: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 107220} - m_Enabled: 0 + m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: e1f5e341af930d6438da8a9fd8d5604f, type: 3} + m_Script: {fileID: 11500000, guid: a6fafd46819d7b64eb2eec65e1cb4b79, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!114 &114000013824945544 +--- !u!114 &114240029386091736 MonoBehaviour: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 107220} - m_Enabled: 0 + m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: ab317b2a3a7a4534283417773793ca8f, type: 3} + m_Script: {fileID: 11500000, guid: 69ac03230da460a428482816c6a3e668, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!114 &114000014020662416 +--- !u!114 &114595786743323458 MonoBehaviour: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 107220} - m_Enabled: 0 + m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: a6fafd46819d7b64eb2eec65e1cb4b79, type: 3} + m_Script: {fileID: 11500000, guid: 43e2ddcaec3d1bf4583c49a494523e08, type: 3} m_Name: m_EditorClassIdentifier: diff --git a/workers/unity/Assets/EntityTemplates/PlayerShipEntityTemplate.cs b/workers/unity/Assets/EntityTemplates/PlayerShipEntityTemplate.cs deleted file mode 100644 index b862b61..0000000 --- a/workers/unity/Assets/EntityTemplates/PlayerShipEntityTemplate.cs +++ /dev/null @@ -1,33 +0,0 @@ -using UnityEngine; -using Improbable.General; -using Improbable.Math; -using Improbable.Player; -using Improbable.Ship; -using Improbable.Unity.Core.Acls; -using Improbable.Worker; - -namespace Assets.EntityTemplates -{ - public class PlayerShipEntityTemplate : MonoBehaviour - { - // Template definition for a PlayerShip snapshot entity - static public Entity GeneratePlayerShipEntityTemplate(string clientWorkerId, Coordinates initialPosition) - { - var playerEntityTemplate = new Entity(); - // Define components attached to entity - playerEntityTemplate.Add(new WorldTransform.Data(new WorldTransformData(initialPosition, 0))); - playerEntityTemplate.Add(new PlayerLifecycle.Data(new PlayerLifecycleData(0, 3, 10))); - playerEntityTemplate.Add(new ShipControls.Data(new ShipControlsData(0, 0))); - - // Grant component access permissions - var acl = Acl.Build() - .SetReadAccess(CommonRequirementSets.PhysicsOrVisual) - .SetWriteAccess(CommonRequirementSets.SpecificClientOnly(clientWorkerId)) - .SetWriteAccess(CommonRequirementSets.SpecificClientOnly(clientWorkerId)) - .SetWriteAccess(CommonRequirementSets.PhysicsOnly); - playerEntityTemplate.SetAcl(acl); - - return playerEntityTemplate; - } - } -} \ No newline at end of file diff --git a/workers/unity/Assets/EntityTemplates/PlayerSpawnerEntityTemplate.cs b/workers/unity/Assets/EntityTemplates/PlayerSpawnerEntityTemplate.cs deleted file mode 100644 index 8d331b6..0000000 --- a/workers/unity/Assets/EntityTemplates/PlayerSpawnerEntityTemplate.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Improbable.Player; -using Improbable.General; -using Improbable.Worker; -using Improbable.Math; -using Improbable.Unity.Core.Acls; -using UnityEngine; - -namespace Assets.EntityTemplates -{ - public class PlayerSpawnerEntityTemplate : MonoBehaviour - { - // Template definition for a PlayerSpawner entity - public static SnapshotEntity GeneratePlayerSpawnerSnapshotEntityTemplate() - { - // Set name of Unity prefab associated with this entity - var playerSpawner = new SnapshotEntity {Prefab = "PlayerSpawner"}; - - // Define components attached to snapshot entity - playerSpawner.Add(new WorldTransform.Data(new WorldTransformData(new Coordinates(-5, 10, 0), 0))); - playerSpawner.Add(new Spawner.Data(new SpawnerData())); - - // Grant FSim (server-side) workers write-access over all of this entity's components, read-access for visual (e.g. client) workers - var acl = Acl.GenerateServerAuthoritativeAcl(playerSpawner); - playerSpawner.SetAcl(acl); - - return playerSpawner; - } - } -} \ No newline at end of file diff --git a/workers/unity/Assets/EntityTemplates/TerrainEntityTemplate.cs b/workers/unity/Assets/EntityTemplates/TerrainEntityTemplate.cs deleted file mode 100644 index d5c45d1..0000000 --- a/workers/unity/Assets/EntityTemplates/TerrainEntityTemplate.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Improbable.Math; -using Improbable.Worker; -using Improbable.General; -using Improbable.Unity.Core.Acls; -using Terrain = Improbable.Terrain.Terrain; -using TerrainData = Improbable.Terrain.TerrainData; -using UnityEngine; - -public class TerrainEntityTemplate : MonoBehaviour -{ - // Template definition for a Terrain entity - public static SnapshotEntity GenerateTerrainSnapshotEntityTemplate() - { - // Set name of Unity prefab associated with this entity - var terrain = new SnapshotEntity {Prefab = "Terrain"}; - // Define components attached to snapshot entity - terrain.Add(new Terrain.Data(new TerrainData())); - terrain.Add(new WorldTransform.Data(new WorldTransformData(new Coordinates(5, 0, 0), 0))); - - // Grant FSim workers write-access over all of this entity's components, read-access for visual (e.g. client) workers - var acl = Acl.GenerateServerAuthoritativeAcl(terrain); - terrain.SetAcl(acl); - - return terrain; - } -} diff --git a/workers/unity/Assets/EntityTemplates.meta b/workers/unity/Assets/Gamelogic/EntityTemplates.meta similarity index 100% rename from workers/unity/Assets/EntityTemplates.meta rename to workers/unity/Assets/Gamelogic/EntityTemplates.meta diff --git a/workers/unity/Assets/Gamelogic/EntityTemplates/EntityTemplateFactory.cs b/workers/unity/Assets/Gamelogic/EntityTemplates/EntityTemplateFactory.cs new file mode 100644 index 0000000..38fc243 --- /dev/null +++ b/workers/unity/Assets/Gamelogic/EntityTemplates/EntityTemplateFactory.cs @@ -0,0 +1,71 @@ +using Assets.Gamelogic.Global; +using Improbable.Global; +using Improbable.Math; +using Improbable.Player; +using Improbable.Ship; +using Improbable.Unity.Core.Acls; +using Improbable.Worker; +using Terrain = Improbable.Terrain.Terrain; +using Random = UnityEngine.Random; // Used in lesson 8 + +namespace Assets.Gamelogic.EntityTemplates +{ + // Factory class with static methods used to define templates for every created entity. + public static class EntityTemplateFactory + { + // Defines the template for the PlayerShip entity. + public static Entity CreatePlayerShipTemplate(string clientWorkerId, Coordinates initialPosition) + { + var playerEntityTemplate = new Entity(); + + // Add components to the entity. + playerEntityTemplate.Add(new WorldTransform.Data(initialPosition, 0)); + playerEntityTemplate.Add(new ClientConnection.Data(SimulationSettings.TotalHeartbeatsBeforeTimeout)); + playerEntityTemplate.Add(new ShipControls.Data(0, 0)); + playerEntityTemplate.Add(new ClientAuthorityCheck.Data()); + + // Sets the access permisisons for each component on the entity relative to the client or server worker ids. + var acl = Acl.Build() + .SetReadAccess(CommonRequirementSets.PhysicsOrVisual) + .SetWriteAccess(CommonRequirementSets.SpecificClientOnly(clientWorkerId)) + .SetWriteAccess(CommonRequirementSets.PhysicsOnly) + .SetWriteAccess(CommonRequirementSets.SpecificClientOnly(clientWorkerId)) + .SetWriteAccess(CommonRequirementSets.SpecificClientOnly(clientWorkerId)); + playerEntityTemplate.SetAcl(acl); + + return playerEntityTemplate; + } + + // Defines the template for the PlayerCreator entity. + public static SnapshotEntity CreatePlayerCreatorTemplate() + { + var playerCreatorEntityTemplate = new SnapshotEntity { Prefab = SimulationSettings.PlayerCreatorPrefabName }; + + // Add components to the entity. + playerCreatorEntityTemplate.Add(new WorldTransform.Data(Coordinates.ZERO, 0)); + playerCreatorEntityTemplate.Add(new PlayerCreation.Data()); + + // Sets the access permisisons for each component on the entity relative to the client or server worker ids. + var acl = Acl.GenerateServerAuthoritativeAcl(playerCreatorEntityTemplate); + playerCreatorEntityTemplate.SetAcl(acl); + + return playerCreatorEntityTemplate; + } + + // Defines the template for the Terrain entity. + public static SnapshotEntity CreateTerrainTemplate() + { + var terrainEntityTemplate = new SnapshotEntity { Prefab = SimulationSettings.TerrainPrefabName }; + + // Add components to the entity. + terrainEntityTemplate.Add(new Terrain.Data()); + terrainEntityTemplate.Add(new WorldTransform.Data(Coordinates.ZERO, 0)); + + // Sets the access permisisons for each component on the entity relative to the client or server worker ids. + var acl = Acl.GenerateServerAuthoritativeAcl(terrainEntityTemplate); + terrainEntityTemplate.SetAcl(acl); + + return terrainEntityTemplate; + } + } +} diff --git a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerEntityLifecycleManager.cs.meta b/workers/unity/Assets/Gamelogic/EntityTemplates/EntityTemplateFactory.cs.meta similarity index 75% rename from workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerEntityLifecycleManager.cs.meta rename to workers/unity/Assets/Gamelogic/EntityTemplates/EntityTemplateFactory.cs.meta index 1680f6d..b216d9f 100644 --- a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerEntityLifecycleManager.cs.meta +++ b/workers/unity/Assets/Gamelogic/EntityTemplates/EntityTemplateFactory.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: e1f5e341af930d6438da8a9fd8d5604f -timeCreated: 1481220799 +guid: 11a95e9882558d8488aa0ee66acc7d6f +timeCreated: 1488971241 licenseType: Pro MonoImporter: serializedVersion: 2 diff --git a/workers/unity/Assets/Gamelogic/Global.meta b/workers/unity/Assets/Gamelogic/Global.meta new file mode 100644 index 0000000..b1dc542 --- /dev/null +++ b/workers/unity/Assets/Gamelogic/Global.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: b41af90ab14f6f64d8253c9a02e6230e +folderAsset: yes +timeCreated: 1490917017 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/workers/unity/Assets/Gamelogic/Global/Bootstrap.cs b/workers/unity/Assets/Gamelogic/Global/Bootstrap.cs new file mode 100644 index 0000000..5c52d3f --- /dev/null +++ b/workers/unity/Assets/Gamelogic/Global/Bootstrap.cs @@ -0,0 +1,80 @@ +using Improbable; +using Improbable.Global; +using Improbable.Unity.Core; +using Improbable.Unity.Core.EntityQueries; +using UnityEngine; +using Improbable.Unity; +using Improbable.Unity.Configuration; +using Assets.Gamelogic.Global; + +// Placed on a GameObject in the ClientScene to execute connection logic on client startup. +public class Bootstrap : MonoBehaviour +{ + public WorkerConfigurationData Configuration = new WorkerConfigurationData(); + + // Called when the Play button is pressed in Unity. + public void Start() + { + SpatialOS.ApplyConfiguration(Configuration); + + Time.fixedDeltaTime = 1.0f / SimulationSettings.FixedFramerate; + + // Distinguishes between when the Unity is running as a client or a server. + switch (SpatialOS.Configuration.WorkerPlatform) + { + case WorkerPlatform.UnityWorker: + Application.targetFrameRate = SimulationSettings.TargetServerFramerate; + SpatialOS.OnDisconnected += reason => Application.Quit(); + SpatialOS.Connect(gameObject); + break; + case WorkerPlatform.UnityClient: + Application.targetFrameRate = SimulationSettings.TargetClientFramerate; + SpatialOS.OnConnected += CreatePlayer; + break; + } + } + + // Called when pressing Connect from the splash screen. + public void AttemptToConnectClient() + { + SpatialOS.Connect(gameObject); + } + + // Search for the PlayerCreator entity in the world in order to send a CreatePlayer command. + public static void CreatePlayer() + { + var playerCreatorQuery = Query.HasComponent().ReturnOnlyEntityIds(); + SpatialOS.WorkerCommands.SendQuery(playerCreatorQuery) + .OnSuccess(OnSuccessfulPlayerCreatorQuery) + .OnFailure(OnFailedPlayerCreatorQuery); + } + + private static void OnSuccessfulPlayerCreatorQuery(EntityQueryResult queryResult) + { + if (queryResult.EntityCount < 1) + { + Debug.LogError("Failed to find PlayerCreator. SpatialOS probably hadn't finished loading the initial snapshot. Try again in a few seconds."); + return; + } + + var playerCreatorEntityId = queryResult.Entities.First.Value.Key; + RequestPlayerCreation(playerCreatorEntityId); + } + + private static void OnFailedPlayerCreatorQuery(ICommandErrorDetails _) + { + Debug.LogError("PlayerCreator query failed. SpatialOS workers probably haven't started yet. Try again in a few seconds."); + } + + // Send a CreatePlayer command to the PLayerCreator entity requesting a Player entity be spawned. + private static void RequestPlayerCreation(EntityId playerCreatorEntityId) + { + SpatialOS.WorkerCommands.SendCommand(PlayerCreation.Commands.CreatePlayer.Descriptor, new CreatePlayerRequest(), playerCreatorEntityId) + .OnFailure(response => OnCreatePlayerFailure(response, playerCreatorEntityId)); + } + + private static void OnCreatePlayerFailure(ICommandErrorDetails _, EntityId playerCreatorEntityId) + { + Debug.LogWarning("CreatePlayer command failed - you probably tried to connect too soon. Try again in a few seconds."); + } +} diff --git a/workers/unity/Assets/EntityTemplates/PlayerShipEntityTemplate.cs.meta b/workers/unity/Assets/Gamelogic/Global/Bootstrap.cs.meta similarity index 75% rename from workers/unity/Assets/EntityTemplates/PlayerShipEntityTemplate.cs.meta rename to workers/unity/Assets/Gamelogic/Global/Bootstrap.cs.meta index 0f9c00d..e44e475 100644 --- a/workers/unity/Assets/EntityTemplates/PlayerShipEntityTemplate.cs.meta +++ b/workers/unity/Assets/Gamelogic/Global/Bootstrap.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: fee49f1f8f3e6014d832702a1673b5c3 -timeCreated: 1481486215 +guid: 0826dccda99bdef4d9cc703995b570aa +timeCreated: 1489075247 licenseType: Pro MonoImporter: serializedVersion: 2 diff --git a/workers/unity/Assets/Gamelogic/Global/PlayerCreatingBehaviour.cs b/workers/unity/Assets/Gamelogic/Global/PlayerCreatingBehaviour.cs new file mode 100644 index 0000000..88443e0 --- /dev/null +++ b/workers/unity/Assets/Gamelogic/Global/PlayerCreatingBehaviour.cs @@ -0,0 +1,61 @@ +using Assets.Gamelogic.EntityTemplates; +using Improbable; +using Improbable.Entity.Component; +using Improbable.Global; +using Improbable.Math; +using Improbable.Unity; +using Improbable.Unity.Core; +using Improbable.Unity.Visualizer; +using UnityEngine; + +namespace Assets.Gamelogic.Global +{ + [WorkerType(WorkerPlatform.UnityWorker)] + public class PlayerCreatingBehaviour : MonoBehaviour + { + [Require] + private PlayerCreation.Writer PlayerCreationWriter; + + private void OnEnable() + { + PlayerCreationWriter.CommandReceiver.OnCreatePlayer.RegisterResponse(OnCreatePlayer); + } + + private void OnDisable() + { + PlayerCreationWriter.CommandReceiver.OnCreatePlayer.DeregisterResponse(); + } + + private CreatePlayerResponse OnCreatePlayer(CreatePlayerRequest request, ICommandCallerInfo callerinfo) + { + CreatePlayerWithReservedId(callerinfo.CallerWorkerId); + return new CreatePlayerResponse(); + } + + private void CreatePlayerWithReservedId(string clientWorkerId) + { + SpatialOS.Commands.ReserveEntityId(PlayerCreationWriter) + .OnSuccess(reservedEntityId => CreatePlayer(clientWorkerId, reservedEntityId)) + .OnFailure(failure => OnFailedReservation(failure, clientWorkerId)); + } + + private void OnFailedReservation(ICommandErrorDetails response, string clientWorkerId) + { + Debug.LogError("Failed to Reserve EntityId for Player: " + response.ErrorMessage + ". Retrying..."); + CreatePlayerWithReservedId(clientWorkerId); + } + + private void CreatePlayer(string clientWorkerId, EntityId entityId) + { + var playerEntityTemplate = EntityTemplateFactory.CreatePlayerShipTemplate(clientWorkerId, Coordinates.ZERO); + SpatialOS.Commands.CreateEntity(PlayerCreationWriter, entityId, SimulationSettings.PlayerShipPrefabName, playerEntityTemplate) + .OnFailure(failure => OnFailedPlayerCreation(failure, clientWorkerId, entityId)); + } + + private void OnFailedPlayerCreation(ICommandErrorDetails response, string clientWorkerId, EntityId entityId) + { + Debug.LogError("Failed to Create PlayerShip Entity: " + response.ErrorMessage + ". Retrying..."); + CreatePlayer(clientWorkerId, entityId); + } + } +} diff --git a/workers/unity/Assets/EntityTemplates/PlayerSpawnerEntityTemplate.cs.meta b/workers/unity/Assets/Gamelogic/Global/PlayerCreatingBehaviour.cs.meta similarity index 75% rename from workers/unity/Assets/EntityTemplates/PlayerSpawnerEntityTemplate.cs.meta rename to workers/unity/Assets/Gamelogic/Global/PlayerCreatingBehaviour.cs.meta index 65d7457..c3ea870 100644 --- a/workers/unity/Assets/EntityTemplates/PlayerSpawnerEntityTemplate.cs.meta +++ b/workers/unity/Assets/Gamelogic/Global/PlayerCreatingBehaviour.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 8117a0eb02e39d44fa9e44bf82146586 -timeCreated: 1479293902 +guid: c2f084e4d9b056044aac654ad447ad51 +timeCreated: 1489078310 licenseType: Pro MonoImporter: serializedVersion: 2 diff --git a/workers/unity/Assets/Gamelogic/Global/SimulationSettings.cs b/workers/unity/Assets/Gamelogic/Global/SimulationSettings.cs new file mode 100644 index 0000000..e4bbc4b --- /dev/null +++ b/workers/unity/Assets/Gamelogic/Global/SimulationSettings.cs @@ -0,0 +1,35 @@ +using UnityEngine; + +namespace Assets.Gamelogic.Global +{ + public static class SimulationSettings + { + // Entity Prefab Names + public static readonly string PlayerShipPrefabName = "PlayerShip"; + public static readonly string PirateShipPrefabName = "PirateShip"; + public static readonly string PlayerCreatorPrefabName = "PlayerCreator"; + public static readonly string TerrainPrefabName = "Terrain"; + + // Worker Connection + public static readonly int TargetServerFramerate = 60; + public static readonly int TargetClientFramerate = 120; + public static readonly int FixedFramerate = 10; + + // Heartbeats + public static readonly float HeartbeatCheckIntervalSecs = 5; + public static readonly uint TotalHeartbeatsBeforeTimeout = 3; + public static readonly float HeartbeatSendingIntervalSecs = 5; + + // Pirates (used in lesson 8 of the tutorial!) + public static readonly int PiratesSpawnDiameter = 300; + public static readonly int TotalPirates = 50; + + // Connection + public static readonly float ClientConnectionTimeoutSecs = 7; + public static readonly float PlayerCreatorQueryRetrySecs = 4; + public static readonly float PlayerEntityCreationRetrySecs = 4; + + // Snapshot + public static readonly string DefaultSnapshotPath = Application.dataPath + "/../../../snapshots/default.snapshot"; + } +} diff --git a/workers/unity/Assets/EntityTemplates/TerrainEntityTemplate.cs.meta b/workers/unity/Assets/Gamelogic/Global/SimulationSettings.cs.meta similarity index 75% rename from workers/unity/Assets/EntityTemplates/TerrainEntityTemplate.cs.meta rename to workers/unity/Assets/Gamelogic/Global/SimulationSettings.cs.meta index 1e139bd..7509fa9 100644 --- a/workers/unity/Assets/EntityTemplates/TerrainEntityTemplate.cs.meta +++ b/workers/unity/Assets/Gamelogic/Global/SimulationSettings.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: d35092e22ba07d042bfeeb24b429d2fa -timeCreated: 1479293902 +guid: 9365b054fde6a3843aa76a7eb76372cf +timeCreated: 1489075273 licenseType: Pro MonoImporter: serializedVersion: 2 diff --git a/workers/unity/Assets/Gamelogic/Pirates.meta b/workers/unity/Assets/Gamelogic/Pirates.meta index 5337a26..7e07ceb 100644 --- a/workers/unity/Assets/Gamelogic/Pirates.meta +++ b/workers/unity/Assets/Gamelogic/Pirates.meta @@ -1,8 +1,8 @@ fileFormatVersion: 2 -guid: b1d73200fa1d20c4fb05d2c643084342 +guid: e11ff076829d5488cb9a1d60a8d3611a folderAsset: yes -timeCreated: 1461085861 -licenseType: Pro +timeCreated: 1490201948 +licenseType: Free DefaultImporter: userData: assetBundleName: diff --git a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/CameraEnablerVisualizer.cs b/workers/unity/Assets/Gamelogic/Pirates/Behaviours/CameraEnablerVisualizer.cs index 825ad02..0bdaa26 100644 --- a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/CameraEnablerVisualizer.cs +++ b/workers/unity/Assets/Gamelogic/Pirates/Behaviours/CameraEnablerVisualizer.cs @@ -1,31 +1,31 @@ -using Improbable.Ship; +using Improbable.Global; using Improbable.Unity; using Improbable.Unity.Visualizer; using UnityEngine; namespace Assets.Gamelogic.Pirates.Behaviours { - // Enable this MonoBehaviour on client workers only + // Add this MonoBehaviour on client workers only [WorkerType(WorkerPlatform.UnityClient)] public class CameraEnablerVisualizer : MonoBehaviour { /* - * Client will only have write-access for their own designated PlayerShip entity's ShipControls component, + * Clients will only have write-access for their own designated PlayerShip entity's ClientAuthorityCheck component, * so this MonoBehaviour will be enabled on the client's designated PlayerShip GameObject only and not on * the GameObject of other players' ships. */ - [Require] protected ShipControls.Writer ShipControlsWriter; + [Require] + private ClientAuthorityCheck.Writer ClientAuthorityCheckWriter; - public UnityEngine.Camera OurCamera; + [SerializeField] + private Vector3 CameraOffset; public void OnEnable() { - OurCamera.enabled = true; - } - - public void OnDisable() - { - OurCamera.enabled = false; + var camera = Camera.main; + camera.transform.parent = transform; + camera.transform.localPosition = CameraOffset; + camera.transform.LookAt(transform.position + Vector3.up); } } } diff --git a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/DecrementHealth.cs b/workers/unity/Assets/Gamelogic/Pirates/Behaviours/DecrementHealth.cs index f6fb066..75feaf6 100644 --- a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/DecrementHealth.cs +++ b/workers/unity/Assets/Gamelogic/Pirates/Behaviours/DecrementHealth.cs @@ -2,10 +2,9 @@ using Improbable.Unity; using Improbable.Unity.Visualizer; - namespace Assets.Gamelogic.Pirates.Behaviours { - // Enable this MonoBehaviour on FSim (server-side) workers only + // Add this MonoBehaviour on server-side workers only [WorkerType(WorkerPlatform.UnityWorker)] public class DecrementHealth : MonoBehaviour { diff --git a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerEntityLifecycleManager.cs b/workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerEntityLifecycleManager.cs deleted file mode 100644 index 25c307f..0000000 --- a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerEntityLifecycleManager.cs +++ /dev/null @@ -1,93 +0,0 @@ -using Improbable; -using Improbable.Entity.Component; -using Improbable.Player; -using Improbable.Unity; -using Improbable.Unity.Core; -using Improbable.Unity.Visualizer; -using Improbable.Worker; -using UnityEngine; - -namespace Assets.Gamelogic.Player -{ - // Enable this MonoBehaviour on FSim (server-side) workers only - [WorkerType(WorkerPlatform.UnityWorker)] - public class PlayerEntityLifecycleManager : MonoBehaviour - { - // Enable this MonoBehaviour only on the worker which has write-access for the entity's PlayerLifecycle component - [Require] private PlayerLifecycle.Writer PlayerLifecycleWriter; - - EntityId thisEntityId; - - void OnEnable() - { - // Cache entity id for faster retrieval - thisEntityId = gameObject.EntityId(); - - // Initialize heartbeat countdown - PlayerLifecycleWriter.Send(new PlayerLifecycle.Update().SetCurrentMissedHeartbeats(0)); - - // Register command callbacks - PlayerLifecycleWriter.CommandReceiver.OnDeletePlayer.RegisterResponse(OnDeletePlayer); - PlayerLifecycleWriter.CommandReceiver.OnHeartbeat.RegisterResponse(OnHeartbeat); - - // Periodic counter increase - InvokeRepeating("IncrementMissedHeartbeats", 0f, PlayerLifecycleWriter.Data.playerHeartbeatInterval); - } - - void OnDisable() - { - // Deregister command callbacks - PlayerLifecycleWriter.CommandReceiver.OnDeletePlayer.DeregisterResponse(); - PlayerLifecycleWriter.CommandReceiver.OnHeartbeat.DeregisterResponse(); - - CancelInvoke("IncrementMissedHeartbeats"); - } - - private DeletePlayerResponse OnDeletePlayer(DeletePlayerRequest Request, ICommandCallerInfo CallerInfo) - { - DeletePlayer(); - return new DeletePlayerResponse(); - } - - private void DeletePlayer() - { - // Use World Commands API to delete this entity - SpatialOS.Commands.DeleteEntity(PlayerLifecycleWriter, thisEntityId, result => - { - if (result.StatusCode != StatusCode.Success) - { - Debug.LogErrorFormat("PlayerEntityLifecycleManager failed to delete inactive player entity {0} with error message: {1}", thisEntityId, result.ErrorMessage); - return; - } - Debug.Log("PlayerEntityLifecycleManager deleted inactive player entity " + thisEntityId); - }); - } - - // Command callback for handling heartbeats from clients indicating client is connect and missed heartbeat counter should be reset - private HeartbeatResponse OnHeartbeat(HeartbeatRequest Request, ICommandCallerInfo CallerInfo) - { - // Heartbeats are issued by clients authoritative over the player entity and should only be sending heartbeats for themselves - if (Request.senderEntityId == thisEntityId) - { - // Reset missed heartbeat counter to avoid entity being deleted - PlayerLifecycleWriter.Send(new PlayerLifecycle.Update().SetCurrentMissedHeartbeats(0)); - } - // Acknowledge command receipt - return new HeartbeatResponse(); - } - - private void IncrementMissedHeartbeats() - { - if (PlayerLifecycleWriter.Data.currentMissedHeartbeats >= PlayerLifecycleWriter.Data.maxMissedHeartbeats) - { - // Delete entity if it has missed too many heartbeats - DeletePlayer(); - } - else - { - // Increment counter if time-out period has not elapsed - PlayerLifecycleWriter.Send(new PlayerLifecycle.Update().SetCurrentMissedHeartbeats(PlayerLifecycleWriter.Data.currentMissedHeartbeats + 1)); - } - } - } -} \ No newline at end of file diff --git a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerHeartbeatSender.cs b/workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerHeartbeatSender.cs deleted file mode 100644 index ed48237..0000000 --- a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerHeartbeatSender.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System; -using Improbable; -using Improbable.Player; -using Improbable.Ship; -using Improbable.Unity; -using Improbable.Unity.Core; -using Improbable.Unity.Visualizer; -using Improbable.Worker; -using UnityEngine; - -namespace Assets.Gamelogic.Player -{ - // Enable this MonoBehaviour on client workers only - [WorkerType(WorkerPlatform.UnityClient)] - public class PlayerHeartbeatSender : MonoBehaviour - { - /* - * Client will only have write-access for their own designated PlayerShip entity's ShipControls component, - * so this MonoBehaviour will be enabled on the client's designated PlayerShip GameObject only and not on - * the GameObject of other players' ships. - */ - [Require] private ShipControls.Writer ShipControlsWriter; - [Require] private PlayerLifecycle.Reader PlayerLifecycleReader; - - // Local tracking of missed heartbeats for log message purposes - private uint missed_heartbeats; - - private void OnEnable() - { - missed_heartbeats = PlayerLifecycleReader.Data.currentMissedHeartbeats; - InvokeRepeating("SendHeartbeat", 0f, PlayerLifecycleReader.Data.playerHeartbeatInterval); - - // Register callback for when components change - PlayerLifecycleReader.ComponentUpdated.Add(OnComponentUpdated); - } - - private void OnDisable() - { - // Deregister callback for when components change - PlayerLifecycleReader.ComponentUpdated.Remove(OnComponentUpdated); - } - - // Callback for whenever one or more property of the PlayerLifecycle component is updated - private void OnComponentUpdated(PlayerLifecycle.Update update) - { - // Update object will have values only for fields which have been updated - if (update.currentMissedHeartbeats.HasValue) - { - // Synchronize local missed heartbeat counter with server-side counter - missed_heartbeats = update.currentMissedHeartbeats.Value; - } - } - - private void SendHeartbeat() - { - // Issue heartbeat to indicate client is still connected, so player's entity is not deleted - EntityId thisEntityId = gameObject.EntityId(); - // Use Commands API to self: implementation of command will occur on server-side - // Any writer can be used when sending commmands - SpatialOS.Commands.SendCommand(ShipControlsWriter, PlayerLifecycle.Commands.Heartbeat.Descriptor, - new HeartbeatRequest(thisEntityId), thisEntityId, result => - { - if (result.StatusCode != StatusCode.Success) - { - missed_heartbeats++; - String msg = "Heartbeats recently failed: " + missed_heartbeats + ", max allowed: " + PlayerLifecycleReader.Data.maxMissedHeartbeats; - Debug.LogError(msg); - } - }); - if (missed_heartbeats >= PlayerLifecycleReader.Data.maxMissedHeartbeats) - { - Debug.LogWarning("Player entity is at risk of being deleted due to missed heartbeats"); - } - } - } -} \ No newline at end of file diff --git a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerHeartbeatSender.cs.meta b/workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerHeartbeatSender.cs.meta deleted file mode 100644 index 3af2b22..0000000 --- a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerHeartbeatSender.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 051f197ef5f2da645a97fd94bf1a5a66 -timeCreated: 1481217411 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerInputController.cs b/workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerInputController.cs index 8a8c5d7..572276a 100644 --- a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerInputController.cs +++ b/workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerInputController.cs @@ -2,10 +2,11 @@ using Improbable.Unity; using Improbable.Unity.Visualizer; using UnityEngine; +using Assets.Gamelogic.UI; namespace Assets.Gamelogic.Pirates.Behaviours { - // Enable this MonoBehaviour on client workers only + // Add this MonoBehaviour on client workers only [WorkerType(WorkerPlatform.UnityClient)] public class PlayerInputController : MonoBehaviour { @@ -14,9 +15,15 @@ public class PlayerInputController : MonoBehaviour * so this MonoBehaviour will be enabled on the client's designated PlayerShip GameObject only and not on * the GameObject of other players' ships. */ - [Require] private ShipControls.Writer ShipControlsWriter; + [Require] + private ShipControls.Writer ShipControlsWriter; - void Update () + void OnEnable() + { + SplashScreenController.HideSplashScreen(); + } + + void Update() { ShipControlsWriter.Send(new ShipControls.Update() .SetTargetSpeed(Mathf.Clamp01(Input.GetAxis("Vertical"))) diff --git a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerSpawnManager.cs b/workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerSpawnManager.cs deleted file mode 100644 index e42eb47..0000000 --- a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerSpawnManager.cs +++ /dev/null @@ -1,53 +0,0 @@ -using Improbable.Entity.Component; -using UnityEngine; -using Improbable.Unity.Visualizer; -using Improbable.Player; -using Improbable.Worker; -using Improbable.Unity; -using Improbable.Unity.Core; -using Assets.EntityTemplates; - -namespace Assets.Gamelogic.Pirates.Behaviours -{ - // Enable this MonoBehaviour on FSim (server-side) workers only - [WorkerType(WorkerPlatform.UnityWorker)] - public class PlayerSpawnManager : MonoBehaviour - { - // Enable this MonoBehaviour only on the worker which has write-access for the entity's Spawner component - [Require] private Spawner.Writer SpawnerWriter; - - void OnEnable() - { - // Register command callback - SpawnerWriter.CommandReceiver.OnSpawnPlayer.RegisterAsyncResponse(OnSpawnPlayer); - } - - void OnDisable() - { - // Deregister command callback - SpawnerWriter.CommandReceiver.OnSpawnPlayer.DeregisterResponse(); - } - - // Command callback for requests by new clients for a new player ship to be spawned - private void OnSpawnPlayer( - ResponseHandle Handle) - { - - var playerEntityTemplate = PlayerShipEntityTemplate.GeneratePlayerShipEntityTemplate(Handle.CallerInfo.CallerWorkerId, - Handle.Request.initialPosition); - SpatialOS.Commands.CreateEntity(SpawnerWriter, "PlayerShip", playerEntityTemplate, result => - { - if (result.StatusCode != StatusCode.Success) - { - Debug.LogError("PlayerSpawnManager failed to create entity: " + result.ErrorMessage); - return; - } - var createdEntityId = result.Response.Value; - Debug.Log("PlayerSpawnManager created player entity with entity ID: " + createdEntityId); - - // Acknowledge command receipt and provide client with ID for newly created entity - Handle.Respond(new SpawnPlayerResponse(createdEntityId)); - }); - } - } -} \ No newline at end of file diff --git a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/ScoreGUI.cs b/workers/unity/Assets/Gamelogic/Pirates/Behaviours/ScoreGUI.cs index b1cbdd7..3e4dd83 100644 --- a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/ScoreGUI.cs +++ b/workers/unity/Assets/Gamelogic/Pirates/Behaviours/ScoreGUI.cs @@ -1,4 +1,4 @@ -using Improbable.Ship; +using Improbable.Global; using Improbable.Unity; using Improbable.Unity.Visualizer; using UnityEngine; @@ -6,7 +6,7 @@ namespace Assets.Gamelogic.Pirates.Behaviours { - // Enable this MonoBehaviour on client workers only + // Add this MonoBehaviour on client workers only [WorkerType(WorkerPlatform.UnityClient)] public class ScoreGUI : MonoBehaviour { @@ -15,7 +15,8 @@ public class ScoreGUI : MonoBehaviour * so this MonoBehaviour will be enabled on the client's designated PlayerShip GameObject only and not on * the GameObject of other players' ships. */ - [Require] private ShipControls.Writer ShipControlsWriter; + [Require] + private ClientAuthorityCheck.Writer ClientAuthorityCheckWriter; private Text totalPointsGUI; diff --git a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/ShipController.cs b/workers/unity/Assets/Gamelogic/Pirates/Behaviours/ShipController.cs deleted file mode 100644 index 4776366..0000000 --- a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/ShipController.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Improbable.Ship; -using Improbable.Unity.Visualizer; -using UnityEngine; - -namespace Assets.Gamelogic.Pirates.Behaviours -{ - // This MonoBehaviour will be enabled on both client and server-side workers - public class ShipController : MonoBehaviour - { - // Inject access to the entity's ShipControls component - [Require] protected ShipControls.Reader ShipControlsReader; - - //Current speed (0-1 range) - private float targetSpeed; - public float currentSpeed { get; private set; } - - //Current steering value (-1 to 1 range) - private float targetSteering; - public float currentSteering { get; private set; } - - public void Update() - { - var inputSpeed = ShipControlsReader.Data.targetSpeed; - var inputSteering = ShipControlsReader.Data.targetSteering; - - var delta = Time.deltaTime; - - // Slowly decay the speed and steering values over time and make sharp turns slow down the ship. - targetSpeed = Mathf.Lerp(targetSpeed, 0f, delta * (0.5f + Mathf.Abs(targetSteering))); - targetSteering = Mathf.Lerp(targetSteering, 0f, delta * 3f); - - // Calculate the input-modified speed - targetSpeed = Mathf.Clamp01(targetSpeed + delta * inputSpeed); - currentSpeed = Mathf.Lerp(currentSpeed, targetSpeed, Mathf.Clamp01(delta * 5f)); - - // Steering is affected by speed -- the slower the ship moves, the less maneuverable is the ship - targetSteering = Mathf.Clamp(targetSteering + delta * 6 * inputSteering * (0.1f + 0.9f * currentSpeed), -1f, 1f); - currentSteering = Mathf.Lerp(currentSteering, targetSteering, delta * 5f); - } - } -} \ No newline at end of file diff --git a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/ShipMovement.cs b/workers/unity/Assets/Gamelogic/Pirates/Behaviours/ShipMovement.cs index 6111d87..b4f3d2d 100644 --- a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/ShipMovement.cs +++ b/workers/unity/Assets/Gamelogic/Pirates/Behaviours/ShipMovement.cs @@ -1,50 +1,99 @@ -using System; -using Improbable.General; +using Improbable.Global; using Improbable.Math; using Improbable.Ship; using Improbable.Unity.Visualizer; using UnityEngine; +using Improbable.Unity; namespace Assets.Gamelogic.Pirates.Behaviours { - // This MonoBehaviour will be enabled on both client and server-side workers + // Add this MonoBehaviour on both client and server-side workers public class ShipMovement : MonoBehaviour { /* - * An entity with this MonoBehaviour will have it enabled only for the single worker (whether client or FSim) + * An entity with this MonoBehaviour will have it enabled only for the single worker (whether client or server) * which has write-access for its WorldTransform component. */ - [Require] private WorldTransform.Writer WorldTransformWriter; + [Require] + private WorldTransform.Writer WorldTransformWriter; + [Require] + protected ShipControls.Reader ShipControlsReader; - public float MovementSpeed = 7; - public float TurningSpeed = 50; + private float targetSpeed; // [0..1] + private float currentSpeed; // [0..1] + private float targetSteering; // [-1..1] + private float currentSteering; // [-1..1] - private ShipController shipController; + [SerializeField] + private Rigidbody myRigidbody; + [SerializeField] + private float MovementSpeed; + [SerializeField] + private float TurningSpeed; - public void OnEnable() + private void OnEnable() { - shipController = GetComponent(); - // Initialize entity's gameobject transform from WorldTransform component values transform.position = WorldTransformWriter.Data.position.ToVector3(); transform.rotation = Quaternion.Euler(0.0f, WorldTransformWriter.Data.rotation, 0.0f); + myRigidbody.inertiaTensorRotation = Quaternion.identity; + } + + // Calculate speed and steer values ready from input for next physics actions in FixedUpdate + private void Update() + { + var inputSpeed = ShipControlsReader.Data.targetSpeed; + var inputSteering = ShipControlsReader.Data.targetSteering; + + var delta = Time.deltaTime; + + // Slowly decay the speed and steering values over time and make sharp turns slow down the ship. + targetSpeed = Mathf.Lerp(targetSpeed, 0f, delta * (0.5f + Mathf.Abs(targetSteering))); + targetSteering = Mathf.Lerp(targetSteering, 0f, delta * 3f); + + // Calculate the input-modified speed + targetSpeed = Mathf.Clamp01(targetSpeed + delta * inputSpeed); + currentSpeed = Mathf.Lerp(currentSpeed, targetSpeed, Mathf.Clamp01(delta * 5f)); + + // Steering is affected by speed -- the slower the ship moves, the less maneuverable is the ship + targetSteering = Mathf.Clamp(targetSteering + delta * 6 * inputSteering * (0.1f + 0.9f * currentSpeed), -1f, 1f); + currentSteering = Mathf.Lerp(currentSteering, targetSteering, delta * 5f); + } + + // Move ship using local speed and steer value + public void FixedUpdate() + { + var deltaTime = Time.deltaTime; + ApplyPhysicsToShip(deltaTime); + SendPositionAndRotationUpdates(); + } + + private void ApplyPhysicsToShip(double deltaTime) + { + var velocityChange = CalculateVelocityChange(deltaTime); + var torqueToApply = CalculateTorqueToApply(deltaTime); + + myRigidbody.AddTorque(torqueToApply); + myRigidbody.AddForce(velocityChange, ForceMode.VelocityChange); } - public void Update () + private Vector3 CalculateVelocityChange(double deltaTime) { - // Move ship using local steering values - if (shipController != null) - { - var delta = Time.deltaTime; - transform.rotation = transform.rotation* - Quaternion.Euler(0f, shipController.currentSteering*delta*TurningSpeed, 0f); - transform.position = transform.position + - transform.localRotation*Vector3.forward*(shipController.currentSpeed*delta*MovementSpeed); + var currentVelocity = myRigidbody.velocity; + var targetVelocity = transform.localRotation * Vector3.forward * (float)(currentSpeed * deltaTime * MovementSpeed); + return targetVelocity - currentVelocity; + } - // Synchronise transform across all workers - WorldTransformWriter.Send(new WorldTransform.Update().SetPosition(transform.position.ToCoordinates()) - .SetRotation((uint)transform.rotation.eulerAngles.y)); - } + private Vector3 CalculateTorqueToApply(double deltaTime) + { + return new Vector3(0f, currentSteering * (float)(deltaTime * TurningSpeed), 0f); + } + + private void SendPositionAndRotationUpdates() + { + WorldTransformWriter.Send(new WorldTransform.Update() + .SetPosition(transform.position.ToCoordinates()) + .SetRotation((uint)transform.rotation.eulerAngles.y)); } } diff --git a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/SinkingBehaviour.cs b/workers/unity/Assets/Gamelogic/Pirates/Behaviours/SinkingBehaviour.cs index 2cf8141..2597127 100644 --- a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/SinkingBehaviour.cs +++ b/workers/unity/Assets/Gamelogic/Pirates/Behaviours/SinkingBehaviour.cs @@ -1,11 +1,10 @@ -using Improbable.Ship; -using Improbable.Unity; +using Improbable.Unity; using Improbable.Unity.Visualizer; using UnityEngine; namespace Assets.Gamelogic.Pirates.Behaviours { - // Enable this MonoBehaviour on client workers only + // Add this MonoBehaviour on client workers only [WorkerType(WorkerPlatform.UnityClient)] public class SinkingBehaviour : MonoBehaviour { diff --git a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/TransformReceiver.cs b/workers/unity/Assets/Gamelogic/Pirates/Behaviours/TransformReceiver.cs index 70a131a..64b4740 100644 --- a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/TransformReceiver.cs +++ b/workers/unity/Assets/Gamelogic/Pirates/Behaviours/TransformReceiver.cs @@ -1,15 +1,16 @@ using UnityEngine; -using Improbable.General; +using Improbable.Global; using Improbable.Math; using Improbable.Unity.Visualizer; namespace Assets.Gamelogic.Pirates.Behaviours { - // This MonoBehaviour will be enabled on both client and server-side workers + // Add this MonoBehaviour on both client and server-side workers public class TransformReceiver : MonoBehaviour { // Inject access to the entity's WorldTransform component - [Require] private WorldTransform.Reader WorldTransformReader; + [Require] + private WorldTransform.Reader WorldTransformReader; void OnEnable() { @@ -24,7 +25,7 @@ void OnEnable() void OnDisable() { // Deregister callback for when component changes - WorldTransformReader.ComponentUpdated.Add(OnComponentUpdated); + WorldTransformReader.ComponentUpdated.Remove(OnComponentUpdated); } // Callback for whenever one or more property of the WorldTransform component is updated @@ -39,9 +40,13 @@ void OnComponentUpdated(WorldTransform.Update update) if (!WorldTransformReader.HasAuthority) { if (update.position.HasValue) + { transform.position = update.position.Value.ToVector3(); + } if (update.rotation.HasValue) + { transform.rotation = Quaternion.Euler(0.0f, update.rotation.Value, 0.0f); + } } } } @@ -50,7 +55,7 @@ public static class CoordinatesExtensions { public static Vector3 ToVector3(this Coordinates coordinates) { - return new Vector3((float) coordinates.X, (float) coordinates.Y, (float) coordinates.Z); + return new Vector3((float)coordinates.X, (float)coordinates.Y, (float)coordinates.Z); } } } \ No newline at end of file diff --git a/workers/unity/Assets/Gamelogic/Pirates/Bootstrap.cs b/workers/unity/Assets/Gamelogic/Pirates/Bootstrap.cs deleted file mode 100644 index 046f300..0000000 --- a/workers/unity/Assets/Gamelogic/Pirates/Bootstrap.cs +++ /dev/null @@ -1,89 +0,0 @@ -using Improbable.Unity; -using Improbable.Unity.Configuration; -using Improbable.Unity.Core; -using UnityEngine; -using Improbable.Player; -using Improbable; -using Improbable.Worker; -using Improbable.Collections; -using Improbable.Math; -using Improbable.Unity.Core.EntityQueries; - -// Placed on a gameobject in client scene to execute connection logic on client startup -public class Bootstrap : MonoBehaviour -{ - public WorkerConfigurationData Configuration = new WorkerConfigurationData(); - - public void Start() - { - SpatialOS.ApplyConfiguration(Configuration); - - switch (SpatialOS.Configuration.WorkerPlatform) - { - case WorkerPlatform.UnityWorker: - SpatialOS.OnDisconnected += reason => Application.Quit(); - - var targetFramerate = 120; - var fixedFramerate = 20; - - Application.targetFrameRate = targetFramerate; - Time.fixedDeltaTime = 1.0f / fixedFramerate; - break; - case WorkerPlatform.UnityClient: - SpatialOS.OnConnected += OnConnected; - break; - } - - SpatialOS.Connect(gameObject); - } - - public void OnConnected() - { - Debug.Log("Bootstrap connected to SpatialOS, finding player spawner..."); - GetPlayerSpawnerEntityId((playerSpawnerEntityId, errorMessage) => - { - if (errorMessage != null) - { - Debug.LogError("Bootstrap failed to get player spawner entity id: " + errorMessage); - return; - } - Debug.Log("Bootstrap found player spawner with entity id: " + playerSpawnerEntityId.Value); - - SpatialOS.WorkerCommands.SendCommand(Spawner.Commands.SpawnPlayer.Descriptor, - new SpawnPlayerRequest(SpatialOS.Configuration.WorkerId, - new Coordinates(0, 0, 0)), - playerSpawnerEntityId.Value, - result => - { - if (result.StatusCode != StatusCode.Success) - { - Debug.LogError("Bootstrap spawn player command failed: " + result.ErrorMessage); - return; - } - Debug.Log("Bootstrap created a player entity with ID: " + result.Response.Value.entityId); - }); - }); - } - - private delegate void GetPlayerSpawnerEntityIdDelegate(Option playerSpawnerEntityId, string errorMessage); - private void GetPlayerSpawnerEntityId(GetPlayerSpawnerEntityIdDelegate callback) - { - SpatialOS.WorkerCommands.SendQuery(Query.HasComponent().ReturnOnlyEntityIds(), result => - { - if (result.StatusCode != StatusCode.Success || !result.Response.HasValue) - { - callback(null, "Bootstrap find player spawner query failed with error: " + result.ErrorMessage); - return; - } - - var response = result.Response.Value; - if (response.EntityCount < 1) - { - callback(null, "Bootstrap failed to find player spawner: no entities found with the PlayerSpawner component"); - return; - } - var playerSpawnerEntityId = response.Entities.First.Value.Key; - callback(new Option(playerSpawnerEntityId), null); - }); - } -} \ No newline at end of file diff --git a/workers/unity/Assets/Gamelogic/Pirates/Bootstrap.cs.meta b/workers/unity/Assets/Gamelogic/Pirates/Bootstrap.cs.meta deleted file mode 100644 index 9f07f99..0000000 --- a/workers/unity/Assets/Gamelogic/Pirates/Bootstrap.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 361245ef8b4be284aa3e4b746081ecdf -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/workers/unity/Assets/Gamelogic/Pirates/Camera/CameraVisualizer.cs b/workers/unity/Assets/Gamelogic/Pirates/Camera/CameraVisualizer.cs deleted file mode 100644 index 8204743..0000000 --- a/workers/unity/Assets/Gamelogic/Pirates/Camera/CameraVisualizer.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Improbable.Unity; -using Improbable.Unity.Visualizer; -using UnityEngine; - -namespace Assets.Gamelogic.Pirates.Camera -{ - // Enable this MonoBehaviour on client workers only - [WorkerType(WorkerPlatform.UnityClient)] - public class CameraVisualizer : MonoBehaviour - { - public Transform CameraRoot; - public float RotateSpeed = 60.0f; - - void Update() - { - if (Input.GetKey(KeyCode.Q)) - { - CameraRoot.transform.Rotate(-Vector3.up * Time.deltaTime * RotateSpeed, Space.World); - } - else if (Input.GetKey(KeyCode.E)) - { - CameraRoot.transform.Rotate(Vector3.up * Time.deltaTime * RotateSpeed, Space.World); - } - } - } -} diff --git a/workers/unity/Assets/Gamelogic/Pirates/Camera/CameraVisualizer.cs.meta b/workers/unity/Assets/Gamelogic/Pirates/Camera/CameraVisualizer.cs.meta deleted file mode 100644 index 8b6dc6f..0000000 --- a/workers/unity/Assets/Gamelogic/Pirates/Camera/CameraVisualizer.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: b3b454d2aa45c4846a0385c0c9ec1f62 -timeCreated: 1451939987 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/workers/unity/Assets/Gamelogic/Pirates/Camera/LagRotation.cs b/workers/unity/Assets/Gamelogic/Pirates/Camera/LagRotation.cs deleted file mode 100644 index 52d47d9..0000000 --- a/workers/unity/Assets/Gamelogic/Pirates/Camera/LagRotation.cs +++ /dev/null @@ -1,28 +0,0 @@ -using UnityEngine; - -namespace Assets.Gamelogic.Pirates.Camera -{ - public class LagRotation : MonoBehaviour - { - public float Speed = 10f; - - Transform ourTransform; - Transform ourParent; - Quaternion ourLocalRotation; - Quaternion ourParentsRotation; - - void Start() - { - ourTransform = transform; - ourParent = ourTransform.parent; - ourLocalRotation = ourTransform.localRotation; - ourParentsRotation = ourParent.rotation; - } - - void LateUpdate() - { - ourParentsRotation = Quaternion.Slerp(ourParentsRotation, ourParent.rotation, Time.deltaTime * Speed); - ourTransform.rotation = ourParentsRotation * ourLocalRotation; - } - } -} \ No newline at end of file diff --git a/workers/unity/Assets/Gamelogic/Pirates/Camera/LagRotation.cs.meta b/workers/unity/Assets/Gamelogic/Pirates/Camera/LagRotation.cs.meta deleted file mode 100644 index 3a1f8d4..0000000 --- a/workers/unity/Assets/Gamelogic/Pirates/Camera/LagRotation.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 8ea6f4f49fb8f5c40a7ce3ea0e208bae -timeCreated: 1451932875 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/workers/unity/Assets/Gamelogic/Pirates/Camera/ShipCamera.cs b/workers/unity/Assets/Gamelogic/Pirates/Camera/ShipCamera.cs deleted file mode 100644 index e683e25..0000000 --- a/workers/unity/Assets/Gamelogic/Pirates/Camera/ShipCamera.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Assets.Gamelogic.Pirates.Behaviours; -using Improbable.Unity; -using Improbable.Unity.Visualizer; -using UnityEngine; - -namespace Assets.Gamelogic.Pirates.Camera -{ - // Enable this MonoBehaviour on client workers only - [WorkerType(WorkerPlatform.UnityClient)] - public class ShipCamera : MonoBehaviour - { - public ShipController Controller; - public AnimationCurve Distance; - public AnimationCurve Angle; - - private Transform ourTransform; - - void Start () - { - ourTransform = transform; - } - - void Update () - { - if (Controller != null) - { - var speed = Controller.currentSpeed; - var rot = Quaternion.Euler(Angle.Evaluate(speed), 0f, 0f); - ourTransform.localPosition = rot * Vector3.back * Distance.Evaluate(speed); - ourTransform.localRotation = rot; - } - } - } -} \ No newline at end of file diff --git a/workers/unity/Assets/Gamelogic/Pirates/Camera/ShipCamera.cs.meta b/workers/unity/Assets/Gamelogic/Pirates/Camera/ShipCamera.cs.meta deleted file mode 100644 index 10765d8..0000000 --- a/workers/unity/Assets/Gamelogic/Pirates/Camera/ShipCamera.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: b53c46c7523602648bd276013ac5bea0 -timeCreated: 1451932875 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/workers/unity/Assets/Gamelogic/Pirates/Cannons/CannonFirer.cs b/workers/unity/Assets/Gamelogic/Pirates/Cannons/CannonFirer.cs index cd992d4..e4ab3a6 100644 --- a/workers/unity/Assets/Gamelogic/Pirates/Cannons/CannonFirer.cs +++ b/workers/unity/Assets/Gamelogic/Pirates/Cannons/CannonFirer.cs @@ -1,6 +1,4 @@ -using Improbable.Ship; -using Improbable.Unity.Visualizer; -using UnityEngine; +using UnityEngine; namespace Assets.Gamelogic.Pirates.Cannons { @@ -14,5 +12,10 @@ private void Start() // Cache entity's cannon gameobject cannon = gameObject.GetComponent(); } + + private void FireCannon(Vector3 direction) + { + cannon.Fire(direction); + } } } \ No newline at end of file diff --git a/workers/unity/Assets/Gamelogic/Pirates/Cannons/DestroyCannonball.cs b/workers/unity/Assets/Gamelogic/Pirates/Cannons/DestroyCannonball.cs index 6e61a2e..9ee4512 100644 --- a/workers/unity/Assets/Gamelogic/Pirates/Cannons/DestroyCannonball.cs +++ b/workers/unity/Assets/Gamelogic/Pirates/Cannons/DestroyCannonball.cs @@ -7,7 +7,7 @@ namespace Assets.Gamelogic.Pirates.Cannons public class DestroyCannonball : MonoBehaviour { public float SecondsUntilDestroy = 4f; - public Option firerEntityId = new Option(); + public Option firerEntityId = new Option(); private float spawnTime; void Start() diff --git a/workers/unity/Assets/Gamelogic/Pirates/Water/RepositionWater.cs b/workers/unity/Assets/Gamelogic/Pirates/Water/RepositionWater.cs index ec908ca..61294c4 100644 --- a/workers/unity/Assets/Gamelogic/Pirates/Water/RepositionWater.cs +++ b/workers/unity/Assets/Gamelogic/Pirates/Water/RepositionWater.cs @@ -7,12 +7,12 @@ public class RepositionWater : MonoBehaviour private Transform ourTransform; private Transform cameraTransform; - void Start () + void Start() { ourTransform = transform; - if (UnityEngine.Camera.main) + if (Camera.main) { - cameraTransform = UnityEngine.Camera.main.transform; + cameraTransform = Camera.main.transform; } } @@ -31,9 +31,9 @@ void LateUpdate() } else { - if (UnityEngine.Camera.main) + if (Camera.main) { - cameraTransform = UnityEngine.Camera.main.transform; + cameraTransform = Camera.main.transform; } } } diff --git a/workers/unity/Assets/Gamelogic/Pirates/Water/Water.cs b/workers/unity/Assets/Gamelogic/Pirates/Water/Water.cs index d6a1872..83c8941 100644 --- a/workers/unity/Assets/Gamelogic/Pirates/Water/Water.cs +++ b/workers/unity/Assets/Gamelogic/Pirates/Water/Water.cs @@ -380,19 +380,19 @@ Vector4 CameraSpacePlane(UnityEngine.Camera cam, Vector3 pos, Vector3 normal, fl static void CalculateReflectionMatrix(ref Matrix4x4 reflectionMat, Vector4 plane) { reflectionMat.m00 = (1F - 2F * plane[0] * plane[0]); - reflectionMat.m01 = (- 2F * plane[0] * plane[1]); - reflectionMat.m02 = (- 2F * plane[0] * plane[2]); - reflectionMat.m03 = (- 2F * plane[3] * plane[0]); + reflectionMat.m01 = (-2F * plane[0] * plane[1]); + reflectionMat.m02 = (-2F * plane[0] * plane[2]); + reflectionMat.m03 = (-2F * plane[3] * plane[0]); - reflectionMat.m10 = (- 2F * plane[1] * plane[0]); + reflectionMat.m10 = (-2F * plane[1] * plane[0]); reflectionMat.m11 = (1F - 2F * plane[1] * plane[1]); - reflectionMat.m12 = (- 2F * plane[1] * plane[2]); - reflectionMat.m13 = (- 2F * plane[3] * plane[1]); + reflectionMat.m12 = (-2F * plane[1] * plane[2]); + reflectionMat.m13 = (-2F * plane[3] * plane[1]); - reflectionMat.m20 = (- 2F * plane[2] * plane[0]); - reflectionMat.m21 = (- 2F * plane[2] * plane[1]); + reflectionMat.m20 = (-2F * plane[2] * plane[0]); + reflectionMat.m21 = (-2F * plane[2] * plane[1]); reflectionMat.m22 = (1F - 2F * plane[2] * plane[2]); - reflectionMat.m23 = (- 2F * plane[3] * plane[2]); + reflectionMat.m23 = (-2F * plane[3] * plane[2]); reflectionMat.m30 = 0F; reflectionMat.m31 = 0F; diff --git a/workers/unity/Assets/Gamelogic/Player.meta b/workers/unity/Assets/Gamelogic/Player.meta new file mode 100644 index 0000000..b45d105 --- /dev/null +++ b/workers/unity/Assets/Gamelogic/Player.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 44662d1da6a5c3a4498cc536030118ac +folderAsset: yes +timeCreated: 1490916821 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/workers/unity/Assets/Gamelogic/Player/HandleClientConnection.cs b/workers/unity/Assets/Gamelogic/Player/HandleClientConnection.cs new file mode 100644 index 0000000..61e18eb --- /dev/null +++ b/workers/unity/Assets/Gamelogic/Player/HandleClientConnection.cs @@ -0,0 +1,70 @@ +using Assets.Gamelogic.Global; +using Assets.Gamelogic.Utils; +using Improbable.Entity.Component; +using Improbable.Player; +using Improbable.Unity.Visualizer; +using UnityEngine; +using Improbable.Unity; +using Improbable.Unity.Core; + +namespace Assets.Gamelogic.Player +{ + [WorkerType(WorkerPlatform.UnityWorker)] + public class HandleClientConnection : MonoBehaviour + { + [Require] + private ClientConnection.Writer ClientConnectionWriter; + + private Coroutine heartbeatCoroutine; + + private void OnEnable() + { + ClientConnectionWriter.CommandReceiver.OnDisconnectClient.RegisterAsyncResponse(OnDisconnectClient); + ClientConnectionWriter.CommandReceiver.OnHeartbeat.RegisterResponse(OnHeartbeat); + heartbeatCoroutine = StartCoroutine(TimerUtils.CallRepeatedly(SimulationSettings.HeartbeatCheckIntervalSecs, CheckHeartbeat)); + } + + private void OnDisable() + { + ClientConnectionWriter.CommandReceiver.OnHeartbeat.DeregisterResponse(); + StopCoroutine(heartbeatCoroutine); + } + + private void OnDisconnectClient(ResponseHandle handle) + { + SpatialOS.Commands.DeleteEntity(ClientConnectionWriter, gameObject.EntityId()); + } + + private HeartbeatResponse OnHeartbeat(HeartbeatRequest request, ICommandCallerInfo callerinfo) + { + SetHeartbeat(SimulationSettings.TotalHeartbeatsBeforeTimeout); + return new HeartbeatResponse(); + } + + private void SetHeartbeat(uint beats) + { + var update = new ClientConnection.Update(); + update.SetTimeoutBeatsRemaining(beats); + ClientConnectionWriter.Send(update); + } + + private void CheckHeartbeat() + { + var heartbeatsRemainingBeforeTimeout = ClientConnectionWriter.Data.timeoutBeatsRemaining; + if (heartbeatsRemainingBeforeTimeout == 0) + { + StopCoroutine(heartbeatCoroutine); + DeletePlayerEntity(); + return; + } + SetHeartbeat(heartbeatsRemainingBeforeTimeout - 1); + } + + private void DeletePlayerEntity() + { + SpatialOS.Commands.DeleteEntity(ClientConnectionWriter, gameObject.EntityId()); + } + } +} diff --git a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerSpawnManager.cs.meta b/workers/unity/Assets/Gamelogic/Player/HandleClientConnection.cs.meta similarity index 76% rename from workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerSpawnManager.cs.meta rename to workers/unity/Assets/Gamelogic/Player/HandleClientConnection.cs.meta index 42cfaad..46ee6dd 100644 --- a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/PlayerSpawnManager.cs.meta +++ b/workers/unity/Assets/Gamelogic/Player/HandleClientConnection.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 052a4a222c049714f9c266a6b483aa16 -timeCreated: 1479219079 +guid: 43e2ddcaec3d1bf4583c49a494523e08 +timeCreated: 1490916831 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/workers/unity/Assets/Gamelogic/Player/SendClientConnection.cs b/workers/unity/Assets/Gamelogic/Player/SendClientConnection.cs new file mode 100644 index 0000000..8ed4f0b --- /dev/null +++ b/workers/unity/Assets/Gamelogic/Player/SendClientConnection.cs @@ -0,0 +1,44 @@ +using Assets.Gamelogic.Global; +using UnityEngine; +using Assets.Gamelogic.Utils; +using Improbable.Global; +using Improbable.Player; +using Improbable.Unity; +using Improbable.Unity.Core; +using Improbable.Unity.Visualizer; + +namespace Assets.Gamelogic.Player +{ + [WorkerType(WorkerPlatform.UnityClient)] + public class SendClientConnection : MonoBehaviour + { + [Require] + private ClientAuthorityCheck.Writer ClientAuthorityCheckWriter; + + private Coroutine heartbeatCoroutine; + + private void OnEnable() + { + heartbeatCoroutine = StartCoroutine(TimerUtils.CallRepeatedly(SimulationSettings.HeartbeatSendingIntervalSecs, SendHeartbeat)); + } + + private void OnDisable() + { + StopCoroutine(heartbeatCoroutine); + } + + private void SendHeartbeat() + { + SpatialOS.Commands.SendCommand(ClientAuthorityCheckWriter, ClientConnection.Commands.Heartbeat.Descriptor, new HeartbeatRequest(), gameObject.EntityId()); + } + + private void OnApplicationQuit() + { + if (SpatialOS.IsConnected) + { + SpatialOS.Commands.SendCommand(ClientAuthorityCheckWriter, ClientConnection.Commands.DisconnectClient.Descriptor, new ClientDisconnectRequest(), gameObject.EntityId()); + } + } + } +} + diff --git a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/ShipController.cs.meta b/workers/unity/Assets/Gamelogic/Player/SendClientConnection.cs.meta similarity index 76% rename from workers/unity/Assets/Gamelogic/Pirates/Behaviours/ShipController.cs.meta rename to workers/unity/Assets/Gamelogic/Player/SendClientConnection.cs.meta index 35f9875..201e687 100644 --- a/workers/unity/Assets/Gamelogic/Pirates/Behaviours/ShipController.cs.meta +++ b/workers/unity/Assets/Gamelogic/Player/SendClientConnection.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: d9e8cb129b8451f44aa7182ee5ffb3e1 -timeCreated: 1451932875 +guid: 69ac03230da460a428482816c6a3e668 +timeCreated: 1490916831 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/workers/unity/Assets/Gamelogic/Pirates/Shaders.meta b/workers/unity/Assets/Gamelogic/Shaders.meta similarity index 100% rename from workers/unity/Assets/Gamelogic/Pirates/Shaders.meta rename to workers/unity/Assets/Gamelogic/Shaders.meta diff --git a/workers/unity/Assets/Gamelogic/Pirates/Shaders/ReapplyShaders.cs b/workers/unity/Assets/Gamelogic/Shaders/ReapplyShaders.cs similarity index 96% rename from workers/unity/Assets/Gamelogic/Pirates/Shaders/ReapplyShaders.cs rename to workers/unity/Assets/Gamelogic/Shaders/ReapplyShaders.cs index 10a3e6c..58036b4 100644 --- a/workers/unity/Assets/Gamelogic/Pirates/Shaders/ReapplyShaders.cs +++ b/workers/unity/Assets/Gamelogic/Shaders/ReapplyShaders.cs @@ -2,7 +2,7 @@ using Improbable.Unity; using Improbable.Unity.Visualizer; -namespace Assets.Gamelogic.Pirates.Shaders +namespace Assets.Gamelogic.Shaders { // Enable this MonoBehaviour on client workers only [WorkerType(WorkerPlatform.UnityClient)] diff --git a/workers/unity/Assets/Gamelogic/Pirates/Shaders/ReapplyShaders.cs.meta b/workers/unity/Assets/Gamelogic/Shaders/ReapplyShaders.cs.meta similarity index 100% rename from workers/unity/Assets/Gamelogic/Pirates/Shaders/ReapplyShaders.cs.meta rename to workers/unity/Assets/Gamelogic/Shaders/ReapplyShaders.cs.meta diff --git a/workers/unity/Assets/Gamelogic/Pirates/Camera.meta b/workers/unity/Assets/Gamelogic/UI.meta similarity index 67% rename from workers/unity/Assets/Gamelogic/Pirates/Camera.meta rename to workers/unity/Assets/Gamelogic/UI.meta index 7de7dbf..3e3827d 100644 --- a/workers/unity/Assets/Gamelogic/Pirates/Camera.meta +++ b/workers/unity/Assets/Gamelogic/UI.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 -guid: 80ad4266fb979b2459fc39a7da2fafc6 +guid: 51e77aeca68a78d4f89a44d1781999d7 folderAsset: yes -timeCreated: 1464099469 +timeCreated: 1488904093 licenseType: Pro DefaultImporter: userData: diff --git a/workers/unity/Assets/Gamelogic/UI/CursorHoverEffect.cs b/workers/unity/Assets/Gamelogic/UI/CursorHoverEffect.cs new file mode 100644 index 0000000..761f782 --- /dev/null +++ b/workers/unity/Assets/Gamelogic/UI/CursorHoverEffect.cs @@ -0,0 +1,33 @@ +using UnityEngine; +using UnityEngine.UI; + +namespace Assets.Gamelogic.UI +{ + public class CursorHoverEffect : MonoBehaviour + { + [SerializeField] + Texture2D HandCursor; + + public void ShowButtonCursor() + { + if (GetComponent