Add lobby/match-start matchmaking flow with additive scene management
Replace the connection-approval role selection with a server-authoritative match flow built on NGO additive scene management: - Scenes: Main is the persistent foundation (NetworkManager, GameModeManager, cameras, HUD); Lobby and Test Map load/unload additively. Add Lobby + Test Map to the build settings; remove the obsolete SampleScene. - MatchManager (plain MonoBehaviour singleton): loads Lobby on server start, StartMatchTrigger lets the host start the match, rolls one random Hunter (rest Hider), swaps Lobby -> Test Map (strictly serialized per NGO), respawns each player as its role variant. Forces additive client sync mode so clients keep Main instead of single-loading it (fixes "Destination scene is not valid"). - Server-driven spawning: null out NetworkConfig.PlayerPrefab at runtime to disable auto-spawn, then spawn players after the lobby floor exists (fixes falling through the floor) with double-spawn and transition guards. - StartMatchTrigger: server-gated OnTriggerEnter, only the host's own player starts the match. - NetworkBootstrap: drop role selection / connection approval; everyone spawns as the neutral Player prefab. Host/Client/Server/Shutdown buttons stay. - NetworkPlayerSetup.ScopedModes flag (baked on Hunter/Hider prefabs): lobby avatar gets the full mode set, match variants get the role-scoped set. - GameModeManager.BindLocalPlayer reads ScopedModes and rebinds the painter unconditionally (fixes stale painter binding on respawn -> brush painting in every mode). - MeshPainter.PaintingEnabled defaults to false (unbound/pre-spawn/remote never paints); PaintHud visibility now also gates on a bound painter (fixes the HUD showing at startup before any avatar exists). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
301f7e64cb
commit
bd70f3b8b9
18 files changed
+1813
-997
No files matched your search
@@ -72,6 +72,10 @@ PrefabInstance:
|
|||||||
propertyPath: m_LocalEulerAnglesHint.z
|
propertyPath: m_LocalEulerAnglesHint.z
|
||||||
value: 0
|
value: 0
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 8574096554986372233, guid: 97017ed3bb40aff4e885440d9a7336ee, type: 3}
|
||||||
|
propertyPath: scopedModes
|
||||||
|
value: 1
|
||||||
|
objectReference: {fileID: 0}
|
||||||
m_RemovedComponents: []
|
m_RemovedComponents: []
|
||||||
m_RemovedGameObjects: []
|
m_RemovedGameObjects: []
|
||||||
m_AddedGameObjects: []
|
m_AddedGameObjects: []
|
||||||
|
|||||||
@@ -80,6 +80,10 @@ PrefabInstance:
|
|||||||
propertyPath: role
|
propertyPath: role
|
||||||
value: 1
|
value: 1
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 8574096554986372233, guid: 97017ed3bb40aff4e885440d9a7336ee, type: 3}
|
||||||
|
propertyPath: scopedModes
|
||||||
|
value: 1
|
||||||
|
objectReference: {fileID: 0}
|
||||||
m_RemovedComponents: []
|
m_RemovedComponents: []
|
||||||
m_RemovedGameObjects: []
|
m_RemovedGameObjects: []
|
||||||
m_AddedGameObjects: []
|
m_AddedGameObjects: []
|
||||||
|
|||||||
@@ -0,0 +1,364 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!29 &1
|
||||||
|
OcclusionCullingSettings:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
serializedVersion: 2
|
||||||
|
m_OcclusionBakeSettings:
|
||||||
|
smallestOccluder: 5
|
||||||
|
smallestHole: 0.25
|
||||||
|
backfaceThreshold: 100
|
||||||
|
m_SceneGUID: 00000000000000000000000000000000
|
||||||
|
m_OcclusionCullingData: {fileID: 0}
|
||||||
|
--- !u!104 &2
|
||||||
|
RenderSettings:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
serializedVersion: 10
|
||||||
|
m_Fog: 0
|
||||||
|
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
|
||||||
|
m_FogMode: 3
|
||||||
|
m_FogDensity: 0.01
|
||||||
|
m_LinearFogStart: 0
|
||||||
|
m_LinearFogEnd: 300
|
||||||
|
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
|
||||||
|
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
|
||||||
|
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
|
||||||
|
m_AmbientIntensity: 1
|
||||||
|
m_AmbientMode: 0
|
||||||
|
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
|
||||||
|
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
|
||||||
|
m_HaloStrength: 0.5
|
||||||
|
m_FlareStrength: 1
|
||||||
|
m_FlareFadeSpeed: 3
|
||||||
|
m_HaloTexture: {fileID: 0}
|
||||||
|
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
|
||||||
|
m_DefaultReflectionMode: 0
|
||||||
|
m_DefaultReflectionResolution: 128
|
||||||
|
m_ReflectionBounces: 1
|
||||||
|
m_ReflectionIntensity: 1
|
||||||
|
m_CustomReflection: {fileID: 0}
|
||||||
|
m_Sun: {fileID: 0}
|
||||||
|
m_UseRadianceAmbientProbe: 0
|
||||||
|
--- !u!157 &3
|
||||||
|
LightmapSettings:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
serializedVersion: 13
|
||||||
|
m_BakeOnSceneLoad: 0
|
||||||
|
m_GISettings:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_BounceScale: 1
|
||||||
|
m_IndirectOutputScale: 1
|
||||||
|
m_AlbedoBoost: 1
|
||||||
|
m_EnvironmentLightingMode: 0
|
||||||
|
m_EnableBakedLightmaps: 1
|
||||||
|
m_EnableRealtimeLightmaps: 0
|
||||||
|
m_LightmapEditorSettings:
|
||||||
|
serializedVersion: 12
|
||||||
|
m_Resolution: 2
|
||||||
|
m_BakeResolution: 40
|
||||||
|
m_AtlasSize: 1024
|
||||||
|
m_AO: 0
|
||||||
|
m_AOMaxDistance: 1
|
||||||
|
m_CompAOExponent: 1
|
||||||
|
m_CompAOExponentDirect: 0
|
||||||
|
m_ExtractAmbientOcclusion: 0
|
||||||
|
m_Padding: 2
|
||||||
|
m_LightmapParameters: {fileID: 0}
|
||||||
|
m_LightmapsBakeMode: 1
|
||||||
|
m_TextureCompression: 1
|
||||||
|
m_ReflectionCompression: 2
|
||||||
|
m_MixedBakeMode: 2
|
||||||
|
m_BakeBackend: 2
|
||||||
|
m_PVRSampling: 1
|
||||||
|
m_PVRDirectSampleCount: 32
|
||||||
|
m_PVRSampleCount: 512
|
||||||
|
m_PVRBounces: 2
|
||||||
|
m_PVREnvironmentSampleCount: 256
|
||||||
|
m_PVREnvironmentReferencePointCount: 2048
|
||||||
|
m_PVRFilteringMode: 1
|
||||||
|
m_PVRDenoiserTypeDirect: 1
|
||||||
|
m_PVRDenoiserTypeIndirect: 1
|
||||||
|
m_PVRDenoiserTypeAO: 1
|
||||||
|
m_PVRFilterTypeDirect: 0
|
||||||
|
m_PVRFilterTypeIndirect: 0
|
||||||
|
m_PVRFilterTypeAO: 0
|
||||||
|
m_PVREnvironmentMIS: 1
|
||||||
|
m_PVRCulling: 1
|
||||||
|
m_PVRFilteringGaussRadiusDirect: 1
|
||||||
|
m_PVRFilteringGaussRadiusIndirect: 1
|
||||||
|
m_PVRFilteringGaussRadiusAO: 1
|
||||||
|
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
|
||||||
|
m_PVRFilteringAtrousPositionSigmaIndirect: 2
|
||||||
|
m_PVRFilteringAtrousPositionSigmaAO: 1
|
||||||
|
m_ExportTrainingData: 0
|
||||||
|
m_TrainingDataDestination: TrainingData
|
||||||
|
m_LightProbeSampleCountMultiplier: 4
|
||||||
|
m_LightingDataAsset: {fileID: 20201, guid: 0000000000000000f000000000000000, type: 0}
|
||||||
|
m_LightingSettings: {fileID: 0}
|
||||||
|
--- !u!196 &4
|
||||||
|
NavMeshSettings:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_BuildSettings:
|
||||||
|
serializedVersion: 3
|
||||||
|
agentTypeID: 0
|
||||||
|
agentRadius: 0.5
|
||||||
|
agentHeight: 2
|
||||||
|
agentSlope: 45
|
||||||
|
agentClimb: 0.4
|
||||||
|
ledgeDropHeight: 0
|
||||||
|
maxJumpAcrossDistance: 0
|
||||||
|
minRegionArea: 2
|
||||||
|
manualCellSize: 0
|
||||||
|
cellSize: 0.16666667
|
||||||
|
manualTileSize: 0
|
||||||
|
tileSize: 256
|
||||||
|
buildHeightMesh: 0
|
||||||
|
maxJobWorkers: 0
|
||||||
|
preserveTilesOutsideBounds: 0
|
||||||
|
debug:
|
||||||
|
m_Flags: 0
|
||||||
|
m_NavMeshData: {fileID: 0}
|
||||||
|
--- !u!1 &968373997
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 968374001}
|
||||||
|
- component: {fileID: 968374000}
|
||||||
|
- component: {fileID: 968373999}
|
||||||
|
- component: {fileID: 968373998}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: Floor
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!65 &968373998
|
||||||
|
BoxCollider:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 968373997}
|
||||||
|
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!23 &968373999
|
||||||
|
MeshRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 968373997}
|
||||||
|
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_ForceMeshLod: -1
|
||||||
|
m_MeshLodSelectionBias: 0
|
||||||
|
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_GlobalIlluminationMeshLod: 0
|
||||||
|
m_SortingLayerID: 0
|
||||||
|
m_SortingLayer: 0
|
||||||
|
m_SortingOrder: 0
|
||||||
|
m_MaskInteraction: 0
|
||||||
|
m_AdditionalVertexStreams: {fileID: 0}
|
||||||
|
--- !u!33 &968374000
|
||||||
|
MeshFilter:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 968373997}
|
||||||
|
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
|
||||||
|
--- !u!4 &968374001
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 968373997}
|
||||||
|
serializedVersion: 2
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: -1, z: 0}
|
||||||
|
m_LocalScale: {x: 10, y: 1, z: 10}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!1 &2141865149
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 2141865153}
|
||||||
|
- component: {fileID: 2141865152}
|
||||||
|
- component: {fileID: 2141865151}
|
||||||
|
- component: {fileID: 2141865150}
|
||||||
|
- component: {fileID: 2141865154}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: Start Match
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!65 &2141865150
|
||||||
|
BoxCollider:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2141865149}
|
||||||
|
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!23 &2141865151
|
||||||
|
MeshRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2141865149}
|
||||||
|
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_ForceMeshLod: -1
|
||||||
|
m_MeshLodSelectionBias: 0
|
||||||
|
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_GlobalIlluminationMeshLod: 0
|
||||||
|
m_SortingLayerID: 0
|
||||||
|
m_SortingLayer: 0
|
||||||
|
m_SortingOrder: 0
|
||||||
|
m_MaskInteraction: 0
|
||||||
|
m_AdditionalVertexStreams: {fileID: 0}
|
||||||
|
--- !u!33 &2141865152
|
||||||
|
MeshFilter:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2141865149}
|
||||||
|
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
|
||||||
|
--- !u!4 &2141865153
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2141865149}
|
||||||
|
serializedVersion: 2
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: -3.89, 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 &2141865154
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2141865149}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: dbc3790cccc4958458bb38d883b69afb, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier: Assembly-CSharp::StartMatchTrigger
|
||||||
|
--- !u!1660057539 &9223372036854775807
|
||||||
|
SceneRoots:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_Roots:
|
||||||
|
- {fileID: 968374001}
|
||||||
|
- {fileID: 2141865153}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3d1c04c698b4f32438a69661b90ff58b
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
File diff suppressed because it is too large.
Load diff
File renamed without changes.
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 427f9e7bc57fb6e49a9233fc60022383
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -137,8 +137,12 @@ public class GameModeManager : MonoBehaviour
|
|||||||
if (!localPlayer) return;
|
if (!localPlayer) return;
|
||||||
player = localPlayer;
|
player = localPlayer;
|
||||||
|
|
||||||
// The painter lives on the player (per-avatar), so bind the local one.
|
// The painter lives on the player (per-avatar), so bind the local one - UNCONDITIONALLY. On a
|
||||||
if (!painter) painter = localPlayer.GetComponentInChildren<MeshPainter>(true);
|
// lobby->match respawn the previous avatar is despawned and the role variant spawned in the same
|
||||||
|
// server frame; the old painter is Destroy-pending (still non-null) when this runs, so a
|
||||||
|
// `if (!painter)` guard would keep the stale reference and the new avatar's painter would never be
|
||||||
|
// mode-toggled - it would paint in every mode. Always re-point to the freshly spawned avatar.
|
||||||
|
painter = localPlayer.GetComponentInChildren<MeshPainter>(true);
|
||||||
PainterChanged?.Invoke(painter);
|
PainterChanged?.Invoke(painter);
|
||||||
|
|
||||||
Transform camTarget = localPlayer.transform.Find("CameraTarget");
|
Transform camTarget = localPlayer.transform.Find("CameraTarget");
|
||||||
@@ -157,11 +161,16 @@ public class GameModeManager : MonoBehaviour
|
|||||||
ActiveMode?.Exit();
|
ActiveMode?.Exit();
|
||||||
_activeIndex = -1;
|
_activeIndex = -1;
|
||||||
|
|
||||||
|
// Lobby/neutral avatar (base Player prefab) -> full mode set; match avatar (Hunter/Hider
|
||||||
|
// variant) -> only its role's modes. Baked per prefab, so no replicated-phase timing race.
|
||||||
var setup = localPlayer.GetComponent<NetworkPlayerSetup>();
|
var setup = localPlayer.GetComponent<NetworkPlayerSetup>();
|
||||||
PlayerRole role = setup ? setup.Role : PlayerRole.Hider;
|
if (setup && setup.ScopedModes)
|
||||||
BuildModes(role);
|
BuildModes(setup.Role);
|
||||||
|
else
|
||||||
|
BuildModes(null);
|
||||||
|
|
||||||
// Each role list is ordered so index 0 is its start mode (Hunter -> First Person, Hider -> Player Control).
|
// Role lists are ordered so index 0 is the start mode (Hunter -> First Person, Hider -> Player
|
||||||
|
// Control); the full lobby set starts at Player Control too.
|
||||||
SwitchTo(0);
|
SwitchTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,282 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Unity.Netcode;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Server-authoritative match flow. Lives on the persistent NetworkManager object in the boot scene
|
||||||
|
/// (Main), which stays loaded the whole session (NetworkManager, cameras, HUD). The gameplay scenes
|
||||||
|
/// (Lobby, Test Map) are loaded ADDITIVELY through NGO's scene manager so Main is never torn down.
|
||||||
|
///
|
||||||
|
/// Two design pillars make the persistent-Main + additive-gameplay model actually work:
|
||||||
|
///
|
||||||
|
/// 1. Clients sync ADDITIVELY (<see cref="NetworkSceneManager.SetClientSynchronizationMode"/> =
|
||||||
|
/// <see cref="LoadSceneMode.Additive"/>). The NGO default (Single) would unload every scene the
|
||||||
|
/// connecting client already has - including its own Main (cameras/HUD/managers) - and reload the
|
||||||
|
/// server's active scene in single mode, which also crashes the player-object scene migration
|
||||||
|
/// (MoveGameObjectToScene "Destination scene is not valid"). Additive keeps the client's Main and
|
||||||
|
/// layers the server's scenes on top. Must be set on the server before any client connects; it is
|
||||||
|
/// auto-propagated to clients via the synchronize event.
|
||||||
|
///
|
||||||
|
/// 2. Players are spawned by THIS manager, not by NGO auto-spawn. NGO would auto-spawn the player the
|
||||||
|
/// instant a peer connects, into whatever scene is active right then - for the host that is Main
|
||||||
|
/// (the additive Lobby load is still in flight), which has no floor, so the host falls into the
|
||||||
|
/// void. We disable auto-spawn (null out <see cref="NetworkConfig.PlayerPrefab"/>) and instead
|
||||||
|
/// spawn the neutral Player prefab into the gameplay scene only once it is loaded, so avatars always
|
||||||
|
/// land on a floor. Main therefore holds zero network objects.
|
||||||
|
///
|
||||||
|
/// Flow: server start -> additive sync mode set -> Lobby loaded additively -> Player spawned for every
|
||||||
|
/// connected peer (full mode set, including First Person). Late joiners spawn on connect into the
|
||||||
|
/// already-loaded scene. The host walks into the Start Match trigger -> <see cref="StartMatch"/>: one
|
||||||
|
/// random connected client is rolled Hunter, the rest Hider; the Lobby is unloaded and Test Map loaded
|
||||||
|
/// (strictly serialized - an NGO constraint, only one scene op in flight); then every player object is
|
||||||
|
/// despawned and respawned as its role's prefab variant.
|
||||||
|
///
|
||||||
|
/// Not a NetworkBehaviour by design: every state change rides existing NGO replication (additive scene
|
||||||
|
/// sync + player-object spawn/despawn), so there is no in-scene NetworkObject hash matching or custom
|
||||||
|
/// RPC to get wrong. The phase here is server-local guard state; clients infer their mode set from the
|
||||||
|
/// spawned avatar (<see cref="NetworkPlayerSetup.ScopedModes"/>), not from a replicated phase, so there
|
||||||
|
/// is no spawn-vs-phase timing race.
|
||||||
|
/// </summary>
|
||||||
|
[DisallowMultipleComponent]
|
||||||
|
public class MatchManager : MonoBehaviour
|
||||||
|
{
|
||||||
|
public enum MatchPhase { Lobby, Transitioning, InMatch }
|
||||||
|
|
||||||
|
public static MatchManager Instance { get; private set; }
|
||||||
|
|
||||||
|
[Header("Scenes (must be in Build Settings)")]
|
||||||
|
[SerializeField] private string lobbySceneName = "Lobby";
|
||||||
|
[SerializeField] private string matchSceneName = "Test Map";
|
||||||
|
|
||||||
|
[Header("Role prefab variants (must be registered network prefabs)")]
|
||||||
|
[SerializeField] private GameObject hunterPrefab;
|
||||||
|
[SerializeField] private GameObject hiderPrefab;
|
||||||
|
|
||||||
|
[Header("Spawn")]
|
||||||
|
[Tooltip("World position lobby avatars are spawned at (raised a touch above the floor so gravity " +
|
||||||
|
"settles them). Per-client ring fan-out is applied on top (NetworkPlayerSetup.PlaceOnSpawnRing).")]
|
||||||
|
[SerializeField] private Vector3 lobbySpawnCenter = new Vector3(0f, 1f, 0f);
|
||||||
|
|
||||||
|
[Tooltip("World position the respawned match avatars are placed at on the match map; per-client ring " +
|
||||||
|
"fan-out is applied on top (NetworkPlayerSetup.PlaceOnSpawnRing).")]
|
||||||
|
[SerializeField] private Vector3 matchSpawnCenter = new Vector3(0f, 1f, 0f);
|
||||||
|
|
||||||
|
/// <summary>Server-local phase guard. Not replicated - see class summary.</summary>
|
||||||
|
public MatchPhase Phase { get; private set; } = MatchPhase.Lobby;
|
||||||
|
|
||||||
|
private NetworkManager _net;
|
||||||
|
private GameObject _playerPrefab; // captured from NetworkConfig.PlayerPrefab; auto-spawn is then disabled so we spawn manually into a loaded scene
|
||||||
|
private bool _hooked;
|
||||||
|
private bool _sceneReady; // server-only: a gameplay scene (lobby/map) is loaded & active, so it is safe to spawn avatars
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
if (Instance && Instance != this) { Destroy(this); return; }
|
||||||
|
Instance = this;
|
||||||
|
_net = GetComponent<NetworkManager>();
|
||||||
|
if (!_net) _net = FindFirstObjectByType<NetworkManager>();
|
||||||
|
|
||||||
|
// Disable NGO auto-spawn (decided purely by PlayerPrefab != null on both host and remote paths).
|
||||||
|
// We keep the reference and spawn manually once a floored scene exists. Runtime-only mutation -
|
||||||
|
// the scene asset still carries PlayerPrefab, so there is no asset diff.
|
||||||
|
if (_net != null)
|
||||||
|
{
|
||||||
|
_playerPrefab = _net.NetworkConfig.PlayerPrefab;
|
||||||
|
_net.NetworkConfig.PlayerPrefab = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnEnable()
|
||||||
|
{
|
||||||
|
if (!_net) _net = FindFirstObjectByType<NetworkManager>();
|
||||||
|
if (!_net) return;
|
||||||
|
_net.OnServerStarted += OnServerStarted;
|
||||||
|
_net.OnClientStarted += OnClientStarted;
|
||||||
|
_net.OnServerStopped += OnNetStopped;
|
||||||
|
_net.OnClientStopped += OnNetStopped;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDisable()
|
||||||
|
{
|
||||||
|
if (_net)
|
||||||
|
{
|
||||||
|
_net.OnServerStarted -= OnServerStarted;
|
||||||
|
_net.OnClientStarted -= OnClientStarted;
|
||||||
|
_net.OnServerStopped -= OnNetStopped;
|
||||||
|
_net.OnClientStopped -= OnNetStopped;
|
||||||
|
_net.OnClientConnectedCallback -= OnClientConnected;
|
||||||
|
if (_net.SceneManager != null) _net.SceneManager.OnSceneEvent -= OnSceneEvent;
|
||||||
|
}
|
||||||
|
if (Instance == this) Instance = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnServerStarted()
|
||||||
|
{
|
||||||
|
HookSceneManager();
|
||||||
|
|
||||||
|
// Keep the connecting client's already-loaded scenes (its Main) and layer ours on top.
|
||||||
|
// Must run before any client synchronizes; auto-propagates to clients. See class summary.
|
||||||
|
if (_net.SceneManager != null)
|
||||||
|
_net.SceneManager.SetClientSynchronizationMode(LoadSceneMode.Additive);
|
||||||
|
|
||||||
|
Phase = MatchPhase.Lobby;
|
||||||
|
_sceneReady = false;
|
||||||
|
|
||||||
|
// Spawn late joiners on connect (server-side callback). Re-hook defensively in case of re-host.
|
||||||
|
_net.OnClientConnectedCallback -= OnClientConnected;
|
||||||
|
_net.OnClientConnectedCallback += OnClientConnected;
|
||||||
|
|
||||||
|
StartCoroutine(LoadLobbyRoutine());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnClientStarted() => HookSceneManager();
|
||||||
|
|
||||||
|
private void OnNetStopped(bool _)
|
||||||
|
{
|
||||||
|
_hooked = false;
|
||||||
|
_sceneReady = false;
|
||||||
|
Phase = MatchPhase.Lobby;
|
||||||
|
if (_net) _net.OnClientConnectedCallback -= OnClientConnected;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HookSceneManager()
|
||||||
|
{
|
||||||
|
if (_hooked || _net == null || _net.SceneManager == null) return;
|
||||||
|
_net.SceneManager.OnSceneEvent += OnSceneEvent;
|
||||||
|
_hooked = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keep the freshly loaded gameplay scene the ACTIVE scene on every machine (lighting / skybox /
|
||||||
|
// instantiation context) - NGO additive loads don't promote the active scene on their own.
|
||||||
|
private void OnSceneEvent(SceneEvent e)
|
||||||
|
{
|
||||||
|
if (e.SceneEventType != SceneEventType.LoadComplete) return;
|
||||||
|
if (e.SceneName != lobbySceneName && e.SceneName != matchSceneName) return;
|
||||||
|
if (e.Scene.IsValid() && e.Scene.isLoaded) SceneManager.SetActiveScene(e.Scene);
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerator LoadLobbyRoutine()
|
||||||
|
{
|
||||||
|
yield return SceneOp(() => _net.SceneManager.LoadScene(lobbySceneName, LoadSceneMode.Additive),
|
||||||
|
SceneEventType.LoadEventCompleted, lobbySceneName);
|
||||||
|
|
||||||
|
// Lobby is loaded and active on the server: now it is safe to spawn the already-connected
|
||||||
|
// peers (the host, plus anyone who connected while the load was in flight).
|
||||||
|
_sceneReady = true;
|
||||||
|
foreach (ulong id in new List<ulong>(_net.ConnectedClientsIds)) SpawnPlayerFor(id, lobbySpawnCenter);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server-side: a peer finished connecting. If a gameplay scene is already up, spawn it now;
|
||||||
|
// otherwise LoadLobbyRoutine (lobby) or RespawnAll (mid-transition) covers it (the PlayerObject
|
||||||
|
// guard in SpawnPlayerFor prevents a double spawn).
|
||||||
|
private void OnClientConnected(ulong clientId)
|
||||||
|
{
|
||||||
|
if (_net == null || !_net.IsServer) return;
|
||||||
|
// During the Lobby->Test Map swap the active scene briefly falls back to Main (no floor); defer
|
||||||
|
// and let RespawnAll spawn this joiner once the map is loaded.
|
||||||
|
if (!_sceneReady || Phase == MatchPhase.Transitioning) return;
|
||||||
|
Vector3 at = Phase == MatchPhase.InMatch ? matchSpawnCenter : lobbySpawnCenter;
|
||||||
|
SpawnPlayerFor(clientId, at);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Spawns the neutral Player avatar for a client into the currently active gameplay scene. No-op if
|
||||||
|
// the client already owns a player object (double-spawn guard) or has since disconnected.
|
||||||
|
private void SpawnPlayerFor(ulong clientId, Vector3 at)
|
||||||
|
{
|
||||||
|
if (!_playerPrefab)
|
||||||
|
{
|
||||||
|
Debug.LogError("[MatchManager] Player prefab missing (was NetworkConfig.PlayerPrefab assigned?) - cannot spawn.", this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!_net.ConnectedClients.TryGetValue(clientId, out var client)) return;
|
||||||
|
if (client.PlayerObject) return;
|
||||||
|
|
||||||
|
var go = Instantiate(_playerPrefab, at, Quaternion.identity);
|
||||||
|
go.GetComponent<NetworkObject>().SpawnAsPlayerObject(clientId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Server-only. Starts the match: roll roles, swap Lobby -> Test Map, respawn as variants.
|
||||||
|
/// Safe to call repeatedly (only acts once, while still in the lobby phase).</summary>
|
||||||
|
public void StartMatch()
|
||||||
|
{
|
||||||
|
if (_net == null || !_net.IsServer) return;
|
||||||
|
if (Phase != MatchPhase.Lobby) return; // double-start / not-in-lobby guard
|
||||||
|
if (!hunterPrefab || !hiderPrefab)
|
||||||
|
{
|
||||||
|
Debug.LogError("[MatchManager] Role prefabs not assigned - cannot start match.", this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var ids = new List<ulong>(_net.ConnectedClientsIds);
|
||||||
|
if (ids.Count == 0) return;
|
||||||
|
|
||||||
|
Phase = MatchPhase.Transitioning;
|
||||||
|
ulong hunterId = ids[Random.Range(0, ids.Count)];
|
||||||
|
Debug.Log($"[MatchManager] Starting match. Hunter = client {hunterId}, {ids.Count} player(s).", this);
|
||||||
|
|
||||||
|
StartCoroutine(MatchSequence(hunterId));
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerator MatchSequence(ulong hunterId)
|
||||||
|
{
|
||||||
|
var sm = _net.SceneManager;
|
||||||
|
|
||||||
|
// 1. Unload the lobby (strictly serialized: one scene op in flight at a time).
|
||||||
|
Scene lobby = SceneManager.GetSceneByName(lobbySceneName);
|
||||||
|
if (lobby.IsValid() && lobby.isLoaded)
|
||||||
|
yield return SceneOp(() => sm.UnloadScene(lobby), SceneEventType.UnloadEventCompleted, lobbySceneName);
|
||||||
|
|
||||||
|
// 2. Load the match map.
|
||||||
|
yield return SceneOp(() => sm.LoadScene(matchSceneName, LoadSceneMode.Additive),
|
||||||
|
SceneEventType.LoadEventCompleted, matchSceneName);
|
||||||
|
|
||||||
|
// 3. Respawn every player as its rolled role's prefab variant.
|
||||||
|
RespawnAll(hunterId);
|
||||||
|
|
||||||
|
Phase = MatchPhase.InMatch;
|
||||||
|
Debug.Log("[MatchManager] Match started.", this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Runs an NGO scene op and waits for its server-side completion event. NGO rejects a new op while one
|
||||||
|
// is in flight, so callers must await this before issuing the next.
|
||||||
|
private IEnumerator SceneOp(System.Func<SceneEventProgressStatus> op, SceneEventType completed, string sceneName)
|
||||||
|
{
|
||||||
|
bool done = false;
|
||||||
|
void OnEvt(SceneEvent e)
|
||||||
|
{
|
||||||
|
if (e.SceneEventType == completed && e.SceneName == sceneName) done = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
_net.SceneManager.OnSceneEvent += OnEvt;
|
||||||
|
SceneEventProgressStatus status = op();
|
||||||
|
if (status != SceneEventProgressStatus.Started)
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"[MatchManager] Scene op on '{sceneName}' returned {status}.", this);
|
||||||
|
_net.SceneManager.OnSceneEvent -= OnEvt;
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!done) yield return null;
|
||||||
|
_net.SceneManager.OnSceneEvent -= OnEvt;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RespawnAll(ulong hunterId)
|
||||||
|
{
|
||||||
|
var ids = new List<ulong>(_net.ConnectedClientsIds);
|
||||||
|
foreach (ulong id in ids)
|
||||||
|
{
|
||||||
|
if (!_net.ConnectedClients.TryGetValue(id, out var client)) continue;
|
||||||
|
GameObject prefab = (id == hunterId) ? hunterPrefab : hiderPrefab;
|
||||||
|
|
||||||
|
// Despawn the lobby avatar first so the client has no stale player object when the variant
|
||||||
|
// claims the slot (avoids NGO's "already has a player object" reassign warning).
|
||||||
|
NetworkObject old = client.PlayerObject;
|
||||||
|
if (old) old.Despawn(true);
|
||||||
|
|
||||||
|
var go = Instantiate(prefab, matchSpawnCenter, Quaternion.identity);
|
||||||
|
go.GetComponent<NetworkObject>().SpawnAsPlayerObject(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c5a1205b169c81541ae07e8f32fd3673
|
||||||
@@ -49,8 +49,10 @@ public partial class MeshPainter : MonoBehaviour
|
|||||||
OnSurface
|
OnSurface
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>When false, mouse painting is ignored. Toggled by the GameModeManager.</summary>
|
/// <summary>When false, mouse painting is ignored. Driven by the GameModeManager (true only in
|
||||||
public bool PaintingEnabled { get; set; } = true;
|
/// PaintMode on the local owner). Defaults OFF so a painter that is not (yet) managed by a mode -
|
||||||
|
/// the pre-spawn window, a remote replica, or any binding gap - never paints from local input.</summary>
|
||||||
|
public bool PaintingEnabled { get; set; } = false;
|
||||||
|
|
||||||
[Header("Backend")]
|
[Header("Backend")]
|
||||||
[Tooltip("ON = GPU painting (fast), OFF = CPU painting. Can be toggled live in Play mode.")]
|
[Tooltip("ON = GPU painting (fast), OFF = CPU painting. Can be toggled live in Play mode.")]
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ using UnityEngine.InputSystem;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Dev-only connection harness for local multiplayer testing across the junction-mirror clones:
|
/// Dev-only connection harness for local multiplayer testing across the junction-mirror clones: one
|
||||||
/// pick a role (Hunter/Hider) in the panel, then one instance clicks Host and the others click
|
/// instance clicks Host and the others click Client (loopback 127.0.0.1 via the configured
|
||||||
/// Client (loopback 127.0.0.1 via the configured UnityTransport). The chosen role rides along as the
|
/// UnityTransport). Everyone spawns as the neutral Player prefab into the Lobby; roles (Hunter/Hider)
|
||||||
/// connection-approval payload, so the server spawns that role's prefab variant for the connection.
|
/// are rolled and applied by <see cref="MatchManager"/> when the match starts, not here. Hotkeys:
|
||||||
/// Hotkeys: H = Host, C = Client, J = Server, K = Shutdown. Purely a testing scaffold - replace with
|
/// H = Host, C = Client, J = Server, K = Shutdown. Purely a testing scaffold - replace with real
|
||||||
/// real lobby/menu UI later. Attach to the same GameObject as the NetworkManager.
|
/// lobby/menu UI later. Attach to the same GameObject as the NetworkManager.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[RequireComponent(typeof(NetworkManager))]
|
[RequireComponent(typeof(NetworkManager))]
|
||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
@@ -22,51 +22,9 @@ public class NetworkBootstrap : MonoBehaviour
|
|||||||
[Tooltip("Allow the H/C/J/K keyboard shortcuts.")]
|
[Tooltip("Allow the H/C/J/K keyboard shortcuts.")]
|
||||||
public bool enableHotkeys = true;
|
public bool enableHotkeys = true;
|
||||||
|
|
||||||
[Header("Role prefabs")]
|
|
||||||
[Tooltip("Prefab spawned for a connection that picked Hunter. Must be registered as a network prefab.")]
|
|
||||||
[SerializeField] private GameObject hunterPrefab;
|
|
||||||
|
|
||||||
[Tooltip("Prefab spawned for a connection that picked Hider. Must be registered as a network prefab.")]
|
|
||||||
[SerializeField] private GameObject hiderPrefab;
|
|
||||||
|
|
||||||
[Tooltip("Role this instance connects as. Toggle it in the dev panel before hosting/joining.")]
|
|
||||||
[SerializeField] private PlayerRole selectedRole = PlayerRole.Hider;
|
|
||||||
|
|
||||||
private NetworkManager _net;
|
private NetworkManager _net;
|
||||||
|
|
||||||
private void Awake()
|
private void Awake() => _net = GetComponent<NetworkManager>();
|
||||||
{
|
|
||||||
_net = GetComponent<NetworkManager>();
|
|
||||||
|
|
||||||
// Per-connection prefab selection needs connection approval: the callback maps the role byte
|
|
||||||
// the joiner sent to the matching prefab hash. Enabled here so the scene asset needn't carry it.
|
|
||||||
_net.NetworkConfig.ConnectionApproval = true;
|
|
||||||
_net.ConnectionApprovalCallback = ApprovalCheck;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Stamps the chosen role into the connection payload, then starts the given mode.
|
|
||||||
/// StartHost runs approval on its own client too, so the host's role is read from this same payload.</summary>
|
|
||||||
private void StartAs(System.Func<bool> start)
|
|
||||||
{
|
|
||||||
_net.NetworkConfig.ConnectionData = new[] { (byte)selectedRole };
|
|
||||||
start();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ApprovalCheck(NetworkManager.ConnectionApprovalRequest request,
|
|
||||||
NetworkManager.ConnectionApprovalResponse response)
|
|
||||||
{
|
|
||||||
PlayerRole role = (request.Payload != null && request.Payload.Length > 0)
|
|
||||||
? (PlayerRole)request.Payload[0]
|
|
||||||
: PlayerRole.Hider;
|
|
||||||
|
|
||||||
GameObject prefab = role == PlayerRole.Hunter ? hunterPrefab : hiderPrefab;
|
|
||||||
var netObj = prefab ? prefab.GetComponent<NetworkObject>() : null;
|
|
||||||
|
|
||||||
response.Approved = true;
|
|
||||||
response.CreatePlayerObject = true;
|
|
||||||
// Null prefab/ref falls back to the NetworkManager's default PlayerPrefab.
|
|
||||||
if (netObj) response.PlayerPrefabHash = netObj.PrefabIdHash;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
@@ -76,9 +34,9 @@ public class NetworkBootstrap : MonoBehaviour
|
|||||||
if (kb == null || _net == null) return;
|
if (kb == null || _net == null) return;
|
||||||
if (!_net.IsListening)
|
if (!_net.IsListening)
|
||||||
{
|
{
|
||||||
if (kb.hKey.wasPressedThisFrame) StartAs(_net.StartHost);
|
if (kb.hKey.wasPressedThisFrame) _net.StartHost();
|
||||||
else if (kb.cKey.wasPressedThisFrame) StartAs(_net.StartClient);
|
else if (kb.cKey.wasPressedThisFrame) _net.StartClient();
|
||||||
else if (kb.jKey.wasPressedThisFrame) StartAs(_net.StartServer);
|
else if (kb.jKey.wasPressedThisFrame) _net.StartServer();
|
||||||
}
|
}
|
||||||
else if (kb.kKey.wasPressedThisFrame)
|
else if (kb.kKey.wasPressedThisFrame)
|
||||||
{
|
{
|
||||||
@@ -91,25 +49,18 @@ public class NetworkBootstrap : MonoBehaviour
|
|||||||
{
|
{
|
||||||
if (!showGui || _net == null) return;
|
if (!showGui || _net == null) return;
|
||||||
|
|
||||||
GUILayout.BeginArea(new Rect(10, 10, 220, 200), GUI.skin.box);
|
GUILayout.BeginArea(new Rect(10, 10, 220, 160), GUI.skin.box);
|
||||||
if (!_net.IsListening)
|
if (!_net.IsListening)
|
||||||
{
|
{
|
||||||
GUILayout.Label("Netcode (dev)");
|
GUILayout.Label("Netcode (dev)");
|
||||||
|
if (GUILayout.Button("Host (H)")) _net.StartHost();
|
||||||
GUILayout.BeginHorizontal();
|
if (GUILayout.Button("Client (C)")) _net.StartClient();
|
||||||
GUILayout.Label("Role:", GUILayout.Width(38));
|
if (GUILayout.Button("Server (J)")) _net.StartServer();
|
||||||
if (GUILayout.Toggle(selectedRole == PlayerRole.Hider, "Hider", GUI.skin.button)) selectedRole = PlayerRole.Hider;
|
|
||||||
if (GUILayout.Toggle(selectedRole == PlayerRole.Hunter, "Hunter", GUI.skin.button)) selectedRole = PlayerRole.Hunter;
|
|
||||||
GUILayout.EndHorizontal();
|
|
||||||
|
|
||||||
if (GUILayout.Button("Host (H)")) StartAs(_net.StartHost);
|
|
||||||
if (GUILayout.Button("Client (C)")) StartAs(_net.StartClient);
|
|
||||||
if (GUILayout.Button("Server (J)")) StartAs(_net.StartServer);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string role = _net.IsHost ? "Host" : _net.IsServer ? "Server" : "Client";
|
string role = _net.IsHost ? "Host" : _net.IsServer ? "Server" : "Client";
|
||||||
GUILayout.Label($"Role: {role} ({selectedRole})");
|
GUILayout.Label($"Role: {role}");
|
||||||
GUILayout.Label($"ClientId: {_net.LocalClientId}");
|
GUILayout.Label($"ClientId: {_net.LocalClientId}");
|
||||||
GUILayout.Label($"Clients: {(_net.IsServer ? _net.ConnectedClients.Count : (_net.IsConnectedClient ? 1 : 0))}");
|
GUILayout.Label($"Clients: {(_net.IsServer ? _net.ConnectedClients.Count : (_net.IsConnectedClient ? 1 : 0))}");
|
||||||
if (GUILayout.Button("Shutdown (K)")) _net.Shutdown();
|
if (GUILayout.Button("Shutdown (K)")) _net.Shutdown();
|
||||||
|
|||||||
@@ -26,9 +26,18 @@ public class NetworkPlayerSetup : NetworkBehaviour
|
|||||||
"Hunter on the Hunter prefab); GameModeManager reads it on spawn to build this role's mode set.")]
|
"Hunter on the Hunter prefab); GameModeManager reads it on spawn to build this role's mode set.")]
|
||||||
[SerializeField] private PlayerRole role = PlayerRole.Hider;
|
[SerializeField] private PlayerRole role = PlayerRole.Hider;
|
||||||
|
|
||||||
|
[Tooltip("False = lobby/neutral avatar (the base Player prefab) gets the FULL mode set; true = match " +
|
||||||
|
"avatar (Hunter/Hider variant) gets only its role's modes. Baked per prefab variant, so the " +
|
||||||
|
"mode set follows the spawned avatar with no replicated-phase timing race.")]
|
||||||
|
[SerializeField] private bool scopedModes = false;
|
||||||
|
|
||||||
/// <summary>The side this avatar plays (Hunter/Hider), baked into the prefab variant.</summary>
|
/// <summary>The side this avatar plays (Hunter/Hider), baked into the prefab variant.</summary>
|
||||||
public PlayerRole Role => role;
|
public PlayerRole Role => role;
|
||||||
|
|
||||||
|
/// <summary>True on the match role variants (scope the mode set to <see cref="Role"/>); false on the
|
||||||
|
/// neutral lobby Player prefab (full mode set). Baked per prefab variant.</summary>
|
||||||
|
public bool ScopedModes => scopedModes;
|
||||||
|
|
||||||
public override void OnNetworkSpawn()
|
public override void OnNetworkSpawn()
|
||||||
{
|
{
|
||||||
var controller = GetComponent<PlayerCharacterController>();
|
var controller = GetComponent<PlayerCharacterController>();
|
||||||
|
|||||||
@@ -170,7 +170,10 @@ public partial class PaintHud : MonoBehaviour
|
|||||||
|
|
||||||
private void OnModeChanged(GameMode mode)
|
private void OnModeChanged(GameMode mode)
|
||||||
{
|
{
|
||||||
bool paint = mode is PaintMode;
|
// Require a bound painter too: pre-spawn the manager sits in a player-less Paint mode (no
|
||||||
|
// PlayerControl without an avatar), but there is nothing to paint yet - keep the HUD hidden until
|
||||||
|
// the local avatar spawns and a painter is bound.
|
||||||
|
bool paint = mode is PaintMode && painter;
|
||||||
if (_panel) _panel.SetActive(paint); // toggles the brush panels and the library panel together
|
if (_panel) _panel.SetActive(paint); // toggles the brush panels and the library panel together
|
||||||
if (paint)
|
if (paint)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
using Unity.Netcode;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sits on the Lobby's "Start Match" trigger volume (a BoxCollider with isTrigger on). When the HOST's
|
||||||
|
/// own player walks in, it asks the <see cref="MatchManager"/> to start the match. Server-gated: pure
|
||||||
|
/// clients fire nothing (IsServer is false there), and only the host-owned player object counts, so a
|
||||||
|
/// remote avatar passing through never starts the match. The trigger lives in the additively-loaded
|
||||||
|
/// Lobby and is destroyed when the lobby unloads, so it cannot start a second match.
|
||||||
|
/// </summary>
|
||||||
|
[RequireComponent(typeof(Collider))]
|
||||||
|
[DisallowMultipleComponent]
|
||||||
|
public class StartMatchTrigger : MonoBehaviour
|
||||||
|
{
|
||||||
|
private void OnTriggerEnter(Collider other)
|
||||||
|
{
|
||||||
|
var nm = NetworkManager.Singleton;
|
||||||
|
if (!nm || !nm.IsServer) return; // only the server/host starts the match
|
||||||
|
|
||||||
|
var netObj = other.GetComponentInParent<NetworkObject>();
|
||||||
|
if (!netObj || !netObj.IsPlayerObject) return; // must be a player avatar
|
||||||
|
if (netObj.OwnerClientId != nm.LocalClientId) return; // ...and specifically the host's own
|
||||||
|
|
||||||
|
if (MatchManager.Instance) MatchManager.Instance.StartMatch();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: dbc3790cccc4958458bb38d883b69afb
|
||||||
@@ -6,8 +6,14 @@ EditorBuildSettings:
|
|||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Scenes:
|
m_Scenes:
|
||||||
- enabled: 1
|
- enabled: 1
|
||||||
path: Assets/Scenes/SampleScene.unity
|
path: Assets/Scenes/Main.unity
|
||||||
guid: 99c9720ab356a0642a771bea13969a05
|
guid: 99c9720ab356a0642a771bea13969a05
|
||||||
|
- enabled: 1
|
||||||
|
path: Assets/Scenes/Lobby.unity
|
||||||
|
guid: 3d1c04c698b4f32438a69661b90ff58b
|
||||||
|
- enabled: 1
|
||||||
|
path: Assets/Scenes/Test Map.unity
|
||||||
|
guid: 427f9e7bc57fb6e49a9233fc60022383
|
||||||
m_configObjects:
|
m_configObjects:
|
||||||
com.unity.input.settings.actions: {fileID: -944628639613478452, guid: 052faaac586de48259a63d0c4782560b, type: 3}
|
com.unity.input.settings.actions: {fileID: -944628639613478452, guid: 052faaac586de48259a63d0c4782560b, type: 3}
|
||||||
m_UseUCBPForAssetBundles: 0
|
m_UseUCBPForAssetBundles: 0
|
||||||
Reference in new issue
Block a user