Compare commits

...
9 Commits
Author SHA1 Message Date
moyu 395db1a3f7 立方体的位置同步 2026-09-20 17:47:51 +08:00
moyu 02265e75ca 统一使用新输入系统 2026-09-20 17:09:58 +08:00
moyu 38303b3743 恢复使用new输入系统 2026-09-20 16:26:09 +08:00
moyu f40487feeb 使用old输入系统 2026-09-20 16:21:10 +08:00
moyu d2ec2f6f0e 移动同步 2026-09-20 15:54:34 +08:00
moyu 3298ccdc76 Create AGENT.md 2026-09-20 15:53:26 +08:00
moyu 179c282405 新增FishNet文档 2026-09-20 15:53:11 +08:00
moyu c403145db9 01 2026-09-17 23:14:34 +08:00
moyu 8d2dda5462 简单的玩家预制体和脚本 2026-09-17 22:49:42 +08:00
455 changed files with 17132 additions and 1155 deletions
+1
View File
@@ -0,0 +1 @@
fishnet 文档位于:Docs/FishNet-Documentation-main
+2
View File
@@ -21,7 +21,9 @@ MonoBehaviour:
- {fileID: 201277550, guid: 5b712878ecece354ba4ffb026c0a221c, type: 3} - {fileID: 201277550, guid: 5b712878ecece354ba4ffb026c0a221c, type: 3}
- {fileID: 4512293259955182956, guid: b8017cef39731ba439c70fecc09488e3, type: 3} - {fileID: 4512293259955182956, guid: b8017cef39731ba439c70fecc09488e3, type: 3}
- {fileID: 201277550, guid: 26a567abbe21227428f5c3d309d1d73c, type: 3} - {fileID: 201277550, guid: 26a567abbe21227428f5c3d309d1d73c, type: 3}
- {fileID: -8731164649411638372, guid: 687b16b0a8065d74fa4380e93a8a3d81, type: 3}
- {fileID: 4512293259955182956, guid: 44611030e61220d42ab7c37ba3c0ea92, type: 3} - {fileID: 4512293259955182956, guid: 44611030e61220d42ab7c37ba3c0ea92, type: 3}
- {fileID: 8499328425325690813, guid: 5d76bafdfa1223f40b69ba0a0c4de184, type: 3}
- {fileID: 8192566354860284824, guid: 6331b3542e64a564c81bc39cedf70c8d, type: 3} - {fileID: 8192566354860284824, guid: 6331b3542e64a564c81bc39cedf70c8d, type: 3}
- {fileID: 4512293259955182956, guid: f32d4c19de900e64cb73cedcb8ba6f70, type: 3} - {fileID: 4512293259955182956, guid: f32d4c19de900e64cb73cedcb8ba6f70, type: 3}
- {fileID: 611616139817875448, guid: bf5f023b4017a5e41a9815ec5745df3d, type: 3} - {fileID: 611616139817875448, guid: bf5f023b4017a5e41a9815ec5745df3d, type: 3}
@@ -1,14 +0,0 @@
fileFormatVersion: 2
guid: 246f31a0e00fea74a93125fec6d80da8
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.7.3R
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil.sln
uploadId: 987062
@@ -1,14 +0,0 @@
fileFormatVersion: 2
guid: 1ec83424c5410b04aab06dddca60e7f6
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.7.3R
assetPath: Assets/FishNet/Runtime/Transporting/Transports/Tugboat/LiteNetLib/LiteNetLib.csproj
uploadId: 987062
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f5f544622debdc74b8f5fbee0fb65f47
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Binary file not shown.
@@ -0,0 +1,132 @@
fileFormatVersion: 2
guid: 4057c2837a4b775408606a074d54cf5e
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationMethod: 0
spriteTessellationDetail: -1
spriteGeometrySubdivision: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 4
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
customData:
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spriteCustomMetadata:
entries: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 437148ba0acd7d84ea3f01d9a9472028
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,158 @@
{
"name": "PlayerControls",
"maps": [
{
"name": "Player",
"id": "a1b2c3d4-0000-4000-8000-000000000001",
"actions": [
{
"name": "Move",
"type": "Value",
"id": "a1b2c3d4-0000-4000-8000-000000000002",
"expectedControlType": "Vector2",
"processors": "",
"interactions": "",
"initialStateCheck": true
},
{
"name": "Look",
"type": "Value",
"id": "a1b2c3d4-0000-4000-8000-000000000003",
"expectedControlType": "Vector2",
"processors": "",
"interactions": "",
"initialStateCheck": true
},
{
"name": "Jump",
"type": "Button",
"id": "a1b2c3d4-0000-4000-8000-000000000004",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Sprint",
"type": "Button",
"id": "a1b2c3d4-0000-4000-8000-000000000005",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Attack",
"type": "Button",
"id": "a1b2c3d4-0000-4000-8000-000000000006",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
}
],
"bindings": [
{
"name": "WASD",
"id": "a1b2c3d4-0000-4000-8000-000000000007",
"path": "2DVector",
"interactions": "",
"processors": "",
"groups": "",
"action": "Move",
"isComposite": true,
"isPartOfComposite": false
},
{
"name": "up",
"id": "a1b2c3d4-0000-4000-8000-000000000008",
"path": "<Keyboard>/w",
"interactions": "",
"processors": "",
"groups": "",
"action": "Move",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "down",
"id": "a1b2c3d4-0000-4000-8000-000000000009",
"path": "<Keyboard>/s",
"interactions": "",
"processors": "",
"groups": "",
"action": "Move",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "left",
"id": "a1b2c3d4-0000-4000-8000-00000000000a",
"path": "<Keyboard>/a",
"interactions": "",
"processors": "",
"groups": "",
"action": "Move",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "right",
"id": "a1b2c3d4-0000-4000-8000-00000000000b",
"path": "<Keyboard>/d",
"interactions": "",
"processors": "",
"groups": "",
"action": "Move",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "",
"id": "a1b2c3d4-0000-4000-8000-00000000000c",
"path": "<Mouse>/delta",
"interactions": "",
"processors": "",
"groups": "",
"action": "Look",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "a1b2c3d4-0000-4000-8000-00000000000d",
"path": "<Keyboard>/space",
"interactions": "",
"processors": "",
"groups": "",
"action": "Jump",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "a1b2c3d4-0000-4000-8000-00000000000e",
"path": "<Keyboard>/leftShift",
"interactions": "",
"processors": "",
"groups": "",
"action": "Sprint",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "a1b2c3d4-0000-4000-8000-00000000000f",
"path": "<Mouse>/leftButton",
"interactions": "",
"processors": "",
"groups": "",
"action": "Attack",
"isComposite": false,
"isPartOfComposite": false
}
]
}
],
"controlSchemes": []
}
@@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: 93d11597dae64cc4aa68018ccaa39195
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3}
generateWrapperCode: 0
wrapperCodePath:
wrapperClassName:
wrapperCodeNamespace:
+264
View File
@@ -0,0 +1,264 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &2655148725409191110
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 29487170300297484}
- component: {fileID: 3803348366860609995}
- component: {fileID: 969463025217515519}
- component: {fileID: 6765530772190315426}
- component: {fileID: 8499328425325690813}
- component: {fileID: 8072914292444380081}
- component: {fileID: -809832392475339488}
- component: {fileID: 4615427192473594859}
m_Layer: 0
m_Name: ACube
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &29487170300297484
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2655148725409191110}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -13.66379, y: 2.13, z: 0.56447}
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 &3803348366860609995
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2655148725409191110}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &969463025217515519
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2655148725409191110}
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!65 &6765530772190315426
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2655148725409191110}
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 &8499328425325690813
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2655148725409191110}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 26b716c41e9b56b4baafaf13a523ba2e, type: 3}
m_Name:
m_EditorClassIdentifier: FishNet.Runtime::FishNet.Object.NetworkObject
_localLevelOfDetailCalculationType: 0
_useLevelOfDetail: 0
_useRootLevelOfDetail: 1
NetworkObserver: {fileID: 0}
_enablePrediction: 0
_predictionType: 0
_localReconcileCorrectionType: 2
_graphicalObject: {fileID: 0}
_detachGraphicalObject: 0
_enableStateForwarding: 1
_networkTransform: {fileID: 0}
_ownerInterpolation: 1
_ownerSmoothedProperties: 255
_adaptiveInterpolation: 3
_spectatorSmoothedProperties: 255
_spectatorInterpolation: 2
_enableTeleport: 0
_teleportThreshold: 1
<PrefabId>k__BackingField: 10
<SpawnableCollectionId>k__BackingField: 0
<AssetPathHash>k__BackingField: 17143552955378212519
SceneId: 0
SerializedTransformProperties:
Position: {x: -13.66379, y: 2.13, z: 0.56447}
Rotation: {x: 0, y: 0, z: 0, w: 1}
Scale: {x: 1, y: 1, z: 1}
IsValid: 1
<IsNested>k__BackingField: 0
WasActiveDuringEdit: 0
WasActiveDuringEdit_Set1: 1
<ComponentIndex>k__BackingField: 0
<PredictedSpawn>k__BackingField: {fileID: 0}
<PredictedOwner>k__BackingField: {fileID: 0}
NetworkBehaviours:
- {fileID: 8072914292444380081}
InitializedParentNetworkBehaviour: {fileID: 0}
InitializedNestedNetworkObjects: []
RuntimeParentNetworkBehaviour: {fileID: 0}
RuntimeChildNetworkBehaviours: []
_isNetworked: 1
_isSpawnable: 1
_isGlobal: 0
_initializeOrder: 0
_preventDespawnOnDisconnect: 0
_defaultDespawnType: 0
_initializedTimestamp: -8584117104219334400
--- !u!114 &8072914292444380081
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2655148725409191110}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8a6a39c46bf52104ba8efe3100bce3f7, type: 3}
m_Name:
m_EditorClassIdentifier: FishNet.Runtime::FishNet.Object.EmptyNetworkBehaviour
_componentIndexCache: 0
_addedNetworkObject: {fileID: 8499328425325690813}
_networkObjectCache: {fileID: 8499328425325690813}
--- !u!54 &-809832392475339488
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2655148725409191110}
serializedVersion: 5
m_Mass: 1
m_LinearDamping: 0
m_AngularDamping: 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 &4615427192473594859
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2655148725409191110}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a2836e36774ca1c4bbbee976e17b649c, type: 3}
m_Name:
m_EditorClassIdentifier: FishNet.Runtime::FishNet.Component.Transforming.NetworkTransform
_componentIndexCache: 255
_addedNetworkObject: {fileID: 8499328425325690813}
_networkObjectCache: {fileID: 0}
_componentConfiguration: 2
_synchronizeParent: 0
_packing:
Position: 1
Rotation: 1
Scale: 0
_useScaledTime: 1
_interpolation: 2
_extrapolation: 2
_enableTeleport: 0
_teleportThreshold: 1
_clientAuthoritative: 1
_sendToOwner: 1
_interval: 1
_synchronizePosition: 1
_positionSensitivity: 0.001
_positionSnapping:
X: 0
Y: 0
Z: 0
_synchronizeRotation: 1
_rotationSnapping:
X: 0
Y: 0
Z: 0
_synchronizeScale: 1
_scaleSensitivity: 0.001
_scaleSnapping:
X: 0
Y: 0
Z: 0
+7
View File
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 5d76bafdfa1223f40b69ba0a0c4de184
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+487
View File
@@ -0,0 +1,487 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &6595615933852889331
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1098286384477188469}
- component: {fileID: 5320338213907378187}
- component: {fileID: 3175729328858663569}
- component: {fileID: 5855560935363092846}
m_Layer: 0
m_Name: PlayerCamera
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!4 &1098286384477188469
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6595615933852889331}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0.6, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 4433491345327751435}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &5320338213907378187
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6595615933852889331}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ca68f61e4f5bf6b439395d4aa1b7334a, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::Agame.MouseLook
mouseSensitivity: 0.12
minLookAngle: -80
maxLookAngle: 80
characterBody: {fileID: 4433491345327751435}
--- !u!20 &3175729328858663569
Camera:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6595615933852889331}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
m_Iso: 200
m_ShutterSpeed: 0.005
m_Aperture: 16
m_FocusDistance: 10
m_FocalLength: 50
m_BladeCount: 5
m_Curvature: {x: 2, y: 11}
m_BarrelClipping: 0.25
m_Anamorphism: 0
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 0
orthographic size: 5
m_Depth: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 1
m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!114 &5855560935363092846
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6595615933852889331}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a79441f348de89743a2939f4d699eac1, type: 3}
m_Name:
m_EditorClassIdentifier: Unity.RenderPipelines.Universal.Runtime::UnityEngine.Rendering.Universal.UniversalAdditionalCameraData
m_RenderShadows: 1
m_RequiresDepthTextureOption: 2
m_RequiresOpaqueTextureOption: 2
m_CameraType: 0
m_Cameras: []
m_RendererIndex: -1
m_VolumeLayerMask:
serializedVersion: 2
m_Bits: 1
m_VolumeTrigger: {fileID: 0}
m_VolumeFrameworkUpdateModeOption: 2
m_RenderPostProcessing: 0
m_Antialiasing: 0
m_AntialiasingQuality: 2
m_StopNaN: 0
m_Dithering: 0
m_ClearDepth: 1
m_AllowXRRendering: 1
m_AllowHDROutput: 1
m_UseScreenCoordOverride: 0
m_ScreenSizeOverride: {x: 0, y: 0, z: 0, w: 0}
m_ScreenCoordScaleBias: {x: 0, y: 0, z: 0, w: 0}
m_RequiresDepthTexture: 0
m_RequiresColorTexture: 0
m_TaaSettings:
m_Quality: 3
m_FrameInfluence: 0.1
m_JitterScale: 1
m_MipBias: 0
m_VarianceClampScale: 0.9
m_ContrastAdaptiveSharpening: 0
m_Version: 2
--- !u!1 &7344258574652498121
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4433491345327751435}
- component: {fileID: 1480568808756146700}
- component: {fileID: 4397186652488278148}
- component: {fileID: 7247448510909021193}
- component: {fileID: 3905363232486332009}
- component: {fileID: -8731164649411638372}
- component: {fileID: -1605824257395221361}
- component: {fileID: -1778631990423174556}
- component: {fileID: -1909282985868566644}
- component: {fileID: -2948519365385897836}
- component: {fileID: 6625924108130006384}
m_Layer: 0
m_Name: Player
m_TagString: Player
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4433491345327751435
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7344258574652498121}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1098286384477188469}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &1480568808756146700
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7344258574652498121}
m_Mesh: {fileID: 10208, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &4397186652488278148
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7344258574652498121}
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: 1
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!143 &7247448510909021193
CharacterController:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7344258574652498121}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Height: 2
m_Radius: 0.5
m_SlopeLimit: 45
m_StepOffset: 0.3
m_SkinWidth: 0.08
m_MinMoveDistance: 0.001
m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &3905363232486332009
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7344258574652498121}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b6780c1c0b9d27c46a0bd43f0d2291f6, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::Agame.PlayerController
_componentIndexCache: 0
_addedNetworkObject: {fileID: -8731164649411638372}
_networkObjectCache: {fileID: -8731164649411638372}
moveSpeed: 5
sprintSpeed: 8
gravity: -20
jumpHeight: 1.5
ownerOnlyObjects:
- {fileID: 6595615933852889331}
--- !u!114 &-8731164649411638372
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7344258574652498121}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 26b716c41e9b56b4baafaf13a523ba2e, type: 3}
m_Name:
m_EditorClassIdentifier: FishNet.Runtime::FishNet.Object.NetworkObject
_localLevelOfDetailCalculationType: 0
_useLevelOfDetail: 0
_useRootLevelOfDetail: 1
NetworkObserver: {fileID: 0}
_enablePrediction: 0
_predictionType: 0
_localReconcileCorrectionType: 2
_graphicalObject: {fileID: 0}
_detachGraphicalObject: 0
_enableStateForwarding: 1
_networkTransform: {fileID: 0}
_ownerInterpolation: 1
_ownerSmoothedProperties: 255
_adaptiveInterpolation: 3
_spectatorSmoothedProperties: 255
_spectatorInterpolation: 2
_enableTeleport: 0
_teleportThreshold: 1
<PrefabId>k__BackingField: 8
<SpawnableCollectionId>k__BackingField: 0
<AssetPathHash>k__BackingField: 15157568118727023227
SceneId: 0
SerializedTransformProperties:
Position: {x: 0, y: 1, z: 0}
Rotation: {x: 0, y: 0, z: 0, w: 1}
Scale: {x: 1, y: 1, z: 1}
IsValid: 1
<IsNested>k__BackingField: 0
WasActiveDuringEdit: 0
WasActiveDuringEdit_Set1: 1
<ComponentIndex>k__BackingField: 0
<PredictedSpawn>k__BackingField: {fileID: 0}
<PredictedOwner>k__BackingField: {fileID: 0}
NetworkBehaviours:
- {fileID: 3905363232486332009}
- {fileID: -1605824257395221361}
- {fileID: -1778631990423174556}
- {fileID: -1909282985868566644}
InitializedParentNetworkBehaviour: {fileID: 0}
InitializedNestedNetworkObjects: []
RuntimeParentNetworkBehaviour: {fileID: 0}
RuntimeChildNetworkBehaviours: []
_isNetworked: 1
_isSpawnable: 1
_isGlobal: 0
_initializeOrder: 0
_preventDespawnOnDisconnect: 0
_defaultDespawnType: 0
_initializedTimestamp: -8584117120783244132
--- !u!114 &-1605824257395221361
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7344258574652498121}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8a6a39c46bf52104ba8efe3100bce3f7, type: 3}
m_Name:
m_EditorClassIdentifier: FishNet.Runtime::FishNet.Object.EmptyNetworkBehaviour
_componentIndexCache: 1
_addedNetworkObject: {fileID: -8731164649411638372}
_networkObjectCache: {fileID: -8731164649411638372}
--- !u!114 &-1778631990423174556
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7344258574652498121}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a2836e36774ca1c4bbbee976e17b649c, type: 3}
m_Name:
m_EditorClassIdentifier: FishNet.Runtime::FishNet.Component.Transforming.NetworkTransform
_componentIndexCache: 2
_addedNetworkObject: {fileID: -8731164649411638372}
_networkObjectCache: {fileID: -8731164649411638372}
_componentConfiguration: 0
_synchronizeParent: 0
_packing:
Position: 1
Rotation: 1
Scale: 0
_useScaledTime: 1
_interpolation: 2
_extrapolation: 2
_enableTeleport: 0
_teleportThreshold: 1
_clientAuthoritative: 1
_sendToOwner: 1
_interval: 1
_synchronizePosition: 1
_positionSensitivity: 0.001
_positionSnapping:
X: 0
Y: 0
Z: 0
_synchronizeRotation: 1
_rotationSnapping:
X: 0
Y: 0
Z: 0
_synchronizeScale: 1
_scaleSensitivity: 0.001
_scaleSnapping:
X: 0
Y: 0
Z: 0
--- !u!114 &-1909282985868566644
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7344258574652498121}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 42ed262caf19a9040bf314a318cfecb6, type: 3}
m_Name:
m_EditorClassIdentifier: '::'
_componentIndexCache: 3
_addedNetworkObject: {fileID: -8731164649411638372}
_networkObjectCache: {fileID: -8731164649411638372}
cubePrefab: {fileID: 8499328425325690813, guid: 5d76bafdfa1223f40b69ba0a0c4de184, type: 3}
--- !u!114 &-2948519365385897836
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7344258574652498121}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 62899f850307741f2a39c98a8b639597, type: 3}
m_Name:
m_EditorClassIdentifier: Unity.InputSystem::UnityEngine.InputSystem.PlayerInput
m_Actions: {fileID: -944628639613478452, guid: 93d11597dae64cc4aa68018ccaa39195, type: 3}
m_NotificationBehavior: 0
m_UIInputModule: {fileID: 0}
m_DeviceLostEvent:
m_PersistentCalls:
m_Calls: []
m_DeviceRegainedEvent:
m_PersistentCalls:
m_Calls: []
m_ControlsChangedEvent:
m_PersistentCalls:
m_Calls: []
m_ActionEvents: []
m_NeverAutoSwitchControlSchemes: 0
m_DefaultControlScheme:
m_DefaultActionMap: Player
m_SplitScreenIndex: -1
m_Camera: {fileID: 0}
--- !u!54 &6625924108130006384
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7344258574652498121}
serializedVersion: 5
m_Mass: 1
m_LinearDamping: 0
m_AngularDamping: 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: 1
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
+7
View File
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 687b16b0a8065d74fa4380e93a8a3d81
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large Load Diff
+109
View File
@@ -0,0 +1,109 @@
using UnityEngine;
using UnityEngine.InputSystem;
namespace Agame
{
/// <summary>
/// 第一人称视角控制:鼠标横移带动 body 偏航,纵移带动相机俯仰。
///
/// 输入来自父节点(Player 根)上 PlayerInput 的 Look 动作。
///
/// 网络侧前提(重要):本组件挂在 PlayerCamera 上,而 PlayerCamera 只会被
/// <see cref="PlayerController"/> 为「本地拥有者」启用(见其 ApplyOwnership)。
/// 非拥有者客户端的相机是 disabled 的,因此这里不会执行,天然不需要再判所有权。
///
/// 反过来说:如果日后把 PlayerCamera 改成常驻启用,必须补上所有权判断,
/// 否则每个客户端都会用自己的鼠标去转动别人玩家的视角。
///
/// 关于光标:锁定/释放光标属于「窗口」层面,不是 gameplay 输入,
/// 所以刻意没有做成 Action —— 那样的话玩家一旦切到别的输入上下文
/// (比如打开菜单、禁用了 Player 这张 Map),连恢复光标的按键都收不到了。
/// </summary>
public class MouseLook : MonoBehaviour
{
[Header("Sensitivity")]
[Tooltip("Degrees of rotation per pixel of mouse movement.")]
[SerializeField] private float mouseSensitivity = 0.12f;
[Header("Vertical Clamp")]
[SerializeField] private float minLookAngle = -80f;
[SerializeField] private float maxLookAngle = 80f;
[Header("References")]
[Tooltip("被偏航(Horizontal)的躯体 Transform,通常是玩家根节点。")]
[SerializeField] private Transform characterBody;
private InputAction _lookAction;
private float _xRotation;
private bool _warnedMissingBody;
private void OnEnable()
{
// PlayerInput 挂在父节点(Player 根)上;相机自身可能是 disabled 的,
// 所以要 includeInactive 才能取到。
PlayerInput playerInput = GetComponentInParent<PlayerInput>(includeInactive: true);
_lookAction = PlayerInputNames.Resolve(playerInput, PlayerInputNames.Look, this);
// 跟随本对象的启用状态锁定光标:只有本地拥有者的相机会被启用,
// 所以光标锁定/释放自然就只在拥有者这一侧发生。
LockCursor(true);
}
private void OnDisable()
{
// 对象被禁用(非拥有者,或玩家已下线)时务必释放光标,否则会锁死在别人的机器上。
LockCursor(false);
}
private void Update()
{
UpdateCursorLock();
if (Cursor.lockState != CursorLockMode.Locked)
return;
if (_lookAction == null)
return;
// Look 绑定的是 <Mouse>/delta,读出来的就是这一帧的鼠标位移(单位:像素)。
Vector2 delta = _lookAction.ReadValue<Vector2>();
// 横移:转动躯体
if (characterBody != null)
{
characterBody.Rotate(Vector3.up * (delta.x * mouseSensitivity));
}
else if (!_warnedMissingBody)
{
_warnedMissingBody = true;
Debug.LogWarning(
$"[{nameof(MouseLook)}] 未指定 Character Body,水平视角不会生效。请指向玩家根节点的 Transform。",
this);
}
// 纵移:俯仰相机,并夹在上下限之间防止翻转
_xRotation = Mathf.Clamp(_xRotation - (delta.y * mouseSensitivity), minLookAngle, maxLookAngle);
transform.localRotation = Quaternion.Euler(_xRotation, 0f, 0f);
}
/// <summary>
/// Esc 释放光标,左键重新抓取(方便编辑器里切出去)。
/// </summary>
private void UpdateCursorLock()
{
Keyboard keyboard = Keyboard.current;
if (keyboard != null && keyboard.escapeKey.wasPressedThisFrame)
LockCursor(false);
Mouse mouse = Mouse.current;
if (mouse != null && mouse.leftButton.wasPressedThisFrame && Cursor.lockState != CursorLockMode.Locked)
LockCursor(true);
}
private void LockCursor(bool locked)
{
Cursor.lockState = locked ? CursorLockMode.Locked : CursorLockMode.None;
Cursor.visible = !locked;
}
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: ca68f61e4f5bf6b439395d4aa1b7334a
+175
View File
@@ -0,0 +1,175 @@
using FishNet.Component.Transforming;
using FishNet.Connection;
using FishNet.Object;
using UnityEngine;
using UnityEngine.InputSystem;
namespace Agame
{
/// <summary>
/// 玩家移动控制 —— FishNet 客户端授权 + Input System 的 PlayerInput / Actions 方案。
///
/// 输入链路:
/// Assets/_Game/Input/PlayerControls.inputactions
/// → Player 根节点上的 PlayerInput 组件(仅本地拥有者启用)
/// → 本脚本在 Update 里读取 Move / Sprint / Jump
///
/// 本脚本同时兼任「输入与相机的所有权开关」,见 ApplyOwnership 的注释。
///
/// FishNet 4.7.3 的三条硬约束(与输入方案无关,继续沿用):
/// 1. 必须继承 NetworkBehaviour,否则拿不到 IsOwner 与网络生命周期回调。
/// 2. IsOwner 禁止在 Awake / Start / OnStartServer / OnStartNetwork 中访问 ——
/// FishNet 的 ILPP 会直接报编译错误。
/// 3. 只有拥有者能驱动自己的对象,少了 IsOwner 判断就会去移动别人的玩家。
/// </summary>
[RequireComponent(typeof(CharacterController))]
public class PlayerController : NetworkBehaviour
{
[Header("Movement")]
[SerializeField, Min(0f)] private float moveSpeed = 5f;
[SerializeField, Min(0f)] private float sprintSpeed = 8f;
[Header("Gravity & Jump")]
[Tooltip("负值向下。")]
[SerializeField] private float gravity = -20f;
[SerializeField, Min(0f)] private float jumpHeight = 1.5f;
[Header("Ownership")]
[Tooltip("仅本地拥有者需要启用的对象(玩家相机等)。非拥有者会自动禁用,避免多相机抢占渲染。")]
[SerializeField] private GameObject[] ownerOnlyObjects;
private CharacterController _controller;
private PlayerInput _playerInput;
private InputAction _moveAction;
private InputAction _jumpAction;
private InputAction _sprintAction;
private Vector3 _verticalVelocity;
private void Awake()
{
// Awake 中不得访问 IsOwner,这里只做纯本地缓存。
_controller = GetComponent<CharacterController>();
_playerInput = GetComponent<PlayerInput>();
if (_playerInput == null)
{
Debug.LogError(
$"[{nameof(PlayerController)}] {name} 上找不到 PlayerInput 组件,输入将不可用。" +
$"请在玩家预制体上加 PlayerInput,并把 Actions 指向 {PlayerInputNames.AssetFileName}。",
this);
return;
}
_moveAction = PlayerInputNames.Resolve(_playerInput, PlayerInputNames.Move, this);
_jumpAction = PlayerInputNames.Resolve(_playerInput, PlayerInputNames.Jump, this);
_sprintAction = PlayerInputNames.Resolve(_playerInput, PlayerInputNames.Sprint, this);
}
public override void OnStartClient()
{
base.OnStartClient();
// 用 OnStartClient 而不是 Awake/Start:走到这里说明对象已完成网络链接、
// 所有权已分配,此时 IsOwner 才是可信的。
ApplyOwnership();
WarnIfTransformNotSynchronized();
}
public override void OnOwnershipClient(NetworkConnection prevOwner)
{
base.OnOwnershipClient(prevOwner);
// 所有权可能中途变更(例如将来的主机迁移),输入与相机要跟着切换。
ApplyOwnership();
}
private void Update()
{
// 只驱动本地拥有者。
if (!IsOwner)
return;
Vector2 moveInput = _moveAction != null ? _moveAction.ReadValue<Vector2>() : Vector2.zero;
Vector3 moveDirection = BuildMoveDirection(moveInput);
bool isSprinting = _sprintAction != null && _sprintAction.IsPressed();
float speed = isSprinting ? sprintSpeed : moveSpeed;
_controller.Move(moveDirection * (speed * Time.deltaTime));
bool jumpPressed = _jumpAction != null && _jumpAction.WasPressedThisFrame();
UpdateJumpAndGravity(jumpPressed);
}
/// <summary>
/// 把 Move 的二维输入转换为相对于角色自身朝向的三维方向
/// (body 的偏航由 MouseLook 负责)。斜向输入做归一化,避免对角线移动比正向更快。
/// </summary>
private Vector3 BuildMoveDirection(Vector2 moveInput)
{
Vector3 direction = transform.right * moveInput.x + transform.forward * moveInput.y;
return Vector3.ClampMagnitude(direction, 1f);
}
private void UpdateJumpAndGravity(bool jumpPressed)
{
bool isGrounded = _controller.isGrounded;
// 贴地时保留一点向下的力,防止 isGrounded 在斜坡/台阶上反复抖动。
if (isGrounded && _verticalVelocity.y < 0f)
_verticalVelocity.y = -2f;
if (isGrounded && jumpPressed)
{
// 由目标跳跃高度反推初速度:v = sqrt(2 * g * h)
_verticalVelocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
}
_verticalVelocity.y += gravity * Time.deltaTime;
_controller.Move(_verticalVelocity * Time.deltaTime);
}
/// <summary>
/// 按所有权统一开关「只属于本地玩家」的东西:PlayerInput 与玩家相机。
///
/// 集中放在这里的原因:这两样都是「一个客户端只该有一份生效」。
/// 散到各脚本里各自 enable 容易漏,而且会出现顺序问题 ——
/// PlayerCamera 上的 MouseLook 在 OnEnable 里就要读 Look 动作,
/// 所以必须先开 PlayerInput、再启用相机,否则第一帧读不到值。
/// </summary>
private void ApplyOwnership()
{
if (_playerInput != null)
_playerInput.enabled = IsOwner;
if (ownerOnlyObjects == null)
return;
foreach (GameObject target in ownerOnlyObjects)
{
if (target != null)
target.SetActive(IsOwner);
}
}
/// <summary>
/// 缺少 NetworkTransform 时位置不会同步,但画面上"自己能走",极易误判成逻辑没问题。
/// 这里主动报一次,省掉对着两个人不同步干瞪眼的时间。
/// </summary>
private void WarnIfTransformNotSynchronized()
{
if (!IsOwner)
return;
if (GetComponent<NetworkTransform>() == null)
{
Debug.LogWarning(
$"[{nameof(PlayerController)}] {name} 上没有 NetworkTransform,位置不会同步到其他客户端。" +
"请在 Player 预制体上加 NetworkTransform,并开启 Client Authoritative 与 Synchronize Position。",
this);
}
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b6780c1c0b9d27c46a0bd43f0d2291f6
+54
View File
@@ -0,0 +1,54 @@
using FishNet.Object;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Serialization;
namespace Agame
{
/// <summary>
/// 按攻击键在当前位置生成一个方块,生成动作经 ServerRpc 在服务端执行。
///
/// 输入来自 Player 根节点上 PlayerInput 的 Attack 动作 —— 与 <see cref="PlayerController"/>
/// 共用同一个 PlayerInput(因此 PlayerInput 的启用/禁用也统一由 PlayerController 按所有权管理,
/// 这里只读动作,不再自己 enable 组件)。
/// </summary>
public class PlayerCubeCreator : NetworkBehaviour
{
[Tooltip("要生成的方块预制体。必须已登记进 FishNet 的可生成预制体列表(DefaultPrefabObjects)。")]
[FormerlySerializedAs("CubePrefab")]
[SerializeField] private NetworkObject cubePrefab;
private InputAction _attackAction;
private void Awake()
{
// Awake 中不得访问 IsOwner,这里只做纯本地缓存。
_attackAction = PlayerInputNames.Resolve(GetComponent<PlayerInput>(), PlayerInputNames.Attack, this);
}
private void Update()
{
// 只让拥有者发起攻击,否则每个客户端都会去指挥别人的玩家造方块。
if (!IsOwner)
return;
if (_attackAction != null && _attackAction.WasPressedThisFrame())
SpawnCube();
}
[ServerRpc]
private void SpawnCube()
{
if (cubePrefab == null)
{
Debug.LogError(
$"[{nameof(PlayerCubeCreator)}] {name} 的 Cube Prefab 没有指定,无法生成方块。",
this);
return;
}
NetworkObject obj = Instantiate(cubePrefab, transform.position, Quaternion.identity);
Spawn(obj); // NetworkBehaviour 对 ServerManager.Spawn 的快捷封装
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 42ed262caf19a9040bf314a318cfecb6
+70
View File
@@ -0,0 +1,70 @@
using UnityEngine;
using UnityEngine.InputSystem;
namespace Agame
{
/// <summary>
/// 输入资产 Assets/_Game/Input/PlayerControls.inputactions 的名称与取值入口。
///
/// 把 Action 名集中在这里,是为了避免 "Move"/"Look"/"Attack" 这类字符串散落在三个脚本里 ——
/// 将来在输入资产里改名,只需要动这一处。
///
/// 约定:三个玩家脚本一律从 PlayerInput 实例上取 Action,而不是各自序列化一个资产引用。
/// 因为 PlayerInput 可能为每个玩家实例化一份 Actions 副本,从实例上取才能拿到正确的那一份。
/// </summary>
public static class PlayerInputNames
{
/// <summary>输入资产的文件名,仅用于错误提示。</summary>
public const string AssetFileName = "PlayerControls.inputactions";
/// <summary>Action Map 名称,需与输入资产中的 Map 一致。</summary>
public const string ActionMap = "Player";
public const string Move = "Move";
public const string Look = "Look";
public const string Jump = "Jump";
public const string Sprint = "Sprint";
public const string Attack = "Attack";
/// <summary>
/// 从 PlayerInput 上解析指定 Action,解析失败时返回 null 并给出明确的错误信息。
/// 这里刻意用 LogError 而不是直接抛 NullReferenceException ——
/// "输入没反应但又不报错"是这类问题里最难排查的一种,必须留下痕迹。
/// </summary>
public static InputAction Resolve(PlayerInput playerInput, string actionName, Object context)
{
string ownerName = context != null ? context.name : "(未知对象)";
if (playerInput == null)
{
Debug.LogError(
$"[{nameof(PlayerInputNames)}] {ownerName} 上找不到 PlayerInput 组件,无法读取输入。" +
$"请在玩家预制体上加 PlayerInput 组件,并把 Actions 指向 {AssetFileName}。",
context);
return null;
}
InputActionAsset asset = playerInput.actions;
if (asset == null)
{
Debug.LogError(
$"[{nameof(PlayerInputNames)}] {ownerName} 的 PlayerInput 没有指定 Actions 资产," +
$"请把 {AssetFileName} 拖进 PlayerInput 的 Actions 槽。",
context);
return null;
}
InputAction action = asset.FindAction(actionName, throwIfNotFound: false);
if (action == null)
{
Debug.LogError(
$"[{nameof(PlayerInputNames)}] {AssetFileName} 里找不到名为 \"{actionName}\" 的动作," +
"请确认 Map 与 Action 名和脚本里的一致。",
context);
return null;
}
return action;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 379ed2c2823ca764982411eec577adce
File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 43 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 114 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 70 KiB

Some files were not shown because too many files have changed in this diff Show More