mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
feat(Examples): Added PlayerControllerKRB
- Uses Kinematic Rigidbody instead of Character Controller - Prefabs added to PlayerTest example
This commit is contained in:
parent
9ffa5523ca
commit
fbab75dfc8
367
Assets/Mirror/Examples/PlayerTest/PlayerKRBReliable.prefab
Normal file
367
Assets/Mirror/Examples/PlayerTest/PlayerKRBReliable.prefab
Normal file
@ -0,0 +1,367 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &3564599214188516024
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 5048467161036537608}
|
||||
- component: {fileID: 7612349963074522185}
|
||||
- component: {fileID: 3334477149274362705}
|
||||
m_Layer: 0
|
||||
m_Name: Visor
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &5048467161036537608
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3564599214188516024}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0.39999998, z: 0.5}
|
||||
m_LocalScale: {x: 0.5, y: 0.1, z: 0.2}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 4320229852458648655}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!33 &7612349963074522185
|
||||
MeshFilter:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3564599214188516024}
|
||||
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!23 &3334477149274362705
|
||||
MeshRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3564599214188516024}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 1
|
||||
m_ReceiveShadows: 1
|
||||
m_DynamicOccludee: 1
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 2
|
||||
m_RenderingLayerMask: 4294967295
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
|
||||
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: 0
|
||||
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
|
||||
--- !u!1 &6908139674379992817
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 4320229852458648655}
|
||||
- component: {fileID: 7269450925790386019}
|
||||
- component: {fileID: 1803642612145923671}
|
||||
m_Layer: 0
|
||||
m_Name: Capsule
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &4320229852458648655
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6908139674379992817}
|
||||
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_Children:
|
||||
- {fileID: 5048467161036537608}
|
||||
m_Father: {fileID: 5650773562400175449}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!33 &7269450925790386019
|
||||
MeshFilter:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6908139674379992817}
|
||||
m_Mesh: {fileID: 10208, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!23 &1803642612145923671
|
||||
MeshRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6908139674379992817}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 1
|
||||
m_ReceiveShadows: 1
|
||||
m_DynamicOccludee: 1
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 2
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 2100000, guid: 792117fe9a386a8489e8010bec746339, 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: 0
|
||||
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
|
||||
--- !u!1 &7197623925735895267
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 5650773562400175449}
|
||||
- component: {fileID: 3870420104013059684}
|
||||
- component: {fileID: 4272311354144086857}
|
||||
- component: {fileID: 6897869481335892641}
|
||||
- component: {fileID: 6441507759764929271}
|
||||
- component: {fileID: 706935836448234532}
|
||||
- component: {fileID: 4932227711505240966}
|
||||
- component: {fileID: 8229469515647906458}
|
||||
m_Layer: 0
|
||||
m_Name: PlayerKRBReliable
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &5650773562400175449
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7197623925735895267}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 1.1, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children:
|
||||
- {fileID: 4320229852458648655}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!136 &3870420104013059684
|
||||
CapsuleCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7197623925735895267}
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
m_Radius: 0.5
|
||||
m_Height: 2
|
||||
m_Direction: 1
|
||||
m_Center: {x: 0, y: 0, z: 0}
|
||||
--- !u!54 &4272311354144086857
|
||||
Rigidbody:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7197623925735895267}
|
||||
serializedVersion: 2
|
||||
m_Mass: 1
|
||||
m_Drag: 0
|
||||
m_AngularDrag: 0.05
|
||||
m_UseGravity: 1
|
||||
m_IsKinematic: 1
|
||||
m_Interpolate: 1
|
||||
m_Constraints: 112
|
||||
m_CollisionDetection: 3
|
||||
--- !u!114 &6897869481335892641
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7197623925735895267}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 9b91ecbcc199f4492b9a91e820070131, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
sceneId: 0
|
||||
_assetId: 3568813205
|
||||
serverOnly: 0
|
||||
visibility: 0
|
||||
hasSpawned: 0
|
||||
--- !u!114 &6441507759764929271
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7197623925735895267}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: a91a718a70d01b347b75cb768a6f1a92, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
syncDirection: 0
|
||||
syncMode: 0
|
||||
syncInterval: 0
|
||||
color:
|
||||
serializedVersion: 2
|
||||
rgba: 4278190080
|
||||
--- !u!114 &706935836448234532
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7197623925735895267}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 71ac1e35462ffad469e77d1c2fe6c9f3, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
syncDirection: 0
|
||||
syncMode: 0
|
||||
syncInterval: 0
|
||||
offset: {x: 0, y: 4, z: -12}
|
||||
rotation: {x: 15, y: 0, z: 0}
|
||||
--- !u!114 &4932227711505240966
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7197623925735895267}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 8ff3ba0becae47b8b9381191598957c8, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
syncDirection: 1
|
||||
syncMode: 0
|
||||
syncInterval: 0
|
||||
target: {fileID: 5650773562400175449}
|
||||
syncPosition: 1
|
||||
syncRotation: 1
|
||||
syncScale: 0
|
||||
onlySyncOnChange: 1
|
||||
compressRotation: 1
|
||||
interpolatePosition: 1
|
||||
interpolateRotation: 1
|
||||
interpolateScale: 1
|
||||
coordinateSpace: 0
|
||||
timelineOffset: 0
|
||||
showGizmos: 0
|
||||
showOverlay: 0
|
||||
overlayColor: {r: 0, g: 0, b: 0, a: 0.5}
|
||||
onlySyncOnChangeCorrectionMultiplier: 2
|
||||
rotationSensitivity: 0.01
|
||||
positionPrecision: 0.01
|
||||
scalePrecision: 0.01
|
||||
--- !u!114 &8229469515647906458
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7197623925735895267}
|
||||
m_Enabled: 0
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 0336d1bd689de45418c08c76ae66e503, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
syncDirection: 0
|
||||
syncMode: 0
|
||||
syncInterval: 0
|
||||
rigidBody: {fileID: 4272311354144086857}
|
||||
capsuleCollider: {fileID: 3870420104013059684}
|
||||
ControllerUIPrefab: {fileID: 1328287033780775043, guid: 5caaf0d5754a64f4080f0c8b55c0b03d,
|
||||
type: 3}
|
||||
moveKeys:
|
||||
Forward: 119
|
||||
Back: 115
|
||||
StrafeLeft: 97
|
||||
StrafeRight: 100
|
||||
TurnLeft: 113
|
||||
TurnRight: 101
|
||||
Jump: 32
|
||||
optionsKeys:
|
||||
MouseSteer: 109
|
||||
AutoRun: 114
|
||||
ToggleUI: 117
|
||||
controlOptions: 4
|
||||
maxMoveSpeed: 8
|
||||
inputSensitivity: 2
|
||||
inputGravity: 2
|
||||
maxTurnSpeed: 100
|
||||
turnAcceleration: 3
|
||||
initialJumpSpeed: 2.5
|
||||
maxJumpSpeed: 3.5
|
||||
jumpAcceleration: 4
|
||||
runtimeData:
|
||||
_horizontal: 0
|
||||
_vertical: 0
|
||||
_turnSpeed: 0
|
||||
_jumpSpeed: 0
|
||||
_animVelocity: 0
|
||||
_animRotation: 0
|
||||
_mouseInputX: 0
|
||||
_mouseSensitivity: 0
|
||||
_groundState: 0
|
||||
_direction: {x: 0, y: 0, z: 0}
|
||||
_velocity: {x: 0, y: 0, z: 0}
|
||||
_controllerUI: {fileID: 0}
|
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 51b55303800297f4ba210567adf65d62
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
367
Assets/Mirror/Examples/PlayerTest/PlayerKRBUnreliable.prefab
Normal file
367
Assets/Mirror/Examples/PlayerTest/PlayerKRBUnreliable.prefab
Normal file
@ -0,0 +1,367 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &2414815785185615771
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 6265883749291389483}
|
||||
- component: {fileID: 8745807705742672234}
|
||||
- component: {fileID: 4520865791365521010}
|
||||
m_Layer: 0
|
||||
m_Name: Visor
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &6265883749291389483
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2414815785185615771}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0.39999998, z: 0.5}
|
||||
m_LocalScale: {x: 0.5, y: 0.1, z: 0.2}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 3102887894851733868}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!33 &8745807705742672234
|
||||
MeshFilter:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2414815785185615771}
|
||||
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!23 &4520865791365521010
|
||||
MeshRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2414815785185615771}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 1
|
||||
m_ReceiveShadows: 1
|
||||
m_DynamicOccludee: 1
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 2
|
||||
m_RenderingLayerMask: 4294967295
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
|
||||
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: 0
|
||||
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
|
||||
--- !u!1 &5703107844171822034
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 3102887894851733868}
|
||||
- component: {fileID: 8365824619968961088}
|
||||
- component: {fileID: 719719793260653428}
|
||||
m_Layer: 0
|
||||
m_Name: Capsule
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &3102887894851733868
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 5703107844171822034}
|
||||
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_Children:
|
||||
- {fileID: 6265883749291389483}
|
||||
m_Father: {fileID: 6814142693731383418}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!33 &8365824619968961088
|
||||
MeshFilter:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 5703107844171822034}
|
||||
m_Mesh: {fileID: 10208, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!23 &719719793260653428
|
||||
MeshRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 5703107844171822034}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 1
|
||||
m_ReceiveShadows: 1
|
||||
m_DynamicOccludee: 1
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 2
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 2100000, guid: 792117fe9a386a8489e8010bec746339, 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: 0
|
||||
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
|
||||
--- !u!1 &8293447860930641344
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 6814142693731383418}
|
||||
- component: {fileID: 2687902018279037767}
|
||||
- component: {fileID: 3148414963753227882}
|
||||
- component: {fileID: 5710847519792162690}
|
||||
- component: {fileID: 5305226192869963732}
|
||||
- component: {fileID: 1816266031544717575}
|
||||
- component: {fileID: 1100861297868964075}
|
||||
- component: {fileID: 3894195534993113074}
|
||||
m_Layer: 0
|
||||
m_Name: PlayerKRBUnreliable
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &6814142693731383418
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8293447860930641344}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 1.1, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children:
|
||||
- {fileID: 3102887894851733868}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!136 &2687902018279037767
|
||||
CapsuleCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8293447860930641344}
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
m_Radius: 0.5
|
||||
m_Height: 2
|
||||
m_Direction: 1
|
||||
m_Center: {x: 0, y: 0, z: 0}
|
||||
--- !u!54 &3148414963753227882
|
||||
Rigidbody:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8293447860930641344}
|
||||
serializedVersion: 2
|
||||
m_Mass: 1
|
||||
m_Drag: 0
|
||||
m_AngularDrag: 0.05
|
||||
m_UseGravity: 1
|
||||
m_IsKinematic: 1
|
||||
m_Interpolate: 1
|
||||
m_Constraints: 112
|
||||
m_CollisionDetection: 3
|
||||
--- !u!114 &5710847519792162690
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8293447860930641344}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 9b91ecbcc199f4492b9a91e820070131, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
sceneId: 0
|
||||
_assetId: 1425781377
|
||||
serverOnly: 0
|
||||
visibility: 0
|
||||
hasSpawned: 0
|
||||
--- !u!114 &5305226192869963732
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8293447860930641344}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: a91a718a70d01b347b75cb768a6f1a92, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
syncDirection: 0
|
||||
syncMode: 0
|
||||
syncInterval: 0
|
||||
color:
|
||||
serializedVersion: 2
|
||||
rgba: 4278190080
|
||||
--- !u!114 &1816266031544717575
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8293447860930641344}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 71ac1e35462ffad469e77d1c2fe6c9f3, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
syncDirection: 0
|
||||
syncMode: 0
|
||||
syncInterval: 0
|
||||
offset: {x: 0, y: 4, z: -12}
|
||||
rotation: {x: 15, y: 0, z: 0}
|
||||
--- !u!114 &1100861297868964075
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8293447860930641344}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: a553cb17010b2403e8523b558bffbc14, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
syncDirection: 1
|
||||
syncMode: 0
|
||||
syncInterval: 0
|
||||
target: {fileID: 6814142693731383418}
|
||||
syncPosition: 1
|
||||
syncRotation: 1
|
||||
syncScale: 0
|
||||
onlySyncOnChange: 1
|
||||
compressRotation: 1
|
||||
interpolatePosition: 1
|
||||
interpolateRotation: 1
|
||||
interpolateScale: 1
|
||||
coordinateSpace: 0
|
||||
timelineOffset: 0
|
||||
showGizmos: 0
|
||||
showOverlay: 0
|
||||
overlayColor: {r: 0, g: 0, b: 0, a: 0.5}
|
||||
bufferResetMultiplier: 3
|
||||
positionSensitivity: 0.01
|
||||
rotationSensitivity: 0.01
|
||||
scaleSensitivity: 0.01
|
||||
--- !u!114 &3894195534993113074
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8293447860930641344}
|
||||
m_Enabled: 0
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 60cbbdae6551c7b4395e1bd09e2ff3ea, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
syncDirection: 0
|
||||
syncMode: 0
|
||||
syncInterval: 0
|
||||
rigidBody: {fileID: 3148414963753227882}
|
||||
capsuleCollider: {fileID: 2687902018279037767}
|
||||
ControllerUIPrefab: {fileID: 1328287033780775043, guid: 5caaf0d5754a64f4080f0c8b55c0b03d,
|
||||
type: 3}
|
||||
moveKeys:
|
||||
Forward: 119
|
||||
Back: 115
|
||||
StrafeLeft: 97
|
||||
StrafeRight: 100
|
||||
TurnLeft: 113
|
||||
TurnRight: 101
|
||||
Jump: 32
|
||||
optionsKeys:
|
||||
MouseSteer: 109
|
||||
AutoRun: 114
|
||||
ToggleUI: 117
|
||||
controlOptions: 4
|
||||
maxMoveSpeed: 8
|
||||
inputSensitivity: 2
|
||||
inputGravity: 2
|
||||
maxTurnSpeed: 100
|
||||
turnAcceleration: 3
|
||||
initialJumpSpeed: 2.5
|
||||
maxJumpSpeed: 3.5
|
||||
jumpAcceleration: 4
|
||||
runtimeData:
|
||||
_horizontal: 0
|
||||
_vertical: 0
|
||||
_turnSpeed: 0
|
||||
_jumpSpeed: 0
|
||||
_animVelocity: 0
|
||||
_animRotation: 0
|
||||
_mouseInputX: 0
|
||||
_mouseSensitivity: 0
|
||||
_groundState: 0
|
||||
_direction: {x: 0, y: 0, z: 0}
|
||||
_velocity: {x: 0, y: 0, z: 0}
|
||||
_controllerUI: {fileID: 0}
|
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6cd3cc8651287ef4a950692d79f015f3
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 42188a14ef528ec489da28afb66db6fa
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,493 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace Mirror.Examples.Common.Controllers.Player
|
||||
{
|
||||
[AddComponentMenu("")]
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
[RequireComponent(typeof(CapsuleCollider))]
|
||||
[RequireComponent(typeof(NetworkIdentity))]
|
||||
[DisallowMultipleComponent]
|
||||
public class PlayerControllerKRBBase : NetworkBehaviour
|
||||
{
|
||||
const float BASE_DPI = 96f;
|
||||
|
||||
public enum GroundState : byte { Grounded, Jumping, Falling }
|
||||
|
||||
[Serializable]
|
||||
public struct MoveKeys
|
||||
{
|
||||
public KeyCode Forward;
|
||||
public KeyCode Back;
|
||||
public KeyCode StrafeLeft;
|
||||
public KeyCode StrafeRight;
|
||||
public KeyCode TurnLeft;
|
||||
public KeyCode TurnRight;
|
||||
public KeyCode Jump;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct OptionsKeys
|
||||
{
|
||||
public KeyCode MouseSteer;
|
||||
public KeyCode AutoRun;
|
||||
public KeyCode ToggleUI;
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum ControlOptions : byte
|
||||
{
|
||||
None,
|
||||
MouseSteer = 1 << 0,
|
||||
AutoRun = 1 << 1,
|
||||
ShowUI = 1 << 2
|
||||
}
|
||||
|
||||
[Header("Avatar Components")]
|
||||
public Rigidbody rigidBody;
|
||||
public CapsuleCollider capsuleCollider;
|
||||
|
||||
[Header("User Interface")]
|
||||
public GameObject ControllerUIPrefab;
|
||||
|
||||
[Header("Configuration")]
|
||||
[SerializeField]
|
||||
public MoveKeys moveKeys = new MoveKeys
|
||||
{
|
||||
Forward = KeyCode.W,
|
||||
Back = KeyCode.S,
|
||||
StrafeLeft = KeyCode.A,
|
||||
StrafeRight = KeyCode.D,
|
||||
TurnLeft = KeyCode.Q,
|
||||
TurnRight = KeyCode.E,
|
||||
Jump = KeyCode.Space,
|
||||
};
|
||||
|
||||
[SerializeField]
|
||||
public OptionsKeys optionsKeys = new OptionsKeys
|
||||
{
|
||||
MouseSteer = KeyCode.M,
|
||||
AutoRun = KeyCode.R,
|
||||
ToggleUI = KeyCode.U
|
||||
};
|
||||
|
||||
[Space(5)]
|
||||
public ControlOptions controlOptions = ControlOptions.ShowUI;
|
||||
|
||||
[Header("Movement")]
|
||||
[Range(0, 20)]
|
||||
[FormerlySerializedAs("moveSpeedMultiplier")]
|
||||
[Tooltip("Speed in meters per second")]
|
||||
public float maxMoveSpeed = 8f;
|
||||
|
||||
// Replacement for Sensitvity from Input Settings.
|
||||
[Range(0, 10f)]
|
||||
[Tooltip("Sensitivity factors into accelleration")]
|
||||
public float inputSensitivity = 2f;
|
||||
|
||||
// Replacement for Gravity from Input Settings.
|
||||
[Range(0, 10f)]
|
||||
[Tooltip("Gravity factors into decelleration")]
|
||||
public float inputGravity = 2f;
|
||||
|
||||
[Header("Turning")]
|
||||
[Range(0, 300f)]
|
||||
[Tooltip("Max Rotation in degrees per second")]
|
||||
public float maxTurnSpeed = 100f;
|
||||
[Range(0, 10f)]
|
||||
[FormerlySerializedAs("turnDelta")]
|
||||
[Tooltip("Rotation acceleration in degrees per second squared")]
|
||||
public float turnAcceleration = 3f;
|
||||
|
||||
[Header("Jumping")]
|
||||
[Range(0, 10f)]
|
||||
[Tooltip("Initial jump speed in meters per second")]
|
||||
public float initialJumpSpeed = 2.5f;
|
||||
[Range(0, 10f)]
|
||||
[Tooltip("Maximum jump speed in meters per second")]
|
||||
public float maxJumpSpeed = 3.5f;
|
||||
[Range(0, 10f)]
|
||||
[FormerlySerializedAs("jumpDelta")]
|
||||
[Tooltip("Jump acceleration in meters per second squared")]
|
||||
public float jumpAcceleration = 4f;
|
||||
|
||||
// Runtime data in a struct so it can be folded up in inspector
|
||||
[Serializable]
|
||||
public struct RuntimeData
|
||||
{
|
||||
[ReadOnly, SerializeField, Range(-1f, 1f)] float _horizontal;
|
||||
[ReadOnly, SerializeField, Range(-1f, 1f)] float _vertical;
|
||||
[ReadOnly, SerializeField, Range(-300f, 300f)] float _turnSpeed;
|
||||
[ReadOnly, SerializeField, Range(-10f, 10f)] float _jumpSpeed;
|
||||
[ReadOnly, SerializeField, Range(-1.5f, 1.5f)] float _animVelocity;
|
||||
[ReadOnly, SerializeField, Range(-1.5f, 1.5f)] float _animRotation;
|
||||
[ReadOnly, SerializeField, Range(-1f, 1f)] float _mouseInputX;
|
||||
[ReadOnly, SerializeField, Range(0, 30f)] float _mouseSensitivity;
|
||||
[ReadOnly, SerializeField] GroundState _groundState;
|
||||
[ReadOnly, SerializeField] Vector3 _direction;
|
||||
[ReadOnly, SerializeField] Vector3Int _velocity;
|
||||
[ReadOnly, SerializeField] GameObject _controllerUI;
|
||||
|
||||
#region Properties
|
||||
|
||||
public float horizontal
|
||||
{
|
||||
get => _horizontal;
|
||||
internal set => _horizontal = value;
|
||||
}
|
||||
|
||||
public float vertical
|
||||
{
|
||||
get => _vertical;
|
||||
internal set => _vertical = value;
|
||||
}
|
||||
|
||||
public float turnSpeed
|
||||
{
|
||||
get => _turnSpeed;
|
||||
internal set => _turnSpeed = value;
|
||||
}
|
||||
|
||||
public float jumpSpeed
|
||||
{
|
||||
get => _jumpSpeed;
|
||||
internal set => _jumpSpeed = value;
|
||||
}
|
||||
|
||||
public float animVelocity
|
||||
{
|
||||
get => _animVelocity;
|
||||
internal set => _animVelocity = value;
|
||||
}
|
||||
|
||||
public float animRotation
|
||||
{
|
||||
get => _animRotation;
|
||||
internal set => _animRotation = value;
|
||||
}
|
||||
|
||||
public float mouseInputX
|
||||
{
|
||||
get => _mouseInputX;
|
||||
internal set => _mouseInputX = value;
|
||||
}
|
||||
|
||||
public float mouseSensitivity
|
||||
{
|
||||
get => _mouseSensitivity;
|
||||
internal set => _mouseSensitivity = value;
|
||||
}
|
||||
|
||||
public GroundState groundState
|
||||
{
|
||||
get => _groundState;
|
||||
internal set => _groundState = value;
|
||||
}
|
||||
|
||||
public Vector3 direction
|
||||
{
|
||||
get => _direction;
|
||||
internal set => _direction = value;
|
||||
}
|
||||
|
||||
public Vector3Int velocity
|
||||
{
|
||||
get => _velocity;
|
||||
internal set => _velocity = value;
|
||||
}
|
||||
|
||||
public GameObject controllerUI
|
||||
{
|
||||
get => _controllerUI;
|
||||
internal set => _controllerUI = value;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Header("Diagnostics")]
|
||||
public RuntimeData runtimeData;
|
||||
|
||||
#region Network Setup
|
||||
|
||||
protected override void OnValidate()
|
||||
{
|
||||
// Skip if Editor is in Play mode
|
||||
if (Application.isPlaying) return;
|
||||
|
||||
base.OnValidate();
|
||||
Reset();
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
if (rigidBody == null)
|
||||
rigidBody = GetComponent<Rigidbody>();
|
||||
if (capsuleCollider == null)
|
||||
capsuleCollider = GetComponent<CapsuleCollider>();
|
||||
|
||||
// Configure Rigidbody
|
||||
rigidBody.useGravity = true;
|
||||
rigidBody.interpolation = RigidbodyInterpolation.Interpolate;
|
||||
rigidBody.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative;
|
||||
rigidBody.isKinematic = true;
|
||||
|
||||
// Freeze rotation on X and Z axes, but allow rotation on Y axis
|
||||
rigidBody.constraints = RigidbodyConstraints.FreezeRotation;
|
||||
|
||||
GetComponent<Rigidbody>().isKinematic = true;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
// For convenience in the examples, we use the GUID of the PlayerControllerUI
|
||||
// to find the correct prefab in the Mirror/Examples/_Common/Controllers folder.
|
||||
// This avoids conflicts with user-created prefabs that may have the same name
|
||||
// and avoids polluting the user's project with Resources.
|
||||
// This is not recommended for production code...use Resources.Load or AssetBundles instead.
|
||||
if (ControllerUIPrefab == null)
|
||||
{
|
||||
string path = UnityEditor.AssetDatabase.GUIDToAssetPath("5caaf0d5754a64f4080f0c8b55c0b03d");
|
||||
ControllerUIPrefab = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(path);
|
||||
}
|
||||
#endif
|
||||
|
||||
this.enabled = false;
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
runtimeData.horizontal = 0f;
|
||||
runtimeData.vertical = 0f;
|
||||
runtimeData.turnSpeed = 0f;
|
||||
}
|
||||
|
||||
public override void OnStartAuthority()
|
||||
{
|
||||
// Calculate DPI-aware sensitivity
|
||||
float dpiScale = (Screen.dpi > 0) ? (Screen.dpi / BASE_DPI) : 1f;
|
||||
runtimeData.mouseSensitivity = turnAcceleration * dpiScale;
|
||||
|
||||
SetCursor(controlOptions.HasFlag(ControlOptions.MouseSteer));
|
||||
|
||||
rigidBody.isKinematic = false;
|
||||
rigidBody.collisionDetectionMode = CollisionDetectionMode.Continuous;
|
||||
|
||||
this.enabled = true;
|
||||
}
|
||||
|
||||
public override void OnStopAuthority()
|
||||
{
|
||||
this.enabled = false;
|
||||
|
||||
rigidBody.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative;
|
||||
rigidBody.isKinematic = true;
|
||||
|
||||
SetCursor(false);
|
||||
}
|
||||
|
||||
public override void OnStartLocalPlayer()
|
||||
{
|
||||
if (ControllerUIPrefab != null)
|
||||
runtimeData.controllerUI = Instantiate(ControllerUIPrefab);
|
||||
|
||||
if (runtimeData.controllerUI != null)
|
||||
{
|
||||
if (runtimeData.controllerUI.TryGetComponent(out PlayerControllerKRBUI canvasControlPanel))
|
||||
canvasControlPanel.Refresh(moveKeys, optionsKeys);
|
||||
|
||||
runtimeData.controllerUI.SetActive(controlOptions.HasFlag(ControlOptions.ShowUI));
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnStopLocalPlayer()
|
||||
{
|
||||
if (runtimeData.controllerUI != null)
|
||||
Destroy(runtimeData.controllerUI);
|
||||
|
||||
runtimeData.controllerUI = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
void Update()
|
||||
{
|
||||
HandleOptions();
|
||||
}
|
||||
|
||||
void HandleOptions()
|
||||
{
|
||||
if (optionsKeys.MouseSteer != KeyCode.None && Input.GetKeyUp(optionsKeys.MouseSteer))
|
||||
{
|
||||
controlOptions ^= ControlOptions.MouseSteer;
|
||||
SetCursor(controlOptions.HasFlag(ControlOptions.MouseSteer));
|
||||
}
|
||||
|
||||
if (optionsKeys.AutoRun != KeyCode.None && Input.GetKeyUp(optionsKeys.AutoRun))
|
||||
controlOptions ^= ControlOptions.AutoRun;
|
||||
|
||||
if (optionsKeys.ToggleUI != KeyCode.None && Input.GetKeyUp(optionsKeys.ToggleUI))
|
||||
{
|
||||
controlOptions ^= ControlOptions.ShowUI;
|
||||
|
||||
if (runtimeData.controllerUI != null)
|
||||
runtimeData.controllerUI.SetActive(controlOptions.HasFlag(ControlOptions.ShowUI));
|
||||
}
|
||||
}
|
||||
|
||||
void SetCursor(bool locked)
|
||||
{
|
||||
Cursor.lockState = locked ? CursorLockMode.Locked : CursorLockMode.None;
|
||||
Cursor.visible = !locked;
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
float fixedDeltaTime = Time.fixedDeltaTime;
|
||||
|
||||
if (controlOptions.HasFlag(ControlOptions.MouseSteer))
|
||||
HandleMouseSteer(fixedDeltaTime);
|
||||
else
|
||||
HandleTurning(fixedDeltaTime);
|
||||
|
||||
HandleJumping(fixedDeltaTime);
|
||||
HandleMove(fixedDeltaTime);
|
||||
ApplyMove(fixedDeltaTime);
|
||||
|
||||
// Update ground state
|
||||
bool isGrounded = Physics.Raycast(transform.position, Vector3.down, capsuleCollider.height / 2 + 0.1f);
|
||||
if (isGrounded)
|
||||
runtimeData.groundState = GroundState.Grounded;
|
||||
else if (runtimeData.groundState != GroundState.Jumping)
|
||||
runtimeData.groundState = GroundState.Falling;
|
||||
|
||||
// Update velocity for diagnostics
|
||||
runtimeData.velocity = Vector3Int.FloorToInt(rigidBody.velocity);
|
||||
}
|
||||
|
||||
// Turning works while airborne...feature?
|
||||
void HandleTurning(float fixedDeltaTime)
|
||||
{
|
||||
float targetTurnSpeed = 0f;
|
||||
|
||||
// TurnLeft and TurnRight cancel each other out, reducing targetTurnSpeed to zero.
|
||||
if (moveKeys.TurnLeft != KeyCode.None && Input.GetKey(moveKeys.TurnLeft))
|
||||
targetTurnSpeed -= maxTurnSpeed;
|
||||
if (moveKeys.TurnRight != KeyCode.None && Input.GetKey(moveKeys.TurnRight))
|
||||
targetTurnSpeed += maxTurnSpeed;
|
||||
|
||||
// If there's turn input or AutoRun is not enabled, adjust turn speed towards target
|
||||
// If no turn input and AutoRun is enabled, maintain the previous turn speed
|
||||
if (targetTurnSpeed != 0f || !controlOptions.HasFlag(ControlOptions.AutoRun))
|
||||
runtimeData.turnSpeed = Mathf.MoveTowards(runtimeData.turnSpeed, targetTurnSpeed, turnAcceleration * maxTurnSpeed * fixedDeltaTime);
|
||||
|
||||
//transform.Rotate(0f, runtimeData.turnSpeed * fixedDeltaTime, 0f);
|
||||
transform.Rotate(transform.up, runtimeData.turnSpeed * fixedDeltaTime, Space.World);
|
||||
}
|
||||
|
||||
void HandleMouseSteer(float fixedDeltaTime)
|
||||
{
|
||||
// Accumulate mouse input over time
|
||||
runtimeData.mouseInputX += Input.GetAxisRaw("Mouse X") * runtimeData.mouseSensitivity;
|
||||
|
||||
// Clamp the accumulator to simulate key press behavior
|
||||
runtimeData.mouseInputX = Mathf.Clamp(runtimeData.mouseInputX, -1f, 1f);
|
||||
|
||||
// Calculate target turn speed
|
||||
float targetTurnSpeed = runtimeData.mouseInputX * maxTurnSpeed;
|
||||
|
||||
// Use the same acceleration logic as HandleTurning
|
||||
runtimeData.turnSpeed = Mathf.MoveTowards(runtimeData.turnSpeed, targetTurnSpeed, runtimeData.mouseSensitivity * maxTurnSpeed * fixedDeltaTime);
|
||||
|
||||
// Apply rotation
|
||||
//transform.Rotate(0f, runtimeData.turnSpeed * fixedDeltaTime, 0f);
|
||||
transform.Rotate(transform.up, runtimeData.turnSpeed * fixedDeltaTime, Space.World);
|
||||
|
||||
runtimeData.mouseInputX = Mathf.MoveTowards(runtimeData.mouseInputX, 0f, runtimeData.mouseSensitivity * fixedDeltaTime);
|
||||
}
|
||||
|
||||
void HandleJumping(float fixedDeltaTime)
|
||||
{
|
||||
if (runtimeData.groundState != GroundState.Falling && moveKeys.Jump != KeyCode.None && Input.GetKey(moveKeys.Jump))
|
||||
{
|
||||
if (runtimeData.groundState != GroundState.Jumping)
|
||||
{
|
||||
runtimeData.groundState = GroundState.Jumping;
|
||||
runtimeData.jumpSpeed = initialJumpSpeed;
|
||||
}
|
||||
else if (runtimeData.jumpSpeed < maxJumpSpeed)
|
||||
{
|
||||
// Increase jumpSpeed using a square root function for a fast start and slow finish
|
||||
float jumpProgress = (runtimeData.jumpSpeed - initialJumpSpeed) / (maxJumpSpeed - initialJumpSpeed);
|
||||
runtimeData.jumpSpeed += (jumpAcceleration * Mathf.Sqrt(1 - jumpProgress)) * fixedDeltaTime;
|
||||
}
|
||||
|
||||
if (runtimeData.jumpSpeed >= maxJumpSpeed)
|
||||
{
|
||||
runtimeData.jumpSpeed = maxJumpSpeed;
|
||||
runtimeData.groundState = GroundState.Falling;
|
||||
}
|
||||
}
|
||||
else if (runtimeData.groundState != GroundState.Grounded)
|
||||
{
|
||||
runtimeData.groundState = GroundState.Falling;
|
||||
runtimeData.jumpSpeed = Mathf.Min(runtimeData.jumpSpeed, maxJumpSpeed);
|
||||
runtimeData.jumpSpeed += Physics.gravity.y * fixedDeltaTime;
|
||||
}
|
||||
else
|
||||
// maintain small downward speed for when falling off ledges
|
||||
runtimeData.jumpSpeed = Physics.gravity.y * fixedDeltaTime;
|
||||
}
|
||||
|
||||
void HandleMove(float fixedDeltaTime)
|
||||
{
|
||||
// Initialize target movement variables
|
||||
float targetMoveX = 0f;
|
||||
float targetMoveZ = 0f;
|
||||
|
||||
// Check for WASD key presses and adjust target movement variables accordingly
|
||||
if (moveKeys.Forward != KeyCode.None && Input.GetKey(moveKeys.Forward)) targetMoveZ = 1f;
|
||||
if (moveKeys.Back != KeyCode.None && Input.GetKey(moveKeys.Back)) targetMoveZ = -1f;
|
||||
if (moveKeys.StrafeLeft != KeyCode.None && Input.GetKey(moveKeys.StrafeLeft)) targetMoveX = -1f;
|
||||
if (moveKeys.StrafeRight != KeyCode.None && Input.GetKey(moveKeys.StrafeRight)) targetMoveX = 1f;
|
||||
|
||||
if (targetMoveX == 0f)
|
||||
{
|
||||
if (!controlOptions.HasFlag(ControlOptions.AutoRun))
|
||||
runtimeData.horizontal = Mathf.MoveTowards(runtimeData.horizontal, targetMoveX, inputGravity * fixedDeltaTime);
|
||||
}
|
||||
else
|
||||
runtimeData.horizontal = Mathf.MoveTowards(runtimeData.horizontal, targetMoveX, inputSensitivity * fixedDeltaTime);
|
||||
|
||||
if (targetMoveZ == 0f)
|
||||
{
|
||||
if (!controlOptions.HasFlag(ControlOptions.AutoRun))
|
||||
runtimeData.vertical = Mathf.MoveTowards(runtimeData.vertical, targetMoveZ, inputGravity * fixedDeltaTime);
|
||||
}
|
||||
else
|
||||
runtimeData.vertical = Mathf.MoveTowards(runtimeData.vertical, targetMoveZ, inputSensitivity * fixedDeltaTime);
|
||||
}
|
||||
|
||||
void ApplyMove(float fixedDeltaTime)
|
||||
{
|
||||
// Handle horizontal movement
|
||||
runtimeData.direction = new Vector3(runtimeData.horizontal, 0f, runtimeData.vertical);
|
||||
runtimeData.direction = Vector3.ClampMagnitude(runtimeData.direction, 1f);
|
||||
runtimeData.direction = transform.TransformDirection(runtimeData.direction);
|
||||
runtimeData.direction *= maxMoveSpeed;
|
||||
|
||||
// Apply horizontal movement
|
||||
rigidBody.MovePosition(rigidBody.position + runtimeData.direction * fixedDeltaTime);
|
||||
|
||||
// Handle vertical movement (jumping and gravity)
|
||||
Vector3 verticalMovement = rigidBody.velocity;
|
||||
verticalMovement.y = runtimeData.jumpSpeed;
|
||||
|
||||
// Apply gravity
|
||||
if (runtimeData.groundState != GroundState.Grounded)
|
||||
verticalMovement.y += Physics.gravity.y * fixedDeltaTime;
|
||||
|
||||
// Apply vertical movement
|
||||
rigidBody.velocity = new Vector3(rigidBody.velocity.x, verticalMovement.y, rigidBody.velocity.z);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f49d76ebe6adef649872e344e495b1c1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,8 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror.Examples.Common.Controllers.Player
|
||||
{
|
||||
[AddComponentMenu("Network/Player Controller KRB (Reliable)")]
|
||||
[RequireComponent(typeof(NetworkTransformReliable))]
|
||||
public class PlayerControllerKRBReliable : PlayerControllerKRBBase { }
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0336d1bd689de45418c08c76ae66e503
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Mirror.Examples.Common.Controllers.Player
|
||||
{
|
||||
[AddComponentMenu("")]
|
||||
[DisallowMultipleComponent]
|
||||
public class PlayerControllerKRBUI : ContollerUIBase
|
||||
{
|
||||
[Serializable]
|
||||
public struct MoveTexts
|
||||
{
|
||||
public Text keyTextTurnLeft;
|
||||
public Text keyTextForward;
|
||||
public Text keyTextTurnRight;
|
||||
public Text keyTextStrafeLeft;
|
||||
public Text keyTextBack;
|
||||
public Text keyTextStrafeRight;
|
||||
public Text keyTextJump;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct OptionsTexts
|
||||
{
|
||||
public Text keyTextMouseSteer;
|
||||
public Text keyTextAutoRun;
|
||||
public Text keyTextToggleUI;
|
||||
}
|
||||
|
||||
[SerializeField] MoveTexts moveTexts;
|
||||
[SerializeField] OptionsTexts optionsTexts;
|
||||
|
||||
public void Refresh(PlayerControllerKRBBase.MoveKeys moveKeys, PlayerControllerKRBBase.OptionsKeys optionsKeys)
|
||||
{
|
||||
// Movement Keys
|
||||
moveTexts.keyTextTurnLeft.text = GetKeyText(moveKeys.TurnLeft);
|
||||
moveTexts.keyTextForward.text = GetKeyText(moveKeys.Forward);
|
||||
moveTexts.keyTextTurnRight.text = GetKeyText(moveKeys.TurnRight);
|
||||
moveTexts.keyTextStrafeLeft.text = GetKeyText(moveKeys.StrafeLeft);
|
||||
moveTexts.keyTextBack.text = GetKeyText(moveKeys.Back);
|
||||
moveTexts.keyTextStrafeRight.text = GetKeyText(moveKeys.StrafeRight);
|
||||
moveTexts.keyTextJump.text = GetKeyText(moveKeys.Jump);
|
||||
|
||||
// Options Keys
|
||||
optionsTexts.keyTextMouseSteer.text = GetKeyText(optionsKeys.MouseSteer);
|
||||
optionsTexts.keyTextAutoRun.text = GetKeyText(optionsKeys.AutoRun);
|
||||
optionsTexts.keyTextToggleUI.text = GetKeyText(optionsKeys.ToggleUI);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b3ad79b59b8ecf4691d945429efae18
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5caaf0d5754a64f4080f0c8b55c0b03d
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,8 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror.Examples.Common.Controllers.Player
|
||||
{
|
||||
[AddComponentMenu("Network/Player Controller KRB (Unreliable)")]
|
||||
[RequireComponent(typeof(NetworkTransformUnreliable))]
|
||||
public class PlayerControllerKRBUnreliable : PlayerControllerKRBBase { }
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 60cbbdae6551c7b4395e1bd09e2ff3ea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue
Block a user