feat: Distributed Authority Sample Avatar interactions (pick up & throw) [MTT-8905] [MTT-8884] (#208)

* asmdefs generated with dependencies mapped

* one unnecessary dependency removed

* renaming asmdefs & adding input assemblyinfo

* avatar-side pickup/toss of pickupable object

* adding a pickupable object, EnvironmentTransform, to scene with a spawner

* adding explicitly inputsystem to player assembly
This commit is contained in:
Fernando Cortez 2024-08-21 15:41:39 -04:00 коммит произвёл GitHub
Родитель 6f0f550ee1
Коммит dbfa3173ec
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
24 изменённых файлов: 1219 добавлений и 7 удалений

Просмотреть файл

@ -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
},
{

Просмотреть файл

@ -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}

Просмотреть файл

@ -212,6 +212,7 @@ GameObject:
- component: {fileID: -8100831418301897270}
- component: {fileID: 4903152183366241606}
- component: {fileID: 8197190117666738524}
- component: {fileID: 539700041658036575}
m_Layer: 0
m_Name: Avatar
m_TagString: Untagged
@ -233,6 +234,7 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 527982249900556139}
- {fileID: 3820763517226122587}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &2864305741433477372
@ -247,7 +249,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3}
m_Name:
m_EditorClassIdentifier:
GlobalObjectIdHash: 2473698027
GlobalObjectIdHash: 3001504883
InScenePlacedSourceGlobalObjectIdHash: 0
DeferredDespawnTick: 0
Ownership: 0
@ -356,7 +358,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 62899f850307741f2a39c98a8b639597, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Actions: {fileID: -944628639613478452, guid: dcd1b4eb76b964f40afe6c0a3ca65c82, type: 3}
m_Actions: {fileID: -944628639613478452, guid: dcd1b4eb76b964f40afe6c0a3ca65c82,
type: 3}
m_NotificationBehavior: 0
m_UIInputModule: {fileID: 0}
m_DeviceLostEvent:
@ -393,3 +396,77 @@ MonoBehaviour:
AnalogMovement: 0
CursorLocked: 1
CursorInputForLook: 1
m_InteractActionReference: {fileID: 1781555164194001046, guid: dcd1b4eb76b964f40afe6c0a3ca65c82,
type: 3}
--- !u!114 &539700041658036575
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: 3820763517226122587}
m_InteractCollider: {fileID: 4881592427634173612}
m_MinTossForce: 5
m_MaxTossForce: 10
--- !u!1 &9009864878170659705
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3820763517226122587}
- component: {fileID: 4881592427634173612}
m_Layer: 0
m_Name: InteractCollider
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &3820763517226122587
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9009864878170659705}
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 &4881592427634173612
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9009864878170659705}
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}

Просмотреть файл

@ -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

Просмотреть файл

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 1c6ec0a7b92244c349d83ba9b4a1c8ab
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -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}

Просмотреть файл

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e54d55fa193a2495ea1270535da81837
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -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}

Просмотреть файл

@ -0,0 +1,2 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Unity.Multiplayer.Samples.SocialHub.Player")]

Просмотреть файл

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3465502a3a2c6448b96874d02edbb908

Просмотреть файл

@ -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<NetworkObject, NetworkObject.OwnershipRequestResponseStatus> OnNetworkObjectOwnershipRequestResponse;
public event Action<NetworkObject, GameplayEvent> 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);
}
}
}

Просмотреть файл

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 54937e94f00ab46c8ae43b81027f342c

Просмотреть файл

@ -0,0 +1,10 @@
using UnityEngine;
namespace Unity.Multiplayer.Samples.SocialHub.Gameplay
{
enum GameplayEvent
{
Despawned,
OwnershipChange
}
}

Просмотреть файл

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 507a19fc89d974f28adddfe762c13eb7

Просмотреть файл

@ -0,0 +1,10 @@
using Unity.Netcode;
using UnityEngine;
namespace Unity.Multiplayer.Samples.SocialHub.Gameplay
{
interface IGameplayEventInvokable
{
event System.Action<NetworkObject, GameplayEvent> OnGameplayEvent;
}
}

Просмотреть файл

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0969e36952ce846e895b036088dd6afa

Просмотреть файл

@ -0,0 +1,11 @@
using System;
using Unity.Netcode;
using UnityEngine;
namespace Unity.Multiplayer.Samples.SocialHub.Gameplay
{
interface IOwnershipRequestable
{
event Action<NetworkObject, NetworkObject.OwnershipRequestResponseStatus> OnNetworkObjectOwnershipRequestResponse;
}
}

Просмотреть файл

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 071ac956e173f479691c6233c0f4fb2e

Просмотреть файл

@ -0,0 +1,27 @@
using Unity.Netcode;
using UnityEngine;
namespace Unity.Multiplayer.Samples.SocialHub.Gameplay
{
class SessionOwnerNetworkObjectSpawner : NetworkBehaviour
{
[SerializeField]
NetworkObject m_NetworkObjectToSpawn;
NetworkVariable<bool> m_InitialSpawnComplete = new NetworkVariable<bool>();
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;
}
}
}

Просмотреть файл

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: eea4e07da167d4da7beddb67532a15f2

Просмотреть файл

@ -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 @@ namespace Unity.Multiplayer.Samples.SocialHub.Input
[SerializeField]
internal bool CursorInputForLook = true;
internal event Action InteractTapped;
internal event Action<double> 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)
{

Просмотреть файл

@ -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<IOwnershipRequestable>();
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<IGameplayEventInvokable>();
gameplayEventInvokable.OnGameplayEvent += OnGameplayEvent;
// prevent collisions from this collider to the picked up object and vice-versa
Physics.IgnoreCollision(m_MainCollider, other.GetComponent<Collider>(), true);
}
}
void OnGameplayEvent(NetworkObject networkObject, GameplayEvent gameplayEvent)
{
switch (gameplayEvent)
{
case GameplayEvent.Despawned:
case GameplayEvent.OwnershipChange:
// unsubscribe
var gameplayEventInvokable = networkObject.GetComponent<IGameplayEventInvokable>();
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<Rigidbody>().useGravity = true;
Physics.IgnoreCollision(m_MainCollider, m_HoldingRigidbody.GetComponent<Collider>(), false);
m_HoldingRigidbody = null;
}
void Toss(double holdDuration)
{
var heldRigidbody = m_HoldingRigidbody.GetComponent<Rigidbody>();
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);
}
}
}

Просмотреть файл

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b47efef44cef74d9ca00f4913607f988

Просмотреть файл

@ -12,8 +12,8 @@ TagManager:
-
- Water
- UI
- '[Empty Slot]'
- Ground
- Pickupable
-
-
-