From 732cea74ce6828c8087b689a716aee261b000e2e Mon Sep 17 00:00:00 2001 From: Amy Reeve Date: Thu, 14 Nov 2024 10:18:52 +0000 Subject: [PATCH] Develop into main (#1379) Co-authored-by: Vic Cooper Co-authored-by: Vic Cooper <63712500+Vic-Cooper@users.noreply.github.com> Co-authored-by: Noel Stephens Co-authored-by: Fernando Cortez Co-authored-by: amanda-butler-unity <96449283+amanda-butler-unity@users.noreply.github.com> --- docs/basics/playerobjects.md | 2 +- docs/learn/bitesize/bitesize-introduction.md | 9 ++-- docs/learn/bitesize/bitesize-socialhub.md | 50 +++++++++++++++++++ .../distributed-authority-quick-start.md | 49 +++--------------- docs/terms-concepts/distributed-authority.md | 1 + sidebars.js | 4 ++ 6 files changed, 69 insertions(+), 46 deletions(-) create mode 100644 docs/learn/bitesize/bitesize-socialhub.md diff --git a/docs/basics/playerobjects.md b/docs/basics/playerobjects.md index fa0439b42..db2b9dab8 100644 --- a/docs/basics/playerobjects.md +++ b/docs/basics/playerobjects.md @@ -99,4 +99,4 @@ To find your own player object just pass `NetworkManager.Singleton.LocalClientId - [NetworkManager](../components/networkmanager.md) - [Distributed authority topologies](../terms-concepts/distributed-authority.md) - [Client-server topologies](../terms-concepts/client-server.md) -- [Object spawning](objectspawning.md) +- [Object spawning](object-spawning.md) diff --git a/docs/learn/bitesize/bitesize-introduction.md b/docs/learn/bitesize/bitesize-introduction.md index f4acedded..b5dfe9dc3 100644 --- a/docs/learn/bitesize/bitesize-introduction.md +++ b/docs/learn/bitesize/bitesize-introduction.md @@ -6,10 +6,11 @@ title: About Bitesize samples The Bitesize Samples repository provides a series of sample code as modules to use in your games and better understand Netcode for GameObjects (Netcode). * [Multiplayer Use Cases](bitesize-usecases.md) - Learn more about core Netcode For GameObjects (Netcode) features through practical examples and In-Editor tutorials. -* [2D Space Shooter Sample](bitesize-spaceshooter.md) - Learn more about physics movement and status effects using Netcode `NetworkVariables` and `ObjectPooling`. -* [Invaders Sample](bitesize-invaders.md) - Learn more about game flow, modes, unconventional movement networked, and a shared timer. -* [Client Driven Sample](bitesize-clientdriven.md) - Learn more about Client driven movements, networked physics, spawning vs statically placed objects, object reparenting. -* [Dynamic Addressables Network Prefabs](bitesize-dynamicprefabs.md) - Learn more about the dynamic prefab system, which allows us to add new spawnable prefabs at runtime. +* [2D Space Shooter](bitesize-spaceshooter.md) - Learn more about physics movement and status effects using Netcode `NetworkVariables` and `ObjectPooling`. +* [Invaders](bitesize-invaders.md) - Learn more about game flow, modes, unconventional movement networked, and a shared timer. +* [Client Driven](bitesize-clientdriven.md) - Learn more about Client driven movements, networked physics, spawning vs statically placed objects, object reparenting. +* [Dynamic Addressables Network Prefabs](bitesize-dynamicprefabs.md) - Learn more about the dynamic prefab system, which allows you to add new spawnable prefabs at runtime. +* [Distributed Authority Social Hub](bitesize-socialhub.md) - Learn how to use features of distributed authority like host migration and NetworkObject ownership transfer. ## Requirements diff --git a/docs/learn/bitesize/bitesize-socialhub.md b/docs/learn/bitesize/bitesize-socialhub.md new file mode 100644 index 000000000..a4283525a --- /dev/null +++ b/docs/learn/bitesize/bitesize-socialhub.md @@ -0,0 +1,50 @@ +--- +id: bitesize-socialhub +title: Distributed Authority Social Hub sample +description: Learn about the scenes in the Distributed Authority Social Hub sample. +--- + +The [Distributed Authority Social Hub Sample](https://github.com/Unity-Technologies/com.unity.multiplayer.samples.bitesize/tree/main/Basic/DistributedAuthoritySocialHub) is a project that demonstrates Distributed Authority's features and helps you integrate Distributed Authority into your own game projects. + +Within Social Hub, you can explore Distributed Authority in a sandbox-like environment. You can: + +- Automatically redistribute ownership of NetworkObjects across connected clients +- Experience responsive gameplay through client-side NetworkObject spawning and deferred NetworkObject despawning +- Transfer ownership of NetworkObjects with variable ownership flags +- Host migration of a networked game session + +## Prerequisites + +Social Hub uses services from Unity Gaming Services to facilitate connectivity between players. To use these services inside your project, you must: + +1. [Create an organization](https://support.unity.com/hc/en-us/articles/208592876-How-do-I-create-a-new-Unity-organization) inside the Unity Dashboard. +2. Register your Unity project with that organization's cloud ID. + +## The Bootstrap scene + +This is the entry point to the sample. After the Bootstrap scene loads, the MainMenu scene appears. + +**Note**: Be sure you have registered the project with a cloud ID. + +## The MainMenu scene + +To create or join an existing game: + +1. Enter a player name and a session name. +2. Select **Start**. + +A successful load indicates that you have correctly registered your project with a cloud ID. + +## The HubScene_TownMarket scene + +This a sandbox-like environment that supports 64 players. The control model is WASD controls. Move around the level with client-authority, and use **E** to interact with crates and pots. These are NetworkObjects that you can pick up, drop, and throw. Attach one NetworkObject to another with an animated rig through the use of FixedJoints. As a client picks up a NetworkObject, authority of that NetworkObject transfers to that client. + +A client has authority over its player NetworkObject. Therefore, the movement, animations, and interactions that a client performs are client-authoritative. + +This sample inherently supports host migration out of the box. Load multiple clients, and witness the automatic distribution of ownership of NetworkObjects when the original session owner leaves the session. + +## Additional resources + +- Get help and ask questions on [Multiplayer Discussions](https://discussions.unity.com/lists/multiplayer). +- Join the community of Multiplayer creators on the [Multiplayer Networking Discord](https://discord.gg/unity-multiplayer-network). +- [Request a feature or report a bug](https://github.com/Unity-Technologies/com.unity.multiplayer.samples.bitesize/issues/new/choose). diff --git a/docs/learn/distributed-authority-quick-start.md b/docs/learn/distributed-authority-quick-start.md index 178ad6744..9f143096d 100644 --- a/docs/learn/distributed-authority-quick-start.md +++ b/docs/learn/distributed-authority-quick-start.md @@ -180,7 +180,6 @@ public class PlayerCubeControllerEditor : NetworkTransformEditor private SerializedProperty m_Speed; private SerializedProperty m_ApplyVerticalInputToZAxis; - public override void OnEnable() { m_Speed = serializedObject.FindProperty(nameof(PlayerCubeController.Speed)); @@ -188,41 +187,18 @@ public class PlayerCubeControllerEditor : NetworkTransformEditor base.OnEnable(); } + private void DisplayPlayerCubeControllerProperties() + { + EditorGUILayout.PropertyField(m_Speed); + EditorGUILayout.PropertyField(m_ApplyVerticalInputToZAxis); + } public override void OnInspectorGUI() { var playerCubeController = target as PlayerCubeController; - - - playerCubeController.PlayerCubeControllerPropertiesVisible = EditorGUILayout.BeginFoldoutHeaderGroup(playerCubeController.PlayerCubeControllerPropertiesVisible, $"{nameof(PlayerCubeController)} Properties"); - if (playerCubeController.PlayerCubeControllerPropertiesVisible) - { - EditorGUILayout.PropertyField(m_Speed); - EditorGUILayout.PropertyField(m_ApplyVerticalInputToZAxis); - } - EditorGUILayout.EndFoldoutHeaderGroup(); - - - EditorGUILayout.Space(); - - - playerCubeController.NetworkTransformPropertiesVisible = EditorGUILayout.BeginFoldoutHeaderGroup(playerCubeController.NetworkTransformPropertiesVisible, $"{nameof(NetworkTransform)} Properties"); - if (playerCubeController.NetworkTransformPropertiesVisible) - { - // End the header group prior to invoking the base OnInspectorGUID in order to avoid nested - // foldout groups. - EditorGUILayout.EndFoldoutHeaderGroup(); - // If NetworkTransform properties are visible, then both the properties any modified properties - // will be applied. - base.OnInspectorGUI(); - } - else - { - // End the header group - EditorGUILayout.EndFoldoutHeaderGroup(); - // If NetworkTransform properties are not visible, then make sure we apply any modified properties. - serializedObject.ApplyModifiedProperties(); - } + void SetExpanded(bool expanded) { playerCubeController.PlayerCubeControllerPropertiesVisible = expanded; }; + DrawFoldOutGroup(playerCubeController.GetType(), DisplayPlayerCubeControllerProperties, playerCubeController.PlayerCubeControllerPropertiesVisible, SetExpanded); + base.OnInspectorGUI(); } } #endif @@ -235,17 +211,11 @@ public class PlayerCubeController : NetworkTransform // within the inspector view will be saved and restored the next time the // asset/prefab is viewed. public bool PlayerCubeControllerPropertiesVisible; - public bool NetworkTransformPropertiesVisible; #endif - - public float Speed = 10; public bool ApplyVerticalInputToZAxis; - - private Vector3 m_Motion; - private void Update() { // If not spawned or we don't have authority, then don't update @@ -254,12 +224,10 @@ public class PlayerCubeController : NetworkTransform return; } - // Handle acquiring and applying player input m_Motion = Vector3.zero; m_Motion.x = Input.GetAxis("Horizontal"); - // Determine whether the vertical input is applied to the Y or Z axis if (!ApplyVerticalInputToZAxis) { @@ -270,7 +238,6 @@ public class PlayerCubeController : NetworkTransform m_Motion.z = Input.GetAxis("Vertical"); } - // If there is any player input magnitude, then apply that amount of // motion to the transform if (m_Motion.magnitude > 0) diff --git a/docs/terms-concepts/distributed-authority.md b/docs/terms-concepts/distributed-authority.md index 44614dfce..c898eb0d5 100644 --- a/docs/terms-concepts/distributed-authority.md +++ b/docs/terms-concepts/distributed-authority.md @@ -50,3 +50,4 @@ For more information about how distributed authority works in Netcode for GameOb - [Race conditions](../basics/race-conditions.md) - [Spawning synchronization](../basics/spawning-synchronization.md) - [Deferred despawning](../basics/deferred-despawning.md) +- [Distributed Authority Social Hub sample](../learn/bitesize/bitesize-socialhub.md) diff --git a/sidebars.js b/sidebars.js index 1dd9ad9aa..9ae218c72 100644 --- a/sidebars.js +++ b/sidebars.js @@ -578,6 +578,10 @@ module.exports = { "type": "doc", "id": "learn/bitesize/bitesize-dynamicPrefabs" }, + { + "type": "doc", + "id": "learn/bitesize/bitesize-socialhub" + }, ] }, {