From 3c2d04f4c0e6ee53650412e4ac59e44d3735f094 Mon Sep 17 00:00:00 2001 From: Fernando Cortez Date: Wed, 14 Aug 2024 12:57:32 -0400 Subject: [PATCH 1/6] asmdefs generated with dependencies mapped --- .../Scripts/Editor/AvatarTransformEditor.cs | 4 ++-- ...multiplayer.samples.socialhub.editor.asmdef | 16 ++++++++++++++++ ...player.samples.socialhub.editor.asmdef.meta | 7 +++++++ ...ltiplayer.samples.socialhub.gameplay.asmdef | 17 +++++++++++++++++ ...ayer.samples.socialhub.gameplay.asmdef.meta | 7 +++++++ .../Assets/Scripts/Input/AvatarInputs.cs | 4 +++- ....multiplayer.samples.socialhub.input.asmdef | 16 ++++++++++++++++ ...iplayer.samples.socialhub.input.asmdef.meta | 7 +++++++ .../Assets/Scripts/Player/AvatarTransform.cs | 7 +++---- ...multiplayer.samples.socialhub.player.asmdef | 18 ++++++++++++++++++ ...player.samples.socialhub.player.asmdef.meta | 7 +++++++ 11 files changed, 103 insertions(+), 7 deletions(-) create mode 100644 Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/com.unity.multiplayer.samples.socialhub.editor.asmdef create mode 100644 Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/com.unity.multiplayer.samples.socialhub.editor.asmdef.meta create mode 100644 Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/com.unity.multiplayer.samples.socialhub.gameplay.asmdef create mode 100644 Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/com.unity.multiplayer.samples.socialhub.gameplay.asmdef.meta create mode 100644 Experimental/DistributedAuthoritySample/Assets/Scripts/Input/com.unity.multiplayer.samples.socialhub.input.asmdef create mode 100644 Experimental/DistributedAuthoritySample/Assets/Scripts/Input/com.unity.multiplayer.samples.socialhub.input.asmdef.meta create mode 100644 Experimental/DistributedAuthoritySample/Assets/Scripts/Player/com.unity.multiplayer.samples.socialhub.player.asmdef create mode 100644 Experimental/DistributedAuthoritySample/Assets/Scripts/Player/com.unity.multiplayer.samples.socialhub.player.asmdef.meta diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/AvatarTransformEditor.cs b/Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/AvatarTransformEditor.cs index f2282a912..ab772c38b 100644 --- a/Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/AvatarTransformEditor.cs +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/AvatarTransformEditor.cs @@ -1,10 +1,10 @@ -using com.unity.multiplayer.samples.distributed_authority.gameplay; +using com.unity.multiplayer.samples.socialhub.player; using UnityEditor; using UnityEditor.UIElements; using UnityEngine; using UnityEngine.UIElements; -namespace com.unity.multiplayer.samples.distributed_authority.editor +namespace com.unity.multiplayer.samples.socialhub.editor { [CustomEditor(typeof(AvatarTransform))] class DerivedComponentEditor : Editor diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/com.unity.multiplayer.samples.socialhub.editor.asmdef b/Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/com.unity.multiplayer.samples.socialhub.editor.asmdef new file mode 100644 index 000000000..27f97af4c --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/com.unity.multiplayer.samples.socialhub.editor.asmdef @@ -0,0 +1,16 @@ +{ + "name": "com.unity.multiplayer.samples.socialhub.editor", + "rootNamespace": "com.unity.multiplayer.samples.socialhub", + "references": [ + "GUID:8314b31eee3cc495ca4a4f078575802d" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/com.unity.multiplayer.samples.socialhub.editor.asmdef.meta b/Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/com.unity.multiplayer.samples.socialhub.editor.asmdef.meta new file mode 100644 index 000000000..fb0b64c54 --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/com.unity.multiplayer.samples.socialhub.editor.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 6846e1cea5ff5448bb199c1d5674fd09 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/com.unity.multiplayer.samples.socialhub.gameplay.asmdef b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/com.unity.multiplayer.samples.socialhub.gameplay.asmdef new file mode 100644 index 000000000..dd6ff4baa --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/com.unity.multiplayer.samples.socialhub.gameplay.asmdef @@ -0,0 +1,17 @@ +{ + "name": "com.unity.multiplayer.samples.socialhub.gameplay", + "rootNamespace": "com.unity.multiplayer.samples.socialhub", + "references": [ + "GUID:1491147abca9d7d4bb7105af628b223e", + "GUID:c15e7f658578345fcb824b0a64d4dbe8" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/com.unity.multiplayer.samples.socialhub.gameplay.asmdef.meta b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/com.unity.multiplayer.samples.socialhub.gameplay.asmdef.meta new file mode 100644 index 000000000..5700dc7bb --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/com.unity.multiplayer.samples.socialhub.gameplay.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 9ff2150ce7d7c415a8af1fbff3dc3e6c +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/AvatarInputs.cs b/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/AvatarInputs.cs index 4289c30dd..c04540d5d 100644 --- a/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/AvatarInputs.cs +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/AvatarInputs.cs @@ -1,7 +1,9 @@ +using System.Runtime.CompilerServices; using UnityEngine; using UnityEngine.InputSystem; -namespace com.unity.multiplayer.samples.distributed_authority.input +[assembly: InternalsVisibleTo("com.unity.multiplayer.samples.socialhub.player")] +namespace com.unity.multiplayer.samples.socialhub.input { class AvatarInputs : MonoBehaviour { diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/com.unity.multiplayer.samples.socialhub.input.asmdef b/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/com.unity.multiplayer.samples.socialhub.input.asmdef new file mode 100644 index 000000000..c509405bd --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/com.unity.multiplayer.samples.socialhub.input.asmdef @@ -0,0 +1,16 @@ +{ + "name": "com.unity.multiplayer.samples.socialhub.input", + "rootNamespace": "com.unity.multiplayer.samples.socialhub", + "references": [ + "GUID:75469ad4d38634e559750d17036d5f7c" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/com.unity.multiplayer.samples.socialhub.input.asmdef.meta b/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/com.unity.multiplayer.samples.socialhub.input.asmdef.meta new file mode 100644 index 000000000..55aae09c1 --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/com.unity.multiplayer.samples.socialhub.input.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: c15e7f658578345fcb824b0a64d4dbe8 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/AvatarTransform.cs b/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/AvatarTransform.cs index b8ea334aa..4f81bc88e 100644 --- a/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/AvatarTransform.cs +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/AvatarTransform.cs @@ -1,9 +1,8 @@ using Unity.Netcode.Components; using UnityEngine; -using UnityEngine.InputSystem; -using com.unity.multiplayer.samples.distributed_authority.input; +using com.unity.multiplayer.samples.socialhub.input; -namespace com.unity.multiplayer.samples.distributed_authority.gameplay +namespace com.unity.multiplayer.samples.socialhub.player { [RequireComponent(typeof(Rigidbody))] public class AvatarTransform : NetworkTransform @@ -11,7 +10,7 @@ public class AvatarTransform : NetworkTransform [SerializeField] Rigidbody m_Rigidbody; [SerializeField] - PlayerInput m_PlayerInput; + MonoBehaviour m_PlayerInput; [SerializeField] AvatarInputs m_AvatarInputs; [SerializeField] diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/com.unity.multiplayer.samples.socialhub.player.asmdef b/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/com.unity.multiplayer.samples.socialhub.player.asmdef new file mode 100644 index 000000000..8a059e8ad --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/com.unity.multiplayer.samples.socialhub.player.asmdef @@ -0,0 +1,18 @@ +{ + "name": "com.unity.multiplayer.samples.socialhub.player", + "rootNamespace": "com.unity.multiplayer.samples.socialhub", + "references": [ + "GUID:1491147abca9d7d4bb7105af628b223e", + "GUID:c15e7f658578345fcb824b0a64d4dbe8", + "GUID:9ff2150ce7d7c415a8af1fbff3dc3e6c" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/com.unity.multiplayer.samples.socialhub.player.asmdef.meta b/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/com.unity.multiplayer.samples.socialhub.player.asmdef.meta new file mode 100644 index 000000000..88021ce08 --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/com.unity.multiplayer.samples.socialhub.player.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 8314b31eee3cc495ca4a4f078575802d +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From ad2404d5426b5edf4e2613da2f656cb20e51b916 Mon Sep 17 00:00:00 2001 From: Fernando Cortez Date: Wed, 14 Aug 2024 13:11:29 -0400 Subject: [PATCH 2/6] one unnecessary dependency removed --- .../com.unity.multiplayer.samples.socialhub.gameplay.asmdef | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/com.unity.multiplayer.samples.socialhub.gameplay.asmdef b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/com.unity.multiplayer.samples.socialhub.gameplay.asmdef index dd6ff4baa..e838cdd64 100644 --- a/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/com.unity.multiplayer.samples.socialhub.gameplay.asmdef +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/com.unity.multiplayer.samples.socialhub.gameplay.asmdef @@ -2,8 +2,7 @@ "name": "com.unity.multiplayer.samples.socialhub.gameplay", "rootNamespace": "com.unity.multiplayer.samples.socialhub", "references": [ - "GUID:1491147abca9d7d4bb7105af628b223e", - "GUID:c15e7f658578345fcb824b0a64d4dbe8" + "GUID:1491147abca9d7d4bb7105af628b223e" ], "includePlatforms": [], "excludePlatforms": [], From c7787f28725943ae7c4006ec9d778272858fe1a9 Mon Sep 17 00:00:00 2001 From: Fernando Cortez Date: Wed, 14 Aug 2024 13:52:49 -0400 Subject: [PATCH 3/6] renaming asmdefs & adding input assemblyinfo --- .../Assets/Scripts/Editor/AvatarTransformEditor.cs | 6 +++--- ...ef => Unity.Multiplayer.Samples.SocialHub.Editor.asmdef} | 4 ++-- ... Unity.Multiplayer.Samples.SocialHub.Editor.asmdef.meta} | 0 ... => Unity.Multiplayer.Samples.SocialHub.Gameplay.asmdef} | 4 ++-- ...nity.Multiplayer.Samples.SocialHub.Gameplay.asmdef.meta} | 0 .../Assets/Scripts/Input/AssemblyInfo.cs | 2 ++ .../Assets/Scripts/Input/AssemblyInfo.cs.meta | 2 ++ .../Assets/Scripts/Input/AvatarInputs.cs | 3 +-- ...def => Unity.Multiplayer.Samples.SocialHub.Input.asmdef} | 4 ++-- ...> Unity.Multiplayer.Samples.SocialHub.Input.asmdef.meta} | 0 .../Assets/Scripts/Player/AvatarTransform.cs | 4 ++-- ...ef => Unity.Multiplayer.Samples.SocialHub.Player.asmdef} | 4 ++-- ... Unity.Multiplayer.Samples.SocialHub.Player.asmdef.meta} | 0 13 files changed, 18 insertions(+), 15 deletions(-) rename Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/{com.unity.multiplayer.samples.socialhub.editor.asmdef => Unity.Multiplayer.Samples.SocialHub.Editor.asmdef} (73%) rename Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/{com.unity.multiplayer.samples.socialhub.editor.asmdef.meta => Unity.Multiplayer.Samples.SocialHub.Editor.asmdef.meta} (100%) rename Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/{com.unity.multiplayer.samples.socialhub.gameplay.asmdef => Unity.Multiplayer.Samples.SocialHub.Gameplay.asmdef} (72%) rename Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/{com.unity.multiplayer.samples.socialhub.gameplay.asmdef.meta => Unity.Multiplayer.Samples.SocialHub.Gameplay.asmdef.meta} (100%) create mode 100644 Experimental/DistributedAuthoritySample/Assets/Scripts/Input/AssemblyInfo.cs create mode 100644 Experimental/DistributedAuthoritySample/Assets/Scripts/Input/AssemblyInfo.cs.meta rename Experimental/DistributedAuthoritySample/Assets/Scripts/Input/{com.unity.multiplayer.samples.socialhub.input.asmdef => Unity.Multiplayer.Samples.SocialHub.Input.asmdef} (73%) rename Experimental/DistributedAuthoritySample/Assets/Scripts/Input/{com.unity.multiplayer.samples.socialhub.input.asmdef.meta => Unity.Multiplayer.Samples.SocialHub.Input.asmdef.meta} (100%) rename Experimental/DistributedAuthoritySample/Assets/Scripts/Player/{com.unity.multiplayer.samples.socialhub.player.asmdef => Unity.Multiplayer.Samples.SocialHub.Player.asmdef} (77%) rename Experimental/DistributedAuthoritySample/Assets/Scripts/Player/{com.unity.multiplayer.samples.socialhub.player.asmdef.meta => Unity.Multiplayer.Samples.SocialHub.Player.asmdef.meta} (100%) diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/AvatarTransformEditor.cs b/Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/AvatarTransformEditor.cs index ab772c38b..578f9d4ad 100644 --- a/Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/AvatarTransformEditor.cs +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/AvatarTransformEditor.cs @@ -1,13 +1,13 @@ -using com.unity.multiplayer.samples.socialhub.player; +using Unity.Multiplayer.Samples.SocialHub.Player; using UnityEditor; using UnityEditor.UIElements; using UnityEngine; using UnityEngine.UIElements; -namespace com.unity.multiplayer.samples.socialhub.editor +namespace Unity.Multiplayer.Samples.SocialHub.Editor { [CustomEditor(typeof(AvatarTransform))] - class DerivedComponentEditor : Editor + class DerivedComponentEditor : UnityEditor.Editor { public override VisualElement CreateInspectorGUI() { diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/com.unity.multiplayer.samples.socialhub.editor.asmdef b/Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/Unity.Multiplayer.Samples.SocialHub.Editor.asmdef similarity index 73% rename from Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/com.unity.multiplayer.samples.socialhub.editor.asmdef rename to Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/Unity.Multiplayer.Samples.SocialHub.Editor.asmdef index 27f97af4c..763c559da 100644 --- a/Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/com.unity.multiplayer.samples.socialhub.editor.asmdef +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/Unity.Multiplayer.Samples.SocialHub.Editor.asmdef @@ -1,6 +1,6 @@ { - "name": "com.unity.multiplayer.samples.socialhub.editor", - "rootNamespace": "com.unity.multiplayer.samples.socialhub", + "name": "Unity.Multiplayer.Samples.SocialHub.Editor", + "rootNamespace": "Unity.Multiplayer.Samples.SocialHub", "references": [ "GUID:8314b31eee3cc495ca4a4f078575802d" ], diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/com.unity.multiplayer.samples.socialhub.editor.asmdef.meta b/Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/Unity.Multiplayer.Samples.SocialHub.Editor.asmdef.meta similarity index 100% rename from Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/com.unity.multiplayer.samples.socialhub.editor.asmdef.meta rename to Experimental/DistributedAuthoritySample/Assets/Scripts/Editor/Unity.Multiplayer.Samples.SocialHub.Editor.asmdef.meta diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/com.unity.multiplayer.samples.socialhub.gameplay.asmdef b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/Unity.Multiplayer.Samples.SocialHub.Gameplay.asmdef similarity index 72% rename from Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/com.unity.multiplayer.samples.socialhub.gameplay.asmdef rename to Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/Unity.Multiplayer.Samples.SocialHub.Gameplay.asmdef index e838cdd64..a09e1b725 100644 --- a/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/com.unity.multiplayer.samples.socialhub.gameplay.asmdef +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/Unity.Multiplayer.Samples.SocialHub.Gameplay.asmdef @@ -1,6 +1,6 @@ { - "name": "com.unity.multiplayer.samples.socialhub.gameplay", - "rootNamespace": "com.unity.multiplayer.samples.socialhub", + "name": "Unity.Multiplayer.Samples.SocialHub.Gameplay", + "rootNamespace": "Unity.Multiplayer.Samples.SocialHub", "references": [ "GUID:1491147abca9d7d4bb7105af628b223e" ], diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/com.unity.multiplayer.samples.socialhub.gameplay.asmdef.meta b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/Unity.Multiplayer.Samples.SocialHub.Gameplay.asmdef.meta similarity index 100% rename from Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/com.unity.multiplayer.samples.socialhub.gameplay.asmdef.meta rename to Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/Unity.Multiplayer.Samples.SocialHub.Gameplay.asmdef.meta diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/AssemblyInfo.cs b/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/AssemblyInfo.cs new file mode 100644 index 000000000..9b00a0c99 --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/AssemblyInfo.cs @@ -0,0 +1,2 @@ +using System.Runtime.CompilerServices; +[assembly: InternalsVisibleTo("Unity.Multiplayer.Samples.SocialHub.Player")] diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/AssemblyInfo.cs.meta b/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/AssemblyInfo.cs.meta new file mode 100644 index 000000000..dc8750969 --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/AssemblyInfo.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 7c74f4c681bf048b5bb6df8e0126a2de \ No newline at end of file diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/AvatarInputs.cs b/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/AvatarInputs.cs index c04540d5d..523078d25 100644 --- a/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/AvatarInputs.cs +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/AvatarInputs.cs @@ -2,8 +2,7 @@ using UnityEngine; using UnityEngine.InputSystem; -[assembly: InternalsVisibleTo("com.unity.multiplayer.samples.socialhub.player")] -namespace com.unity.multiplayer.samples.socialhub.input +namespace Unity.Multiplayer.Samples.SocialHub.Input { class AvatarInputs : MonoBehaviour { diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/com.unity.multiplayer.samples.socialhub.input.asmdef b/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/Unity.Multiplayer.Samples.SocialHub.Input.asmdef similarity index 73% rename from Experimental/DistributedAuthoritySample/Assets/Scripts/Input/com.unity.multiplayer.samples.socialhub.input.asmdef rename to Experimental/DistributedAuthoritySample/Assets/Scripts/Input/Unity.Multiplayer.Samples.SocialHub.Input.asmdef index c509405bd..47acd6f34 100644 --- a/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/com.unity.multiplayer.samples.socialhub.input.asmdef +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/Unity.Multiplayer.Samples.SocialHub.Input.asmdef @@ -1,6 +1,6 @@ { - "name": "com.unity.multiplayer.samples.socialhub.input", - "rootNamespace": "com.unity.multiplayer.samples.socialhub", + "name": "Unity.Multiplayer.Samples.SocialHub.Input", + "rootNamespace": "Unity.Multiplayer.Samples.SocialHub", "references": [ "GUID:75469ad4d38634e559750d17036d5f7c" ], diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/com.unity.multiplayer.samples.socialhub.input.asmdef.meta b/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/Unity.Multiplayer.Samples.SocialHub.Input.asmdef.meta similarity index 100% rename from Experimental/DistributedAuthoritySample/Assets/Scripts/Input/com.unity.multiplayer.samples.socialhub.input.asmdef.meta rename to Experimental/DistributedAuthoritySample/Assets/Scripts/Input/Unity.Multiplayer.Samples.SocialHub.Input.asmdef.meta diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/AvatarTransform.cs b/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/AvatarTransform.cs index 4f81bc88e..90b14338c 100644 --- a/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/AvatarTransform.cs +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/AvatarTransform.cs @@ -1,8 +1,8 @@ using Unity.Netcode.Components; using UnityEngine; -using com.unity.multiplayer.samples.socialhub.input; +using Unity.Multiplayer.Samples.SocialHub.Input; -namespace com.unity.multiplayer.samples.socialhub.player +namespace Unity.Multiplayer.Samples.SocialHub.Player { [RequireComponent(typeof(Rigidbody))] public class AvatarTransform : NetworkTransform diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/com.unity.multiplayer.samples.socialhub.player.asmdef b/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/Unity.Multiplayer.Samples.SocialHub.Player.asmdef similarity index 77% rename from Experimental/DistributedAuthoritySample/Assets/Scripts/Player/com.unity.multiplayer.samples.socialhub.player.asmdef rename to Experimental/DistributedAuthoritySample/Assets/Scripts/Player/Unity.Multiplayer.Samples.SocialHub.Player.asmdef index 8a059e8ad..5a39c55fa 100644 --- a/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/com.unity.multiplayer.samples.socialhub.player.asmdef +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/Unity.Multiplayer.Samples.SocialHub.Player.asmdef @@ -1,6 +1,6 @@ { - "name": "com.unity.multiplayer.samples.socialhub.player", - "rootNamespace": "com.unity.multiplayer.samples.socialhub", + "name": "Unity.Multiplayer.Samples.SocialHub.Player", + "rootNamespace": "Unity.Multiplayer.Samples.SocialHub", "references": [ "GUID:1491147abca9d7d4bb7105af628b223e", "GUID:c15e7f658578345fcb824b0a64d4dbe8", diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/com.unity.multiplayer.samples.socialhub.player.asmdef.meta b/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/Unity.Multiplayer.Samples.SocialHub.Player.asmdef.meta similarity index 100% rename from Experimental/DistributedAuthoritySample/Assets/Scripts/Player/com.unity.multiplayer.samples.socialhub.player.asmdef.meta rename to Experimental/DistributedAuthoritySample/Assets/Scripts/Player/Unity.Multiplayer.Samples.SocialHub.Player.asmdef.meta From 609c59dfd9b506ac393307e77ced5786e39a69ab Mon Sep 17 00:00:00 2001 From: Fernando Cortez Date: Thu, 15 Aug 2024 13:29:10 -0400 Subject: [PATCH 4/6] avatar-side pickup/toss of pickupable object --- .../Assets/Prefabs/Avatar.prefab | 92 ++++++- .../Assets/Scripts/Gameplay/AssemblyInfo.cs | 2 + .../Scripts/Gameplay/AssemblyInfo.cs.meta | 2 + .../Assets/Scripts/Gameplay/GameplayEvent.cs | 10 + .../Scripts/Gameplay/GameplayEvent.cs.meta | 2 + .../Gameplay/IGameplayEventInvokable.cs | 10 + .../Gameplay/IGameplayEventInvokable.cs.meta | 2 + .../Scripts/Gameplay/IOwnershipRequestable.cs | 11 + .../Gameplay/IOwnershipRequestable.cs.meta | 2 + .../Assets/Scripts/Input/AvatarInputs.cs | 60 ++++- .../Scripts/Player/AvatarInteractions.cs | 228 ++++++++++++++++++ .../Scripts/Player/AvatarInteractions.cs.meta | 2 + .../ProjectSettings/TagManager.asset | 2 +- 13 files changed, 414 insertions(+), 11 deletions(-) create mode 100644 Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/AssemblyInfo.cs create mode 100644 Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/AssemblyInfo.cs.meta create mode 100644 Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/GameplayEvent.cs create mode 100644 Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/GameplayEvent.cs.meta create mode 100644 Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/IGameplayEventInvokable.cs create mode 100644 Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/IGameplayEventInvokable.cs.meta create mode 100644 Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/IOwnershipRequestable.cs create mode 100644 Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/IOwnershipRequestable.cs.meta create mode 100644 Experimental/DistributedAuthoritySample/Assets/Scripts/Player/AvatarInteractions.cs create mode 100644 Experimental/DistributedAuthoritySample/Assets/Scripts/Player/AvatarInteractions.cs.meta diff --git a/Experimental/DistributedAuthoritySample/Assets/Prefabs/Avatar.prefab b/Experimental/DistributedAuthoritySample/Assets/Prefabs/Avatar.prefab index 5bac5aa18..46e760340 100644 --- a/Experimental/DistributedAuthoritySample/Assets/Prefabs/Avatar.prefab +++ b/Experimental/DistributedAuthoritySample/Assets/Prefabs/Avatar.prefab @@ -1,5 +1,58 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: +--- !u!1 &2790727344451942854 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 5714572371256472543} + - component: {fileID: 1819693744524683591} + m_Layer: 0 + m_Name: InteractCollider + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &5714572371256472543 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2790727344451942854} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 1.1} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 378099091213283077} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!65 &1819693744524683591 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2790727344451942854} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 1 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} --- !u!1 &2971605785670457434 GameObject: m_ObjectHideFlags: 0 @@ -212,6 +265,7 @@ GameObject: - component: {fileID: -8100831418301897270} - component: {fileID: 4903152183366241606} - component: {fileID: 8197190117666738524} + - component: {fileID: 6126152928325105854} m_Layer: 0 m_Name: Avatar m_TagString: Untagged @@ -233,6 +287,7 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: - {fileID: 527982249900556139} + - {fileID: 5714572371256472543} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &2864305741433477372 @@ -290,7 +345,6 @@ MonoBehaviour: InLocalSpace: 0 Interpolate: 1 SlerpPosition: 0 - PropertiesVisible: 1 m_Rigidbody: {fileID: 4745766379562620470} m_PlayerInput: {fileID: 4903152183366241606} m_AvatarInputs: {fileID: 8197190117666738524} @@ -382,15 +436,35 @@ MonoBehaviour: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5478015027486214707} - m_Enabled: 1 + m_Enabled: 0 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 7e9f71718dd134b14b300e378e98c718, type: 3} m_Name: m_EditorClassIdentifier: - move: {x: 0, y: 0} - look: {x: 0, y: 0} - jump: 0 - sprint: 0 - analogMovement: 0 - cursorLocked: 1 - cursorInputForLook: 1 + m_InteractActionReference: {fileID: 1781555164194001046, guid: dcd1b4eb76b964f40afe6c0a3ca65c82, type: 3} + Move: {x: 0, y: 0} + Look: {x: 0, y: 0} + Jump: 0 + Sprint: 0 + AnalogMovement: 0 + CursorLocked: 1 + CursorInputForLook: 1 +--- !u!114 &6126152928325105854 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5478015027486214707} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: b47efef44cef74d9ca00f4913607f988, type: 3} + m_Name: + m_EditorClassIdentifier: + m_MainCollider: {fileID: 817796967242824188} + m_AvatarInputs: {fileID: 8197190117666738524} + m_NetworkRigidbody: {fileID: -8100831418301897270} + m_HoldTransform: {fileID: 378099091213283077} + m_InteractCollider: {fileID: 1819693744524683591} + m_MinTossForce: 5 + m_MaxTossForce: 10 diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/AssemblyInfo.cs b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/AssemblyInfo.cs new file mode 100644 index 000000000..9b00a0c99 --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/AssemblyInfo.cs @@ -0,0 +1,2 @@ +using System.Runtime.CompilerServices; +[assembly: InternalsVisibleTo("Unity.Multiplayer.Samples.SocialHub.Player")] diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/AssemblyInfo.cs.meta b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/AssemblyInfo.cs.meta new file mode 100644 index 000000000..b48cd6cd4 --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/AssemblyInfo.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 3465502a3a2c6448b96874d02edbb908 diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/GameplayEvent.cs b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/GameplayEvent.cs new file mode 100644 index 000000000..b2e3aff99 --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/GameplayEvent.cs @@ -0,0 +1,10 @@ +using UnityEngine; + +namespace Unity.Multiplayer.Samples.SocialHub.Gameplay +{ + enum GameplayEvent + { + Despawned, + OwnershipChange + } +} diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/GameplayEvent.cs.meta b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/GameplayEvent.cs.meta new file mode 100644 index 000000000..685a4d486 --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/GameplayEvent.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 507a19fc89d974f28adddfe762c13eb7 \ No newline at end of file diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/IGameplayEventInvokable.cs b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/IGameplayEventInvokable.cs new file mode 100644 index 000000000..94f0cc79c --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/IGameplayEventInvokable.cs @@ -0,0 +1,10 @@ +using Unity.Netcode; +using UnityEngine; + +namespace Unity.Multiplayer.Samples.SocialHub.Gameplay +{ + interface IGameplayEventInvokable + { + event System.Action OnGameplayEvent; + } +} diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/IGameplayEventInvokable.cs.meta b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/IGameplayEventInvokable.cs.meta new file mode 100644 index 000000000..f3be27c52 --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/IGameplayEventInvokable.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 0969e36952ce846e895b036088dd6afa diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/IOwnershipRequestable.cs b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/IOwnershipRequestable.cs new file mode 100644 index 000000000..e61f52504 --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/IOwnershipRequestable.cs @@ -0,0 +1,11 @@ +using System; +using Unity.Netcode; +using UnityEngine; + +namespace Unity.Multiplayer.Samples.SocialHub.Gameplay +{ + interface IOwnershipRequestable + { + event Action OnNetworkObjectOwnershipRequestResponse; + } +} diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/IOwnershipRequestable.cs.meta b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/IOwnershipRequestable.cs.meta new file mode 100644 index 000000000..df8630127 --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/IOwnershipRequestable.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 071ac956e173f479691c6233c0f4fb2e \ No newline at end of file diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/AvatarInputs.cs b/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/AvatarInputs.cs index 523078d25..c4abc9618 100644 --- a/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/AvatarInputs.cs +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Input/AvatarInputs.cs @@ -1,11 +1,15 @@ -using System.Runtime.CompilerServices; +using System; using UnityEngine; using UnityEngine.InputSystem; +using UnityEngine.InputSystem.Interactions; namespace Unity.Multiplayer.Samples.SocialHub.Input { class AvatarInputs : MonoBehaviour { + [SerializeField] + InputActionReference m_InteractActionReference; + [Header("Character Input Values")] [SerializeField] internal Vector2 Move; @@ -26,6 +30,60 @@ class AvatarInputs : MonoBehaviour [SerializeField] internal bool CursorInputForLook = true; + internal event Action InteractTapped; + internal event Action InteractHeld; + + // tracking when a Hold interaction has started/ended + bool m_HoldingInteractionPerformed; + + void Start() + { + if (m_InteractActionReference == null) + { + Debug.LogWarning("Assign Interact InputActionReference to this MonoBehaviour!", this); + return; + } + + m_InteractActionReference.action.performed += OnInteractPerformed; + m_InteractActionReference.action.canceled += OnInteractCanceled; + m_InteractActionReference.action.Enable(); + } + + void OnDestroy() + { + if (m_InteractActionReference != null) + { + m_InteractActionReference.action.performed -= OnInteractPerformed; + m_InteractActionReference.action.canceled -= OnInteractCanceled; + m_InteractActionReference.action.Disable(); + } + } + + void OnInteractPerformed(InputAction.CallbackContext context) + { + switch (context.interaction) + { + case HoldInteraction: + m_HoldingInteractionPerformed = true; + break; + case TapInteraction: + InteractTapped?.Invoke(); + break; + } + } + + void OnInteractCanceled(InputAction.CallbackContext context) + { + if (context.interaction is HoldInteraction) + { + if (m_HoldingInteractionPerformed) + { + InteractHeld?.Invoke(context.duration); + } + m_HoldingInteractionPerformed = false; + } + } + #if ENABLE_INPUT_SYSTEM void OnMove(InputValue value) { diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/AvatarInteractions.cs b/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/AvatarInteractions.cs new file mode 100644 index 000000000..e511bc6ca --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/AvatarInteractions.cs @@ -0,0 +1,228 @@ +using System; +using Unity.Multiplayer.Samples.SocialHub.Gameplay; +using Unity.Multiplayer.Samples.SocialHub.Input; +using Unity.Netcode; +using Unity.Netcode.Components; +using UnityEngine; + +namespace Unity.Multiplayer.Samples.SocialHub.Player +{ + [RequireComponent(typeof(AvatarInputs))] + class AvatarInteractions : NetworkBehaviour + { + [SerializeField] + Collider m_MainCollider; + + [SerializeField] + AvatarInputs m_AvatarInputs; + + [SerializeField] + NetworkRigidbody m_NetworkRigidbody; + + [SerializeField] + Transform m_HoldTransform; + + [SerializeField] + Collider m_InteractCollider; + + [SerializeField] + float m_MinTossForce; + + [SerializeField] + float m_MaxTossForce; + + Collider[] m_Results = new Collider[1]; + + LayerMask m_PickupableLayerMask; + + NetworkRigidbody m_HoldingRigidbody; + + const float k_MinDurationHeld = 0f; + const float k_MaxDurationHeld = 2f; + + void Awake() + { + m_PickupableLayerMask = 1 << LayerMask.NameToLayer("Pickupable"); + } + + public override void OnNetworkSpawn() + { + if (!HasAuthority) + { + return; + } + + if (!m_AvatarInputs) + { + Debug.LogWarning("Assign AvatarInputs in the inspector!"); + return; + } + + m_AvatarInputs.InteractTapped += OnTapPerformed; + m_AvatarInputs.InteractHeld += OnHoldReleased; + } + + public override void OnNetworkDespawn() + { + if (m_AvatarInputs) + { + m_AvatarInputs.InteractTapped -= OnTapPerformed; + m_AvatarInputs.InteractHeld -= OnHoldReleased; + } + } + + void OnTapPerformed() + { + if (m_HoldingRigidbody != null) + { + ReleaseHeldObject(); + } + else + { + PickUp(); + } + } + + void OnHoldReleased(double holdDuration) + { + if (m_HoldingRigidbody != null) + { + Toss(holdDuration); + } + } + + void PickUp() + { + if (Physics.OverlapBoxNonAlloc(m_InteractCollider.transform.position, m_InteractCollider.bounds.extents, m_Results, Quaternion.identity, mask: m_PickupableLayerMask) > 0) + { + if (m_Results[0].TryGetComponent(out NetworkObject otherNetworkObject)) + { + // if NetworkObject is locked, nothing we can do but retry a pickup at another time + if (otherNetworkObject.IsOwnershipLocked) + { + return; + } + + // trivial case: other NetworkObject is owned by this client, we can attach to fixed joint + if (otherNetworkObject.HasAuthority) + { + AttachToFixedJoint(otherNetworkObject); + return; + } + + if (otherNetworkObject.IsOwnershipTransferable) + { + // can use change ownership directly + otherNetworkObject.ChangeOwnership(OwnerClientId); + + // we can attach it via FixedPoint now as we are now owning this NetworkObject + AttachToFixedJoint(otherNetworkObject); + } + else if (otherNetworkObject.IsOwnershipRequestRequired) + { + // if not transferable, we must request access to become owner + if (m_Results[0].TryGetComponent(out IOwnershipRequestable otherRequestable)) + { + var ownershipRequestStatus = otherNetworkObject.RequestOwnership(); + if (ownershipRequestStatus == NetworkObject.OwnershipRequestStatus.RequestSent) + { + otherRequestable.OnNetworkObjectOwnershipRequestResponse += OnOwnershipRequestResponse; + } + } + } + } + } + } + + void OnOwnershipRequestResponse(NetworkObject other, NetworkObject.OwnershipRequestResponseStatus status) + { + // unsubscribe + var ownershipRequestable = other.GetComponent(); + ownershipRequestable.OnNetworkObjectOwnershipRequestResponse -= OnOwnershipRequestResponse; + + if (status != NetworkObject.OwnershipRequestResponseStatus.Approved) + { + return; + } + + AttachToFixedJoint(other); + } + + void AttachToFixedJoint(NetworkObject other) + { + if (!other.TryGetComponent(out NetworkRigidbody otherNetworkRigidbody)) + { + return; + } + + var success = otherNetworkRigidbody.AttachToFixedJoint(m_NetworkRigidbody, m_HoldTransform.position, massScale: 0.00001f); + if (success) + { + m_HoldingRigidbody = otherNetworkRigidbody; + + // set ownership status to request required, now that this object is being held + m_HoldingRigidbody.NetworkObject.SetOwnershipStatus(NetworkObject.OwnershipStatus.RequestRequired, clearAndSet: true); + + var gameplayEventInvokable = other.GetComponent(); + gameplayEventInvokable.OnGameplayEvent += OnGameplayEvent; + + // prevent collisions from this collider to the picked up object and vice-versa + Physics.IgnoreCollision(m_MainCollider, other.GetComponent(), true); + } + } + + void OnGameplayEvent(NetworkObject networkObject, GameplayEvent gameplayEvent) + { + switch (gameplayEvent) + { + case GameplayEvent.Despawned: + case GameplayEvent.OwnershipChange: + + // unsubscribe + var gameplayEventInvokable = networkObject.GetComponent(); + gameplayEventInvokable.OnGameplayEvent -= OnGameplayEvent; + + // revert collision + if (networkObject.TryGetComponent(out Collider otherCollider)) + { + Physics.IgnoreCollision(m_MainCollider, otherCollider, false); + } + + // don't have ownership of the item, thus we can't invoke DetachFromFixedJoint(), but we need to remove created FixedJoint component + if (networkObject.TryGetComponent(out FixedJoint fixedJoint)) + { + Destroy(fixedJoint); + } + + m_HoldingRigidbody = null; + + break; + default: + throw new Exception($"Unknown GameplayEvent {gameplayEvent}!"); + } + } + + void ReleaseHeldObject() + { + // set ownership status to request required, now that this object is being held + m_HoldingRigidbody.NetworkObject.SetOwnershipStatus(NetworkObject.OwnershipStatus.Distributable, clearAndSet: true); + m_HoldingRigidbody.NetworkObject.SetOwnershipStatus(NetworkObject.OwnershipStatus.Transferable); + + m_HoldingRigidbody.DetachFromFixedJoint(); + m_HoldingRigidbody.GetComponent().useGravity = true; + Physics.IgnoreCollision(m_MainCollider, m_HoldingRigidbody.GetComponent(), false); + m_HoldingRigidbody = null; + } + + void Toss(double holdDuration) + { + var heldRigidbody = m_HoldingRigidbody.GetComponent(); + ReleaseHeldObject(); + + // apply a force to the released object + float timeHeldClamped = Mathf.Clamp((float)holdDuration, k_MinDurationHeld, k_MaxDurationHeld); + float tossForce = Mathf.Lerp(m_MinTossForce, m_MaxTossForce, Mathf.Clamp(timeHeldClamped, 0f, 1f)); + heldRigidbody.AddForce(transform.forward * tossForce, ForceMode.Impulse); + } + } +} diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/AvatarInteractions.cs.meta b/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/AvatarInteractions.cs.meta new file mode 100644 index 000000000..2981f7212 --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/AvatarInteractions.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: b47efef44cef74d9ca00f4913607f988 \ No newline at end of file diff --git a/Experimental/DistributedAuthoritySample/ProjectSettings/TagManager.asset b/Experimental/DistributedAuthoritySample/ProjectSettings/TagManager.asset index 148ab95f6..8899010ff 100644 --- a/Experimental/DistributedAuthoritySample/ProjectSettings/TagManager.asset +++ b/Experimental/DistributedAuthoritySample/ProjectSettings/TagManager.asset @@ -12,8 +12,8 @@ TagManager: - - Water - UI - - '[Empty Slot]' - Ground + - Pickupable - - - From d7e70f81d75dac1c85e2cac91090f3cce5e0d4e9 Mon Sep 17 00:00:00 2001 From: Fernando Cortez Date: Thu, 15 Aug 2024 14:37:48 -0400 Subject: [PATCH 5/6] adding a pickupable object, EnvironmentTransform, to scene with a spawner --- .../InputSystem/AvatarActions.inputactions | 4 +- .../Assets/NetworkPrefabs.asset | 7 +- .../Assets/Prefabs/Avatar.prefab | 2 +- .../DistributableTransferableObject.prefab | 211 +++++++++ ...istributableTransferableObject.prefab.meta | 7 + .../SessionOwnerNetworkObjectSpawner.prefab | 71 +++ ...ssionOwnerNetworkObjectSpawner.prefab.meta | 7 + .../Assets/Scenes/HubScene.unity | 420 ++++++++++++++++++ .../Scripts/Gameplay/EnvironmentTransform.cs | 54 +++ .../Gameplay/EnvironmentTransform.cs.meta | 2 + .../SessionOwnerNetworkObjectSpawner.cs | 27 ++ .../SessionOwnerNetworkObjectSpawner.cs.meta | 2 + .../Assets/Scripts/Player/AvatarTransform.cs | 1 + 13 files changed, 811 insertions(+), 4 deletions(-) create mode 100644 Experimental/DistributedAuthoritySample/Assets/Prefabs/DistributableTransferableObject.prefab create mode 100644 Experimental/DistributedAuthoritySample/Assets/Prefabs/DistributableTransferableObject.prefab.meta create mode 100644 Experimental/DistributedAuthoritySample/Assets/Prefabs/SessionOwnerNetworkObjectSpawner.prefab create mode 100644 Experimental/DistributedAuthoritySample/Assets/Prefabs/SessionOwnerNetworkObjectSpawner.prefab.meta create mode 100644 Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/EnvironmentTransform.cs create mode 100644 Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/EnvironmentTransform.cs.meta create mode 100644 Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/SessionOwnerNetworkObjectSpawner.cs create mode 100644 Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/SessionOwnerNetworkObjectSpawner.cs.meta diff --git a/Experimental/DistributedAuthoritySample/Assets/InputSystem/AvatarActions.inputactions b/Experimental/DistributedAuthoritySample/Assets/InputSystem/AvatarActions.inputactions index 05274d353..513fc5005 100644 --- a/Experimental/DistributedAuthoritySample/Assets/InputSystem/AvatarActions.inputactions +++ b/Experimental/DistributedAuthoritySample/Assets/InputSystem/AvatarActions.inputactions @@ -36,9 +36,9 @@ "name": "Interact", "type": "Button", "id": "852140f2-7766-474d-8707-702459ba45f3", - "expectedControlType": "Button", + "expectedControlType": "", "processors": "", - "interactions": "Hold", + "interactions": "Hold,Tap", "initialStateCheck": false }, { diff --git a/Experimental/DistributedAuthoritySample/Assets/NetworkPrefabs.asset b/Experimental/DistributedAuthoritySample/Assets/NetworkPrefabs.asset index 63e14cc1b..ceae78d4c 100644 --- a/Experimental/DistributedAuthoritySample/Assets/NetworkPrefabs.asset +++ b/Experimental/DistributedAuthoritySample/Assets/NetworkPrefabs.asset @@ -13,4 +13,9 @@ MonoBehaviour: m_Name: NetworkPrefabs m_EditorClassIdentifier: IsDefault: 1 - List: [] + List: + - Override: 0 + Prefab: {fileID: 893974733110552042, guid: 1c6ec0a7b92244c349d83ba9b4a1c8ab, type: 3} + SourcePrefabToOverride: {fileID: 0} + SourceHashToOverride: 0 + OverridingTargetPrefab: {fileID: 0} diff --git a/Experimental/DistributedAuthoritySample/Assets/Prefabs/Avatar.prefab b/Experimental/DistributedAuthoritySample/Assets/Prefabs/Avatar.prefab index 46e760340..d4a198d0e 100644 --- a/Experimental/DistributedAuthoritySample/Assets/Prefabs/Avatar.prefab +++ b/Experimental/DistributedAuthoritySample/Assets/Prefabs/Avatar.prefab @@ -464,7 +464,7 @@ MonoBehaviour: m_MainCollider: {fileID: 817796967242824188} m_AvatarInputs: {fileID: 8197190117666738524} m_NetworkRigidbody: {fileID: -8100831418301897270} - m_HoldTransform: {fileID: 378099091213283077} + m_HoldTransform: {fileID: 5714572371256472543} m_InteractCollider: {fileID: 1819693744524683591} m_MinTossForce: 5 m_MaxTossForce: 10 diff --git a/Experimental/DistributedAuthoritySample/Assets/Prefabs/DistributableTransferableObject.prefab b/Experimental/DistributedAuthoritySample/Assets/Prefabs/DistributableTransferableObject.prefab new file mode 100644 index 000000000..0872489ec --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Prefabs/DistributableTransferableObject.prefab @@ -0,0 +1,211 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &893974733110552042 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2736246462863405418} + - component: {fileID: 7532867373889483769} + - component: {fileID: 6167276273388148193} + - component: {fileID: 7690746213975220858} + - component: {fileID: 5499784127695994160} + - component: {fileID: -7368379283164171724} + - component: {fileID: 6039897070700006726} + - component: {fileID: 6689110374311511483} + m_Layer: 7 + m_Name: DistributableTransferableObject + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2736246462863405418 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 893974733110552042} + serializedVersion: 2 + 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_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!33 &7532867373889483769 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 893974733110552042} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!23 &6167276273388148193 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 893974733110552042} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RayTracingAccelStructBuildFlagsOverride: 0 + m_RayTracingAccelStructBuildFlags: 1 + m_SmallMeshCulling: 1 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_AdditionalVertexStreams: {fileID: 0} +--- !u!65 &7690746213975220858 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 893974733110552042} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 0 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!114 &5499784127695994160 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 893974733110552042} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3} + m_Name: + m_EditorClassIdentifier: + GlobalObjectIdHash: 2069120471 + InScenePlacedSourceGlobalObjectIdHash: 0 + DeferredDespawnTick: 0 + Ownership: 3 + AlwaysReplicateAsRoot: 0 + SynchronizeTransform: 1 + ActiveSceneSynchronization: 0 + SceneMigrationSynchronization: 1 + SpawnWithObservers: 1 + DontDestroyWithOwner: 1 + AutoObjectParentSync: 1 +--- !u!54 &-7368379283164171724 +Rigidbody: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 893974733110552042} + serializedVersion: 4 + m_Mass: 1 + m_Drag: 0 + m_AngularDrag: 0.05 + m_CenterOfMass: {x: 0, y: 0, z: 0} + m_InertiaTensor: {x: 1, y: 1, z: 1} + m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ImplicitCom: 1 + m_ImplicitTensor: 1 + m_UseGravity: 1 + m_IsKinematic: 0 + m_Interpolate: 0 + m_Constraints: 0 + m_CollisionDetection: 0 +--- !u!114 &6039897070700006726 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 893974733110552042} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 54937e94f00ab46c8ae43b81027f342c, type: 3} + m_Name: + m_EditorClassIdentifier: + AuthorityMode: 1 + UseUnreliableDeltas: 0 + SyncPositionX: 1 + SyncPositionY: 1 + SyncPositionZ: 1 + SyncRotAngleX: 1 + SyncRotAngleY: 1 + SyncRotAngleZ: 1 + SyncScaleX: 0 + SyncScaleY: 0 + SyncScaleZ: 0 + PositionThreshold: 0.001 + RotAngleThreshold: 0.01 + ScaleThreshold: 0.01 + UseQuaternionSynchronization: 0 + UseQuaternionCompression: 0 + UseHalfFloatPrecision: 0 + InLocalSpace: 0 + Interpolate: 1 + SlerpPosition: 0 +--- !u!114 &6689110374311511483 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 893974733110552042} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f6c0be61502bb534f922ebb746851216, type: 3} + m_Name: + m_EditorClassIdentifier: + UseRigidBodyForMotion: 1 + AutoUpdateKinematicState: 1 + AutoSetKinematicOnDespawn: 1 diff --git a/Experimental/DistributedAuthoritySample/Assets/Prefabs/DistributableTransferableObject.prefab.meta b/Experimental/DistributedAuthoritySample/Assets/Prefabs/DistributableTransferableObject.prefab.meta new file mode 100644 index 000000000..747c7c3d7 --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Prefabs/DistributableTransferableObject.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 1c6ec0a7b92244c349d83ba9b4a1c8ab +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Experimental/DistributedAuthoritySample/Assets/Prefabs/SessionOwnerNetworkObjectSpawner.prefab b/Experimental/DistributedAuthoritySample/Assets/Prefabs/SessionOwnerNetworkObjectSpawner.prefab new file mode 100644 index 000000000..2fd5ad46b --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Prefabs/SessionOwnerNetworkObjectSpawner.prefab @@ -0,0 +1,71 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &4843296344903462454 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1258953842080244886} + - component: {fileID: 1499607153087855347} + - component: {fileID: 8817259292813230997} + m_Layer: 0 + m_Name: SessionOwnerNetworkObjectSpawner + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1258953842080244886 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4843296344903462454} + serializedVersion: 2 + 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_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1499607153087855347 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4843296344903462454} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3} + m_Name: + m_EditorClassIdentifier: + GlobalObjectIdHash: 433160265 + InScenePlacedSourceGlobalObjectIdHash: 0 + DeferredDespawnTick: 0 + Ownership: 0 + AlwaysReplicateAsRoot: 0 + SynchronizeTransform: 1 + ActiveSceneSynchronization: 0 + SceneMigrationSynchronization: 1 + SpawnWithObservers: 1 + DontDestroyWithOwner: 1 + AutoObjectParentSync: 1 +--- !u!114 &8817259292813230997 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4843296344903462454} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: eea4e07da167d4da7beddb67532a15f2, type: 3} + m_Name: + m_EditorClassIdentifier: + m_NetworkObjectToSpawn: {fileID: 0} diff --git a/Experimental/DistributedAuthoritySample/Assets/Prefabs/SessionOwnerNetworkObjectSpawner.prefab.meta b/Experimental/DistributedAuthoritySample/Assets/Prefabs/SessionOwnerNetworkObjectSpawner.prefab.meta new file mode 100644 index 000000000..75da0b74d --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Prefabs/SessionOwnerNetworkObjectSpawner.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: e54d55fa193a2495ea1270535da81837 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Experimental/DistributedAuthoritySample/Assets/Scenes/HubScene.unity b/Experimental/DistributedAuthoritySample/Assets/Scenes/HubScene.unity index 59c32d26d..a39ad0a8f 100644 --- a/Experimental/DistributedAuthoritySample/Assets/Scenes/HubScene.unity +++ b/Experimental/DistributedAuthoritySample/Assets/Scenes/HubScene.unity @@ -118,6 +118,144 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} +--- !u!1001 &43234386 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalPosition.y + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalPosition.z + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1499607153087855347, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: GlobalObjectIdHash + value: 3505677855 + objectReference: {fileID: 0} + - target: {fileID: 1499607153087855347, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: InScenePlacedSourceGlobalObjectIdHash + value: 882396614 + objectReference: {fileID: 0} + - target: {fileID: 4843296344903462454, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_Name + value: SessionOwnerNetworkObjectSpawner (1) + objectReference: {fileID: 0} + - target: {fileID: 8817259292813230997, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_NetworkObjectToSpawn + value: + objectReference: {fileID: 5499784127695994160, guid: 1c6ec0a7b92244c349d83ba9b4a1c8ab, type: 3} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: e54d55fa193a2495ea1270535da81837, type: 3} +--- !u!1001 &373304902 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalPosition.x + value: -2 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalPosition.y + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalPosition.z + value: 5 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1499607153087855347, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: GlobalObjectIdHash + value: 910008014 + objectReference: {fileID: 0} + - target: {fileID: 1499607153087855347, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: InScenePlacedSourceGlobalObjectIdHash + value: 882396614 + objectReference: {fileID: 0} + - target: {fileID: 4843296344903462454, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_Name + value: SessionOwnerNetworkObjectSpawner (3) + objectReference: {fileID: 0} + - target: {fileID: 8817259292813230997, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_NetworkObjectToSpawn + value: + objectReference: {fileID: 5499784127695994160, guid: 1c6ec0a7b92244c349d83ba9b4a1c8ab, type: 3} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: e54d55fa193a2495ea1270535da81837, type: 3} --- !u!1 &410087039 GameObject: m_ObjectHideFlags: 0 @@ -288,6 +426,75 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1001 &961771512 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalPosition.y + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalPosition.z + value: 5 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1499607153087855347, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: GlobalObjectIdHash + value: 3782993129 + objectReference: {fileID: 0} + - target: {fileID: 1499607153087855347, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: InScenePlacedSourceGlobalObjectIdHash + value: 882396614 + objectReference: {fileID: 0} + - target: {fileID: 4843296344903462454, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_Name + value: SessionOwnerNetworkObjectSpawner (4) + objectReference: {fileID: 0} + - target: {fileID: 8817259292813230997, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_NetworkObjectToSpawn + value: + objectReference: {fileID: 5499784127695994160, guid: 1c6ec0a7b92244c349d83ba9b4a1c8ab, type: 3} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: e54d55fa193a2495ea1270535da81837, type: 3} --- !u!1 &1305680749 GameObject: m_ObjectHideFlags: 0 @@ -332,6 +539,75 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1001 &1329704198 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalPosition.x + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalPosition.y + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalPosition.z + value: 5 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1499607153087855347, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: GlobalObjectIdHash + value: 1417850551 + objectReference: {fileID: 0} + - target: {fileID: 1499607153087855347, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: InScenePlacedSourceGlobalObjectIdHash + value: 882396614 + objectReference: {fileID: 0} + - target: {fileID: 4843296344903462454, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_Name + value: SessionOwnerNetworkObjectSpawner (5) + objectReference: {fileID: 0} + - target: {fileID: 8817259292813230997, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_NetworkObjectToSpawn + value: + objectReference: {fileID: 5499784127695994160, guid: 1c6ec0a7b92244c349d83ba9b4a1c8ab, type: 3} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: e54d55fa193a2495ea1270535da81837, type: 3} --- !u!1 &1888825843 GameObject: m_ObjectHideFlags: 0 @@ -441,6 +717,75 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1001 &1947161561 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalPosition.x + value: -2 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalPosition.y + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalPosition.z + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1499607153087855347, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: GlobalObjectIdHash + value: 2143928463 + objectReference: {fileID: 0} + - target: {fileID: 1499607153087855347, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: InScenePlacedSourceGlobalObjectIdHash + value: 882396614 + objectReference: {fileID: 0} + - target: {fileID: 4843296344903462454, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_Name + value: SessionOwnerNetworkObjectSpawner + objectReference: {fileID: 0} + - target: {fileID: 8817259292813230997, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_NetworkObjectToSpawn + value: + objectReference: {fileID: 5499784127695994160, guid: 1c6ec0a7b92244c349d83ba9b4a1c8ab, type: 3} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: e54d55fa193a2495ea1270535da81837, type: 3} --- !u!1001 &2024073102 PrefabInstance: m_ObjectHideFlags: 0 @@ -498,6 +843,75 @@ PrefabInstance: m_AddedGameObjects: [] m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: eb439f24fcad44d48b8231b7418345d0, type: 3} +--- !u!1001 &2029928583 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalPosition.x + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalPosition.y + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalPosition.z + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1258953842080244886, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1499607153087855347, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: GlobalObjectIdHash + value: 4096214831 + objectReference: {fileID: 0} + - target: {fileID: 1499607153087855347, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: InScenePlacedSourceGlobalObjectIdHash + value: 882396614 + objectReference: {fileID: 0} + - target: {fileID: 4843296344903462454, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_Name + value: SessionOwnerNetworkObjectSpawner (2) + objectReference: {fileID: 0} + - target: {fileID: 8817259292813230997, guid: e54d55fa193a2495ea1270535da81837, type: 3} + propertyPath: m_NetworkObjectToSpawn + value: + objectReference: {fileID: 5499784127695994160, guid: 1c6ec0a7b92244c349d83ba9b4a1c8ab, type: 3} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: e54d55fa193a2495ea1270535da81837, type: 3} --- !u!1660057539 &9223372036854775807 SceneRoots: m_ObjectHideFlags: 0 @@ -507,3 +921,9 @@ SceneRoots: - {fileID: 2024073102} - {fileID: 1888825847} - {fileID: 1305680751} + - {fileID: 1947161561} + - {fileID: 43234386} + - {fileID: 2029928583} + - {fileID: 373304902} + - {fileID: 961771512} + - {fileID: 1329704198} diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/EnvironmentTransform.cs b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/EnvironmentTransform.cs new file mode 100644 index 000000000..17decbb41 --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/EnvironmentTransform.cs @@ -0,0 +1,54 @@ +using System; +using Unity.Netcode; +using Unity.Netcode.Components; +using UnityEngine; + +namespace Unity.Multiplayer.Samples.SocialHub.Gameplay +{ + class EnvironmentTransform : NetworkTransform, IOwnershipRequestable, IGameplayEventInvokable + { + public event Action OnNetworkObjectOwnershipRequestResponse; + + public event Action OnGameplayEvent; + + public override void OnNetworkSpawn() + { + base.OnNetworkSpawn(); + + NetworkObject.OnOwnershipRequested += OnOwnershipRequested; + NetworkObject.OnOwnershipRequestResponse += OnOwnershipRequestResponse; + } + + public override void OnNetworkDespawn() + { + if (NetworkObject) + { + NetworkObject.OnOwnershipRequested -= OnOwnershipRequested; + NetworkObject.OnOwnershipRequestResponse -= OnOwnershipRequestResponse; + } + + OnGameplayEvent?.Invoke(NetworkObject, GameplayEvent.Despawned); + } + + protected override void OnOwnershipChanged(ulong previous, ulong current) + { + base.OnOwnershipChanged(previous, current); + + OnGameplayEvent?.Invoke(NetworkObject, GameplayEvent.OwnershipChange); + } + + // note: invoked on owning client + bool OnOwnershipRequested(ulong clientRequesting) + { + // defaulting all ownership requests to true, as is the default for all ownership requests + // here, you'd introduce game-based logic to deny/approve requests + return true; + } + + // note: invoked on requesting client + void OnOwnershipRequestResponse(NetworkObject.OwnershipRequestResponseStatus ownershipRequestResponse) + { + OnNetworkObjectOwnershipRequestResponse?.Invoke(NetworkObject, ownershipRequestResponse); + } + } +} diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/EnvironmentTransform.cs.meta b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/EnvironmentTransform.cs.meta new file mode 100644 index 000000000..fa3a503d7 --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/EnvironmentTransform.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 54937e94f00ab46c8ae43b81027f342c \ No newline at end of file diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/SessionOwnerNetworkObjectSpawner.cs b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/SessionOwnerNetworkObjectSpawner.cs new file mode 100644 index 000000000..f255bc0c9 --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/SessionOwnerNetworkObjectSpawner.cs @@ -0,0 +1,27 @@ +using Unity.Netcode; +using UnityEngine; + +namespace Unity.Multiplayer.Samples.SocialHub.Gameplay +{ + class SessionOwnerNetworkObjectSpawner : NetworkBehaviour + { + [SerializeField] + NetworkObject m_NetworkObjectToSpawn; + + NetworkVariable m_InitialSpawnComplete = new NetworkVariable(); + + public override void OnNetworkSpawn() + { + if (IsSessionOwner && !m_InitialSpawnComplete.Value) + { + Spawn(); + } + } + + void Spawn() + { + m_NetworkObjectToSpawn.InstantiateAndSpawn(NetworkManager, position: transform.position, rotation: transform.rotation); + m_InitialSpawnComplete.Value = true; + } + } +} diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/SessionOwnerNetworkObjectSpawner.cs.meta b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/SessionOwnerNetworkObjectSpawner.cs.meta new file mode 100644 index 000000000..50612e5bb --- /dev/null +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Gameplay/SessionOwnerNetworkObjectSpawner.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: eea4e07da167d4da7beddb67532a15f2 \ No newline at end of file diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/AvatarTransform.cs b/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/AvatarTransform.cs index 90b14338c..19aed92b3 100644 --- a/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/AvatarTransform.cs +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/AvatarTransform.cs @@ -52,6 +52,7 @@ public override void OnNetworkSpawn() } m_PlayerInput.enabled = true; + m_AvatarInputs.enabled = true; m_Rigidbody.isKinematic = false; // Freeze rotation on the x and z axes to prevent toppling From 301856bf5f690bd08862699989ca181ffab504c3 Mon Sep 17 00:00:00 2001 From: Fernando Cortez Date: Thu, 15 Aug 2024 16:00:58 -0400 Subject: [PATCH 6/6] adding explicitly inputsystem to player assembly --- .../Assets/Prefabs/Avatar.prefab | 17 ++++++++--------- .../Assets/Scripts/Player/AvatarTransform.cs | 4 +++- ....Multiplayer.Samples.SocialHub.Player.asmdef | 3 ++- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Experimental/DistributedAuthoritySample/Assets/Prefabs/Avatar.prefab b/Experimental/DistributedAuthoritySample/Assets/Prefabs/Avatar.prefab index 5bac5aa18..4bcfbc52e 100644 --- a/Experimental/DistributedAuthoritySample/Assets/Prefabs/Avatar.prefab +++ b/Experimental/DistributedAuthoritySample/Assets/Prefabs/Avatar.prefab @@ -290,7 +290,6 @@ MonoBehaviour: InLocalSpace: 0 Interpolate: 1 SlerpPosition: 0 - PropertiesVisible: 1 m_Rigidbody: {fileID: 4745766379562620470} m_PlayerInput: {fileID: 4903152183366241606} m_AvatarInputs: {fileID: 8197190117666738524} @@ -382,15 +381,15 @@ MonoBehaviour: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5478015027486214707} - m_Enabled: 1 + m_Enabled: 0 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 7e9f71718dd134b14b300e378e98c718, type: 3} m_Name: m_EditorClassIdentifier: - move: {x: 0, y: 0} - look: {x: 0, y: 0} - jump: 0 - sprint: 0 - analogMovement: 0 - cursorLocked: 1 - cursorInputForLook: 1 + Move: {x: 0, y: 0} + Look: {x: 0, y: 0} + Jump: 0 + Sprint: 0 + AnalogMovement: 0 + CursorLocked: 1 + CursorInputForLook: 1 diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/AvatarTransform.cs b/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/AvatarTransform.cs index 90b14338c..7601e7640 100644 --- a/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/AvatarTransform.cs +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/AvatarTransform.cs @@ -1,6 +1,7 @@ using Unity.Netcode.Components; using UnityEngine; using Unity.Multiplayer.Samples.SocialHub.Input; +using UnityEngine.InputSystem; namespace Unity.Multiplayer.Samples.SocialHub.Player { @@ -10,7 +11,7 @@ public class AvatarTransform : NetworkTransform [SerializeField] Rigidbody m_Rigidbody; [SerializeField] - MonoBehaviour m_PlayerInput; + PlayerInput m_PlayerInput; [SerializeField] AvatarInputs m_AvatarInputs; [SerializeField] @@ -52,6 +53,7 @@ public override void OnNetworkSpawn() } m_PlayerInput.enabled = true; + m_AvatarInputs.enabled = true; m_Rigidbody.isKinematic = false; // Freeze rotation on the x and z axes to prevent toppling diff --git a/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/Unity.Multiplayer.Samples.SocialHub.Player.asmdef b/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/Unity.Multiplayer.Samples.SocialHub.Player.asmdef index 5a39c55fa..ebff7a9ea 100644 --- a/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/Unity.Multiplayer.Samples.SocialHub.Player.asmdef +++ b/Experimental/DistributedAuthoritySample/Assets/Scripts/Player/Unity.Multiplayer.Samples.SocialHub.Player.asmdef @@ -4,7 +4,8 @@ "references": [ "GUID:1491147abca9d7d4bb7105af628b223e", "GUID:c15e7f658578345fcb824b0a64d4dbe8", - "GUID:9ff2150ce7d7c415a8af1fbff3dc3e6c" + "GUID:9ff2150ce7d7c415a8af1fbff3dc3e6c", + "GUID:75469ad4d38634e559750d17036d5f7c" ], "includePlatforms": [], "excludePlatforms": [],