Upload project
This commit is contained in:
parent
6bbeab16d1
commit
bf545f3baf
13
.idea/.idea.MP-TD/.idea/.gitignore
generated
vendored
Normal file
13
.idea/.idea.MP-TD/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Rider ignored files
|
||||||
|
/contentModel.xml
|
||||||
|
/projectSettingsUpdater.xml
|
||||||
|
/modules.xml
|
||||||
|
/.idea.MP-TD.iml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
8
.idea/.idea.MP-TD/.idea/indexLayout.xml
generated
Normal file
8
.idea/.idea.MP-TD/.idea/indexLayout.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="UserContentModel">
|
||||||
|
<attachedFolders />
|
||||||
|
<explicitIncludes />
|
||||||
|
<explicitExcludes />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/.idea.MP-TD/.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
6
.idea/.idea.MP-TD/.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="TrailingSpacesInProperty" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
</profile>
|
||||||
|
</component>
|
||||||
1057
Assets/InputSystem_Actions.inputactions
Normal file
1057
Assets/InputSystem_Actions.inputactions
Normal file
File diff suppressed because it is too large
Load Diff
14
Assets/InputSystem_Actions.inputactions.meta
Normal file
14
Assets/InputSystem_Actions.inputactions.meta
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 052faaac586de48259a63d0c4782560b
|
||||||
|
ScriptedImporter:
|
||||||
|
internalIDToNameTable: []
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3}
|
||||||
|
generateWrapperCode: 0
|
||||||
|
wrapperCodePath:
|
||||||
|
wrapperClassName:
|
||||||
|
wrapperCodeNamespace:
|
||||||
8
Assets/Prefabs.meta
Normal file
8
Assets/Prefabs.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 82f549f0feccd434ab87169bc93b457f
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
163
Assets/Prefabs/CharacterPrefab.prefab
Normal file
163
Assets/Prefabs/CharacterPrefab.prefab
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!1 &1555240849038293811
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 1555240849038293810}
|
||||||
|
- component: {fileID: 6060867110873050882}
|
||||||
|
- component: {fileID: 6622008125457246999}
|
||||||
|
- component: {fileID: 4995878257031069448}
|
||||||
|
- component: {fileID: 8700726934599842024}
|
||||||
|
- component: {fileID: 1854736588908238760}
|
||||||
|
- component: {fileID: 3403150522591491636}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: CharacterPrefab
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &1555240849038293810
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1555240849038293811}
|
||||||
|
serializedVersion: 2
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!136 &6060867110873050882
|
||||||
|
CapsuleCollider:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1555240849038293811}
|
||||||
|
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: 2
|
||||||
|
m_Radius: 0.5
|
||||||
|
m_Height: 2
|
||||||
|
m_Direction: 1
|
||||||
|
m_Center: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!114 &6622008125457246999
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1555240849038293811}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: c16549610bfe4458aa9389201d072bb6, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
--- !u!114 &4995878257031069448
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1555240849038293811}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 7c79d771cedb4794bf100ce60df5f764, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
DefaultGhostMode: 0
|
||||||
|
SupportedGhostModes: 3
|
||||||
|
OptimizationMode: 0
|
||||||
|
Importance: 1
|
||||||
|
prefabId:
|
||||||
|
HasOwner: 0
|
||||||
|
SupportAutoCommandTarget: 1
|
||||||
|
TrackInterpolationDelay: 0
|
||||||
|
GhostGroup: 0
|
||||||
|
UsePreSerialization: 0
|
||||||
|
RollbackPredictedSpawnedGhostState: 0
|
||||||
|
RollbackPredictionOnStructuralChanges: 1
|
||||||
|
--- !u!23 &8700726934599842024
|
||||||
|
MeshRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1555240849038293811}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_CastShadows: 1
|
||||||
|
m_ReceiveShadows: 1
|
||||||
|
m_DynamicOccludee: 1
|
||||||
|
m_StaticShadowCaster: 0
|
||||||
|
m_MotionVectors: 1
|
||||||
|
m_LightProbeUsage: 1
|
||||||
|
m_ReflectionProbeUsage: 1
|
||||||
|
m_RayTracingMode: 2
|
||||||
|
m_RayTraceProcedural: 0
|
||||||
|
m_RayTracingAccelStructBuildFlagsOverride: 0
|
||||||
|
m_RayTracingAccelStructBuildFlags: 1
|
||||||
|
m_SmallMeshCulling: 1
|
||||||
|
m_RenderingLayerMask: 257
|
||||||
|
m_RendererPriority: 0
|
||||||
|
m_Materials:
|
||||||
|
- {fileID: 2100000, guid: 70c3442346d77cb4781288146feb488a, type: 2}
|
||||||
|
m_StaticBatchInfo:
|
||||||
|
firstSubMesh: 0
|
||||||
|
subMeshCount: 0
|
||||||
|
m_StaticBatchRoot: {fileID: 0}
|
||||||
|
m_ProbeAnchor: {fileID: 0}
|
||||||
|
m_LightProbeVolumeOverride: {fileID: 0}
|
||||||
|
m_ScaleInLightmap: 1
|
||||||
|
m_ReceiveGI: 1
|
||||||
|
m_PreserveUVs: 0
|
||||||
|
m_IgnoreNormalsForChartDetection: 0
|
||||||
|
m_ImportantGI: 0
|
||||||
|
m_StitchLightmapSeams: 1
|
||||||
|
m_SelectedEditorRenderState: 3
|
||||||
|
m_MinimumChartSize: 4
|
||||||
|
m_AutoUVMaxDistance: 0.5
|
||||||
|
m_AutoUVMaxAngle: 89
|
||||||
|
m_LightmapParameters: {fileID: 0}
|
||||||
|
m_SortingLayerID: 0
|
||||||
|
m_SortingLayer: 0
|
||||||
|
m_SortingOrder: 0
|
||||||
|
m_AdditionalVertexStreams: {fileID: 0}
|
||||||
|
--- !u!33 &1854736588908238760
|
||||||
|
MeshFilter:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1555240849038293811}
|
||||||
|
m_Mesh: {fileID: 10208, guid: 0000000000000000e000000000000000, type: 0}
|
||||||
|
--- !u!114 &3403150522591491636
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1555240849038293811}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 544609009a6605d44a92eca2ad0145ad, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
7
Assets/Prefabs/CharacterPrefab.prefab.meta
Normal file
7
Assets/Prefabs/CharacterPrefab.prefab.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2c95b1fb964db584b842d4c61dff15c7
|
||||||
|
PrefabImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
34
Assets/Readme.asset
Normal file
34
Assets/Readme.asset
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!114 &11400000
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: fcf7219bab7fe46a1ad266029b2fee19, type: 3}
|
||||||
|
m_Name: Readme
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
icon: {fileID: 2800000, guid: 727a75301c3d24613a3ebcec4a24c2c8, type: 3}
|
||||||
|
title: URP Empty Template
|
||||||
|
sections:
|
||||||
|
- heading: Welcome to the Universal Render Pipeline
|
||||||
|
text: This template includes the settings and assets you need to start creating with the Universal Render Pipeline.
|
||||||
|
linkText:
|
||||||
|
url:
|
||||||
|
- heading: URP Documentation
|
||||||
|
text:
|
||||||
|
linkText: Read more about URP
|
||||||
|
url: https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@latest
|
||||||
|
- heading: Forums
|
||||||
|
text:
|
||||||
|
linkText: Get answers and support
|
||||||
|
url: https://forum.unity.com/forums/universal-render-pipeline.383/
|
||||||
|
- heading: Report bugs
|
||||||
|
text:
|
||||||
|
linkText: Submit a report
|
||||||
|
url: https://unity3d.com/unity/qa/bug-reporting
|
||||||
|
loadedLayout: 1
|
||||||
8
Assets/Readme.asset.meta
Normal file
8
Assets/Readme.asset.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8105016687592461f977c054a80ce2f2
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 0
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
Assets/Samples.meta
Normal file
8
Assets/Samples.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6d31ac21ab8253442ba45b149384d19d
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
Assets/Samples/Character Controller.meta
Normal file
8
Assets/Samples/Character Controller.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 50a29f4f31781fb4984017ae3db933e3
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
Assets/Samples/Character Controller/1.2.4.meta
Normal file
8
Assets/Samples/Character Controller/1.2.4.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a9001debb3a3a3243a1dd776f71d35fe
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6afefbe93f0fd7a4da29aa55f1659aab
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"displayName":"Standard Characters",
|
||||||
|
"description": "Replace this string with your own description of the sample. Delete the Samples folder if not needed.",
|
||||||
|
"createSeparatePackage": false
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 70f0f4c77223cfe47874f4fa60a4dde6
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: cae70069c0be15b49a1ae75f627ca5b0
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,133 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!114 &-7466207842126543850
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 11
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
version: 9
|
||||||
|
--- !u!21 &2100000
|
||||||
|
Material:
|
||||||
|
serializedVersion: 8
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_Name: SimpleMaterial_White
|
||||||
|
m_Shader: {fileID: -6465566751694194690, guid: 2d40c85a2e8955d4ea370f6fd8c48a34, type: 3}
|
||||||
|
m_Parent: {fileID: 0}
|
||||||
|
m_ModifiedSerializedProperties: 0
|
||||||
|
m_ValidKeywords: []
|
||||||
|
m_InvalidKeywords: []
|
||||||
|
m_LightmapFlags: 4
|
||||||
|
m_EnableInstancingVariants: 0
|
||||||
|
m_DoubleSidedGI: 0
|
||||||
|
m_CustomRenderQueue: -1
|
||||||
|
stringTagMap: {}
|
||||||
|
disabledShaderPasses:
|
||||||
|
- MOTIONVECTORS
|
||||||
|
m_LockedProperties:
|
||||||
|
m_SavedProperties:
|
||||||
|
serializedVersion: 3
|
||||||
|
m_TexEnvs:
|
||||||
|
- _BaseMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _BumpMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _DetailAlbedoMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _DetailMask:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _DetailNormalMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _EmissionMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _MainTex:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _MetallicGlossMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _OcclusionMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _ParallaxMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _SpecGlossMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- unity_Lightmaps:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- unity_LightmapsInd:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- unity_ShadowMasks:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
m_Ints: []
|
||||||
|
m_Floats:
|
||||||
|
- Vector1_3962d271a12b44169f6af5da4a6b1eae: 0.5
|
||||||
|
- _AlphaClip: 0
|
||||||
|
- _Blend: 0
|
||||||
|
- _BumpScale: 1
|
||||||
|
- _ClearCoatMask: 0
|
||||||
|
- _ClearCoatSmoothness: 0
|
||||||
|
- _Cull: 2
|
||||||
|
- _Cutoff: 0.5
|
||||||
|
- _DetailAlbedoMapScale: 1
|
||||||
|
- _DetailNormalMapScale: 1
|
||||||
|
- _DstBlend: 0
|
||||||
|
- _EnvironmentReflections: 1
|
||||||
|
- _GlossMapScale: 0
|
||||||
|
- _Glossiness: 0
|
||||||
|
- _GlossyReflections: 0
|
||||||
|
- _Metallic: 0
|
||||||
|
- _OcclusionStrength: 1
|
||||||
|
- _Parallax: 0.005
|
||||||
|
- _QueueControl: 0
|
||||||
|
- _QueueOffset: 0
|
||||||
|
- _ReceiveShadows: 1
|
||||||
|
- _Smoothness: 0.5
|
||||||
|
- _SmoothnessTextureChannel: 0
|
||||||
|
- _SpecularHighlights: 1
|
||||||
|
- _SrcBlend: 1
|
||||||
|
- _Surface: 0
|
||||||
|
- _WorkflowMode: 1
|
||||||
|
- _ZWrite: 1
|
||||||
|
m_Colors:
|
||||||
|
- Color_cb3bb3be051d4782821489a356b18884: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||||
|
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
|
||||||
|
m_BuildTextureStacks: []
|
||||||
|
m_AllowLocking: 1
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 70c3442346d77cb4781288146feb488a
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 2100000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,10 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2d40c85a2e8955d4ea370f6fd8c48a34
|
||||||
|
ScriptedImporter:
|
||||||
|
internalIDToNameTable: []
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 612c2e3af04f3d54a9f97a248cc1b074
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 99214d3f1d71df340b942a6ad26882ae
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
using Unity.Burst;
|
||||||
|
using Unity.Collections;
|
||||||
|
using Unity.Entities;
|
||||||
|
using Unity.Jobs;
|
||||||
|
using Unity.Mathematics;
|
||||||
|
using Unity.Transforms;
|
||||||
|
|
||||||
|
[UpdateInGroup(typeof(PresentationSystemGroup))]
|
||||||
|
public partial class MainCameraSystem : SystemBase
|
||||||
|
{
|
||||||
|
protected override void OnUpdate()
|
||||||
|
{
|
||||||
|
if (MainGameObjectCamera.Instance != null && SystemAPI.HasSingleton<MainEntityCamera>())
|
||||||
|
{
|
||||||
|
Entity mainEntityCameraEntity = SystemAPI.GetSingletonEntity<MainEntityCamera>();
|
||||||
|
LocalToWorld targetLocalToWorld = SystemAPI.GetComponent<LocalToWorld>(mainEntityCameraEntity);
|
||||||
|
MainGameObjectCamera.Instance.transform.SetPositionAndRotation(targetLocalToWorld.Position, targetLocalToWorld.Rotation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7d4fbc2db2fb32d48b168c795a5c3afd
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
using System;
|
||||||
|
using Unity.Collections;
|
||||||
|
using Unity.Entities;
|
||||||
|
using Unity.Mathematics;
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public struct MainEntityCamera : IComponentData
|
||||||
|
{
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9680d5663c7e4b24a9308dce893ab885
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using Unity.Entities;
|
||||||
|
|
||||||
|
[DisallowMultipleComponent]
|
||||||
|
public class MainEntityCameraAuthoring : MonoBehaviour
|
||||||
|
{
|
||||||
|
public class Baker : Baker<MainEntityCameraAuthoring>
|
||||||
|
{
|
||||||
|
public override void Bake(MainEntityCameraAuthoring authoring)
|
||||||
|
{
|
||||||
|
Entity entity = GetEntity(TransformUsageFlags.Dynamic);
|
||||||
|
AddComponent<MainEntityCamera>(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 91cffade3faa23640921cbb79b1e6bb0
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class MainGameObjectCamera : MonoBehaviour
|
||||||
|
{
|
||||||
|
public static Camera Instance;
|
||||||
|
|
||||||
|
void Awake()
|
||||||
|
{
|
||||||
|
Instance = GetComponent<UnityEngine.Camera>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ef98a7c3224c6704d976c8bd33dfc59e
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using Unity.Burst;
|
||||||
|
using Unity.Entities;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
[UpdateInGroup(typeof(FixedStepSimulationSystemGroup), OrderLast = true)]
|
||||||
|
[BurstCompile]
|
||||||
|
public partial struct FixedTickSystem : ISystem
|
||||||
|
{
|
||||||
|
public struct Singleton : IComponentData
|
||||||
|
{
|
||||||
|
public uint Tick;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnCreate(ref SystemState state)
|
||||||
|
{
|
||||||
|
if (!SystemAPI.HasSingleton<Singleton>())
|
||||||
|
{
|
||||||
|
Entity singletonEntity = state.EntityManager.CreateEntity();
|
||||||
|
state.EntityManager.AddComponentData(singletonEntity, new Singleton());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[BurstCompile]
|
||||||
|
public void OnUpdate(ref SystemState state)
|
||||||
|
{
|
||||||
|
ref Singleton singleton = ref SystemAPI.GetSingletonRW<Singleton>().ValueRW;
|
||||||
|
singleton.Tick++;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d6fbafd4891f00443b6216ceb5e730e2
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Unity.Entities;
|
||||||
|
using Unity.Mathematics;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public struct FixedInputEvent
|
||||||
|
{
|
||||||
|
private byte _wasEverSet;
|
||||||
|
private uint _lastSetTick;
|
||||||
|
|
||||||
|
public void Set(uint tick)
|
||||||
|
{
|
||||||
|
_lastSetTick = tick;
|
||||||
|
_wasEverSet = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsSet(uint tick)
|
||||||
|
{
|
||||||
|
if (_wasEverSet == 1)
|
||||||
|
{
|
||||||
|
return tick == _lastSetTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b8544c6607fc2464898a9419ad9e6edf
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: bbdb83402ee5311408f853bab201d6a0
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: dee4f1f9965526945b6c704f95625b90
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,250 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!1 &1555240848202863130
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 1555240848202863129}
|
||||||
|
- component: {fileID: 1555240848202863135}
|
||||||
|
- component: {fileID: 1555240848202863128}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: Capsule
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &1555240848202863129
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1555240848202863130}
|
||||||
|
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: []
|
||||||
|
m_Father: {fileID: 1555240849038293810}
|
||||||
|
m_RootOrder: 0
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!33 &1555240848202863135
|
||||||
|
MeshFilter:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1555240848202863130}
|
||||||
|
m_Mesh: {fileID: 10208, guid: 0000000000000000e000000000000000, type: 0}
|
||||||
|
--- !u!23 &1555240848202863128
|
||||||
|
MeshRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1555240848202863130}
|
||||||
|
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_RenderingLayerMask: 257
|
||||||
|
m_RendererPriority: 0
|
||||||
|
m_Materials:
|
||||||
|
- {fileID: 2100000, guid: 70c3442346d77cb4781288146feb488a, type: 2}
|
||||||
|
m_StaticBatchInfo:
|
||||||
|
firstSubMesh: 0
|
||||||
|
subMeshCount: 0
|
||||||
|
m_StaticBatchRoot: {fileID: 0}
|
||||||
|
m_ProbeAnchor: {fileID: 0}
|
||||||
|
m_LightProbeVolumeOverride: {fileID: 0}
|
||||||
|
m_ScaleInLightmap: 1
|
||||||
|
m_ReceiveGI: 1
|
||||||
|
m_PreserveUVs: 0
|
||||||
|
m_IgnoreNormalsForChartDetection: 0
|
||||||
|
m_ImportantGI: 0
|
||||||
|
m_StitchLightmapSeams: 1
|
||||||
|
m_SelectedEditorRenderState: 3
|
||||||
|
m_MinimumChartSize: 4
|
||||||
|
m_AutoUVMaxDistance: 0.5
|
||||||
|
m_AutoUVMaxAngle: 89
|
||||||
|
m_LightmapParameters: {fileID: 0}
|
||||||
|
m_SortingLayerID: 0
|
||||||
|
m_SortingLayer: 0
|
||||||
|
m_SortingOrder: 0
|
||||||
|
m_AdditionalVertexStreams: {fileID: 0}
|
||||||
|
--- !u!1 &1555240849038293811
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 1555240849038293810}
|
||||||
|
- component: {fileID: 6060867110873050882}
|
||||||
|
- component: {fileID: 2674214978767437844}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: FirstPersonCharacter
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &1555240849038293810
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1555240849038293811}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children:
|
||||||
|
- {fileID: 1555240848202863129}
|
||||||
|
- {fileID: 6401532902016766949}
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_RootOrder: 0
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!136 &6060867110873050882
|
||||||
|
CapsuleCollider:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1555240849038293811}
|
||||||
|
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: 2
|
||||||
|
m_Radius: 0.5
|
||||||
|
m_Height: 2
|
||||||
|
m_Direction: 1
|
||||||
|
m_Center: {x: 0, y: 1, z: 0}
|
||||||
|
--- !u!114 &2674214978767437844
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1555240849038293811}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 03c9592a80483fd478e45d176ac83132, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
ViewEntity: {fileID: 3463604651959167738}
|
||||||
|
CharacterProperties:
|
||||||
|
CustomPhysicsBodyTags:
|
||||||
|
Tag00: 0
|
||||||
|
Tag01: 0
|
||||||
|
Tag02: 0
|
||||||
|
Tag03: 0
|
||||||
|
Tag04: 0
|
||||||
|
Tag05: 0
|
||||||
|
Tag06: 0
|
||||||
|
Tag07: 0
|
||||||
|
InterpolatePosition: 1
|
||||||
|
InterpolateRotation: 0
|
||||||
|
EvaluateGrounding: 1
|
||||||
|
SnapToGround: 1
|
||||||
|
GroundSnappingDistance: 0.5
|
||||||
|
EnhancedGroundPrecision: 0
|
||||||
|
MaxGroundedSlopeAngle: 60
|
||||||
|
DetectMovementCollisions: 1
|
||||||
|
DecollideFromOverlaps: 1
|
||||||
|
ProjectVelocityOnInitialOverlaps: 0
|
||||||
|
MaxContinuousCollisionsIterations: 8
|
||||||
|
MaxOverlapDecollisionIterations: 2
|
||||||
|
DiscardMovementWhenExceedMaxIterations: 1
|
||||||
|
KillVelocityWhenExceedMaxIterations: 1
|
||||||
|
DetectObstructionsForParentBodyMovement: 0
|
||||||
|
SimulateDynamicBody: 1
|
||||||
|
Mass: 1
|
||||||
|
GroundMaxSpeed: 10
|
||||||
|
GroundedMovementSharpness: 15
|
||||||
|
AirAcceleration: 50
|
||||||
|
AirMaxSpeed: 10
|
||||||
|
AirDrag: 0
|
||||||
|
JumpSpeed: 10
|
||||||
|
Gravity:
|
||||||
|
x: -0
|
||||||
|
y: -30
|
||||||
|
z: -0
|
||||||
|
PreventAirAccelerationAgainstUngroundedHits: 1
|
||||||
|
StepAndSlopeHandling:
|
||||||
|
StepHandling: 0
|
||||||
|
MaxStepHeight: 0.5
|
||||||
|
ExtraStepChecksDistance: 0.1
|
||||||
|
CharacterWidthForStepGroundingCheck: 1
|
||||||
|
PreventGroundingWhenMovingTowardsNoGrounding: 1
|
||||||
|
HasMaxDownwardSlopeChangeAngle: 0
|
||||||
|
MaxDownwardSlopeChangeAngle: 90
|
||||||
|
ConstrainVelocityToGroundPlane: 1
|
||||||
|
MinViewAngle: -90
|
||||||
|
MaxViewAngle: 90
|
||||||
|
--- !u!1 &3463604651959167738
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 6401532902016766949}
|
||||||
|
- component: {fileID: 3909008753188905296}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: View
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &6401532902016766949
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 3463604651959167738}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 1.4, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 1555240849038293810}
|
||||||
|
m_RootOrder: 1
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!114 &3909008753188905296
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 3463604651959167738}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: f3ddd2cb094880b40a1612adcf67e9a2, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
Character: {fileID: 1555240849038293811}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e95be3f6ef9cc8243994bdcda968a0e5
|
||||||
|
PrefabImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,47 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!1 &577874318210893199
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 577874318210893197}
|
||||||
|
- component: {fileID: 7698645590983583992}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: FirstPersonPlayer
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &577874318210893197
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 577874318210893199}
|
||||||
|
serializedVersion: 2
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!114 &7698645590983583992
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 577874318210893199}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 98df7776338bbf9418e4d50363a02333, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
ControlledCharacter: {fileID: 0}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8c22dcbefac332745a1efbea69cb8bfc
|
||||||
|
PrefabImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 03d97814abf1c7b45b2d6aab78865870
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,229 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using Unity.Burst;
|
||||||
|
using Unity.Collections;
|
||||||
|
using Unity.Entities;
|
||||||
|
using Unity.Jobs;
|
||||||
|
using Unity.Mathematics;
|
||||||
|
using Unity.Physics;
|
||||||
|
using Unity.Physics.Authoring;
|
||||||
|
using Unity.Physics.Extensions;
|
||||||
|
using Unity.Physics.Systems;
|
||||||
|
using Unity.Transforms;
|
||||||
|
using Unity.CharacterController;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public struct FirstPersonCharacterUpdateContext
|
||||||
|
{
|
||||||
|
// Here, you may add additional global data for your character updates, such as ComponentLookups, Singletons, NativeCollections, etc...
|
||||||
|
// The data you add here will be accessible in your character updates and all of your character "callbacks".
|
||||||
|
|
||||||
|
public void OnSystemCreate(ref SystemState state)
|
||||||
|
{
|
||||||
|
// Get lookups
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnSystemUpdate(ref SystemState state)
|
||||||
|
{
|
||||||
|
// Update lookups
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly partial struct FirstPersonCharacterAspect : IAspect, IKinematicCharacterProcessor<FirstPersonCharacterUpdateContext>
|
||||||
|
{
|
||||||
|
public readonly KinematicCharacterAspect CharacterAspect;
|
||||||
|
public readonly RefRW<FirstPersonCharacterComponent> CharacterComponent;
|
||||||
|
public readonly RefRW<FirstPersonCharacterControl> CharacterControl;
|
||||||
|
|
||||||
|
public void PhysicsUpdate(ref FirstPersonCharacterUpdateContext context, ref KinematicCharacterUpdateContext baseContext)
|
||||||
|
{
|
||||||
|
ref FirstPersonCharacterComponent characterComponent = ref CharacterComponent.ValueRW;
|
||||||
|
ref KinematicCharacterBody characterBody = ref CharacterAspect.CharacterBody.ValueRW;
|
||||||
|
ref float3 characterPosition = ref CharacterAspect.LocalTransform.ValueRW.Position;
|
||||||
|
|
||||||
|
// First phase of default character update
|
||||||
|
CharacterAspect.Update_Initialize(in this, ref context, ref baseContext, ref characterBody, baseContext.Time.DeltaTime);
|
||||||
|
CharacterAspect.Update_ParentMovement(in this, ref context, ref baseContext, ref characterBody, ref characterPosition, characterBody.WasGroundedBeforeCharacterUpdate);
|
||||||
|
CharacterAspect.Update_Grounding(in this, ref context, ref baseContext, ref characterBody, ref characterPosition);
|
||||||
|
|
||||||
|
// Update desired character velocity after grounding was detected, but before doing additional processing that depends on velocity
|
||||||
|
HandleVelocityControl(ref context, ref baseContext);
|
||||||
|
|
||||||
|
// Second phase of default character update
|
||||||
|
CharacterAspect.Update_PreventGroundingFromFutureSlopeChange(in this, ref context, ref baseContext, ref characterBody, in characterComponent.StepAndSlopeHandling);
|
||||||
|
CharacterAspect.Update_GroundPushing(in this, ref context, ref baseContext, characterComponent.Gravity);
|
||||||
|
CharacterAspect.Update_MovementAndDecollisions(in this, ref context, ref baseContext, ref characterBody, ref characterPosition);
|
||||||
|
CharacterAspect.Update_MovingPlatformDetection(ref baseContext, ref characterBody);
|
||||||
|
CharacterAspect.Update_ParentMomentum(ref baseContext, ref characterBody);
|
||||||
|
CharacterAspect.Update_ProcessStatefulCharacterHits();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleVelocityControl(ref FirstPersonCharacterUpdateContext context, ref KinematicCharacterUpdateContext baseContext)
|
||||||
|
{
|
||||||
|
float deltaTime = baseContext.Time.DeltaTime;
|
||||||
|
ref KinematicCharacterBody characterBody = ref CharacterAspect.CharacterBody.ValueRW;
|
||||||
|
ref FirstPersonCharacterComponent characterComponent = ref CharacterComponent.ValueRW;
|
||||||
|
ref FirstPersonCharacterControl characterControl = ref CharacterControl.ValueRW;
|
||||||
|
|
||||||
|
// Rotate move input and velocity to take into account parent rotation
|
||||||
|
if(characterBody.ParentEntity != Entity.Null)
|
||||||
|
{
|
||||||
|
characterControl.MoveVector = math.rotate(characterBody.RotationFromParent, characterControl.MoveVector);
|
||||||
|
characterBody.RelativeVelocity = math.rotate(characterBody.RotationFromParent, characterBody.RelativeVelocity);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (characterBody.IsGrounded)
|
||||||
|
{
|
||||||
|
// Move on ground
|
||||||
|
float3 targetVelocity = characterControl.MoveVector * characterComponent.GroundMaxSpeed;
|
||||||
|
CharacterControlUtilities.StandardGroundMove_Interpolated(ref characterBody.RelativeVelocity, targetVelocity, characterComponent.GroundedMovementSharpness, deltaTime, characterBody.GroundingUp, characterBody.GroundHit.Normal);
|
||||||
|
|
||||||
|
// Jump
|
||||||
|
if (characterControl.Jump)
|
||||||
|
{
|
||||||
|
CharacterControlUtilities.StandardJump(ref characterBody, characterBody.GroundingUp * characterComponent.JumpSpeed, true, characterBody.GroundingUp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Move in air
|
||||||
|
float3 airAcceleration = characterControl.MoveVector * characterComponent.AirAcceleration;
|
||||||
|
if (math.lengthsq(airAcceleration) > 0f)
|
||||||
|
{
|
||||||
|
float3 tmpVelocity = characterBody.RelativeVelocity;
|
||||||
|
CharacterControlUtilities.StandardAirMove(ref characterBody.RelativeVelocity, airAcceleration, characterComponent.AirMaxSpeed, characterBody.GroundingUp, deltaTime, false);
|
||||||
|
|
||||||
|
// Cancel air acceleration from input if we would hit a non-grounded surface (prevents air-climbing slopes at high air accelerations)
|
||||||
|
if (characterComponent.PreventAirAccelerationAgainstUngroundedHits && CharacterAspect.MovementWouldHitNonGroundedObstruction(in this, ref context, ref baseContext, characterBody.RelativeVelocity * deltaTime, out ColliderCastHit hit))
|
||||||
|
{
|
||||||
|
characterBody.RelativeVelocity = tmpVelocity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gravity
|
||||||
|
CharacterControlUtilities.AccelerateVelocity(ref characterBody.RelativeVelocity, characterComponent.Gravity, deltaTime);
|
||||||
|
|
||||||
|
// Drag
|
||||||
|
CharacterControlUtilities.ApplyDragToVelocity(ref characterBody.RelativeVelocity, deltaTime, characterComponent.AirDrag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void VariableUpdate(ref FirstPersonCharacterUpdateContext context, ref KinematicCharacterUpdateContext baseContext)
|
||||||
|
{
|
||||||
|
ref KinematicCharacterBody characterBody = ref CharacterAspect.CharacterBody.ValueRW;
|
||||||
|
ref FirstPersonCharacterComponent characterComponent = ref CharacterComponent.ValueRW;
|
||||||
|
ref FirstPersonCharacterControl characterControl = ref CharacterControl.ValueRW;
|
||||||
|
ref quaternion characterRotation = ref CharacterAspect.LocalTransform.ValueRW.Rotation;
|
||||||
|
|
||||||
|
// Add rotation from parent body to the character rotation
|
||||||
|
// (this is for allowing a rotating moving platform to rotate your character as well, and handle interpolation properly)
|
||||||
|
KinematicCharacterUtilities.AddVariableRateRotationFromFixedRateRotation(ref characterRotation, characterBody.RotationFromParent, baseContext.Time.DeltaTime, characterBody.LastPhysicsUpdateDeltaTime);
|
||||||
|
|
||||||
|
// Compute character & view rotations from rotation input
|
||||||
|
FirstPersonCharacterUtilities.ComputeFinalRotationsFromRotationDelta(
|
||||||
|
ref characterRotation,
|
||||||
|
ref characterComponent.ViewPitchDegrees,
|
||||||
|
characterControl.LookDegreesDelta,
|
||||||
|
0f,
|
||||||
|
characterComponent.MinViewAngle,
|
||||||
|
characterComponent.MaxViewAngle,
|
||||||
|
out float canceledPitchDegrees,
|
||||||
|
out characterComponent.ViewLocalRotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Character Processor Callbacks
|
||||||
|
public void UpdateGroundingUp(
|
||||||
|
ref FirstPersonCharacterUpdateContext context,
|
||||||
|
ref KinematicCharacterUpdateContext baseContext)
|
||||||
|
{
|
||||||
|
ref KinematicCharacterBody characterBody = ref CharacterAspect.CharacterBody.ValueRW;
|
||||||
|
|
||||||
|
CharacterAspect.Default_UpdateGroundingUp(ref characterBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CanCollideWithHit(
|
||||||
|
ref FirstPersonCharacterUpdateContext context,
|
||||||
|
ref KinematicCharacterUpdateContext baseContext,
|
||||||
|
in BasicHit hit)
|
||||||
|
{
|
||||||
|
return PhysicsUtilities.IsCollidable(hit.Material);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsGroundedOnHit(
|
||||||
|
ref FirstPersonCharacterUpdateContext context,
|
||||||
|
ref KinematicCharacterUpdateContext baseContext,
|
||||||
|
in BasicHit hit,
|
||||||
|
int groundingEvaluationType)
|
||||||
|
{
|
||||||
|
FirstPersonCharacterComponent characterComponent = CharacterComponent.ValueRO;
|
||||||
|
|
||||||
|
return CharacterAspect.Default_IsGroundedOnHit(
|
||||||
|
in this,
|
||||||
|
ref context,
|
||||||
|
ref baseContext,
|
||||||
|
in hit,
|
||||||
|
in characterComponent.StepAndSlopeHandling,
|
||||||
|
groundingEvaluationType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnMovementHit(
|
||||||
|
ref FirstPersonCharacterUpdateContext context,
|
||||||
|
ref KinematicCharacterUpdateContext baseContext,
|
||||||
|
ref KinematicCharacterHit hit,
|
||||||
|
ref float3 remainingMovementDirection,
|
||||||
|
ref float remainingMovementLength,
|
||||||
|
float3 originalVelocityDirection,
|
||||||
|
float hitDistance)
|
||||||
|
{
|
||||||
|
ref KinematicCharacterBody characterBody = ref CharacterAspect.CharacterBody.ValueRW;
|
||||||
|
ref float3 characterPosition = ref CharacterAspect.LocalTransform.ValueRW.Position;
|
||||||
|
FirstPersonCharacterComponent characterComponent = CharacterComponent.ValueRO;
|
||||||
|
|
||||||
|
CharacterAspect.Default_OnMovementHit(
|
||||||
|
in this,
|
||||||
|
ref context,
|
||||||
|
ref baseContext,
|
||||||
|
ref characterBody,
|
||||||
|
ref characterPosition,
|
||||||
|
ref hit,
|
||||||
|
ref remainingMovementDirection,
|
||||||
|
ref remainingMovementLength,
|
||||||
|
originalVelocityDirection,
|
||||||
|
hitDistance,
|
||||||
|
characterComponent.StepAndSlopeHandling.StepHandling,
|
||||||
|
characterComponent.StepAndSlopeHandling.MaxStepHeight,
|
||||||
|
characterComponent.StepAndSlopeHandling.CharacterWidthForStepGroundingCheck);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OverrideDynamicHitMasses(
|
||||||
|
ref FirstPersonCharacterUpdateContext context,
|
||||||
|
ref KinematicCharacterUpdateContext baseContext,
|
||||||
|
ref PhysicsMass characterMass,
|
||||||
|
ref PhysicsMass otherMass,
|
||||||
|
BasicHit hit)
|
||||||
|
{
|
||||||
|
// Custom mass overrides
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ProjectVelocityOnHits(
|
||||||
|
ref FirstPersonCharacterUpdateContext context,
|
||||||
|
ref KinematicCharacterUpdateContext baseContext,
|
||||||
|
ref float3 velocity,
|
||||||
|
ref bool characterIsGrounded,
|
||||||
|
ref BasicHit characterGroundHit,
|
||||||
|
in DynamicBuffer<KinematicVelocityProjectionHit> velocityProjectionHits,
|
||||||
|
float3 originalVelocityDirection)
|
||||||
|
{
|
||||||
|
FirstPersonCharacterComponent characterComponent = CharacterComponent.ValueRO;
|
||||||
|
|
||||||
|
CharacterAspect.Default_ProjectVelocityOnHits(
|
||||||
|
ref velocity,
|
||||||
|
ref characterIsGrounded,
|
||||||
|
ref characterGroundHit,
|
||||||
|
in velocityProjectionHits,
|
||||||
|
originalVelocityDirection,
|
||||||
|
characterComponent.StepAndSlopeHandling.ConstrainVelocityToGroundPlane);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f5e8284f926e5e7448f516cf2f1b9519
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
using Unity.Entities;
|
||||||
|
using Unity.Mathematics;
|
||||||
|
using Unity.Physics.Authoring;
|
||||||
|
using UnityEngine;
|
||||||
|
using Unity.CharacterController;
|
||||||
|
using Unity.Physics;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine.Serialization;
|
||||||
|
|
||||||
|
[DisallowMultipleComponent]
|
||||||
|
public class FirstPersonCharacterAuthoring : MonoBehaviour
|
||||||
|
{
|
||||||
|
public GameObject ViewEntity;
|
||||||
|
public AuthoringKinematicCharacterProperties CharacterProperties = AuthoringKinematicCharacterProperties.GetDefault();
|
||||||
|
|
||||||
|
public float GroundMaxSpeed = 10f;
|
||||||
|
public float GroundedMovementSharpness = 15f;
|
||||||
|
public float AirAcceleration = 50f;
|
||||||
|
public float AirMaxSpeed = 10f;
|
||||||
|
public float AirDrag = 0f;
|
||||||
|
public float JumpSpeed = 10f;
|
||||||
|
public float3 Gravity = math.up() * -30f;
|
||||||
|
public bool PreventAirAccelerationAgainstUngroundedHits = true;
|
||||||
|
public BasicStepAndSlopeHandlingParameters StepAndSlopeHandling = BasicStepAndSlopeHandlingParameters.GetDefault();
|
||||||
|
public float MinViewAngle = -90f;
|
||||||
|
public float MaxViewAngle = 90f;
|
||||||
|
|
||||||
|
public class Baker : Baker<FirstPersonCharacterAuthoring>
|
||||||
|
{
|
||||||
|
public override void Bake(FirstPersonCharacterAuthoring authoring)
|
||||||
|
{
|
||||||
|
KinematicCharacterUtilities.BakeCharacter(this, authoring.gameObject, authoring.CharacterProperties);
|
||||||
|
|
||||||
|
Entity entity = GetEntity(TransformUsageFlags.Dynamic | TransformUsageFlags.WorldSpace);
|
||||||
|
|
||||||
|
AddComponent(entity, new FirstPersonCharacterComponent
|
||||||
|
{
|
||||||
|
GroundMaxSpeed = authoring.GroundMaxSpeed,
|
||||||
|
GroundedMovementSharpness = authoring.GroundedMovementSharpness,
|
||||||
|
AirAcceleration = authoring.AirAcceleration,
|
||||||
|
AirMaxSpeed = authoring.AirMaxSpeed,
|
||||||
|
AirDrag = authoring.AirDrag,
|
||||||
|
JumpSpeed = authoring.JumpSpeed,
|
||||||
|
Gravity = authoring.Gravity,
|
||||||
|
PreventAirAccelerationAgainstUngroundedHits = authoring.PreventAirAccelerationAgainstUngroundedHits,
|
||||||
|
StepAndSlopeHandling = authoring.StepAndSlopeHandling,
|
||||||
|
MinViewAngle = authoring.MinViewAngle,
|
||||||
|
MaxViewAngle = authoring.MaxViewAngle,
|
||||||
|
|
||||||
|
ViewEntity = GetEntity(authoring.ViewEntity, TransformUsageFlags.Dynamic),
|
||||||
|
ViewPitchDegrees = 0f,
|
||||||
|
ViewLocalRotation = quaternion.identity,
|
||||||
|
});
|
||||||
|
AddComponent(entity, new FirstPersonCharacterControl());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 03c9592a80483fd478e45d176ac83132
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using Unity.Collections;
|
||||||
|
using Unity.Entities;
|
||||||
|
using Unity.Mathematics;
|
||||||
|
using UnityEngine;
|
||||||
|
using Unity.CharacterController;
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public struct FirstPersonCharacterComponent : IComponentData
|
||||||
|
{
|
||||||
|
public float GroundMaxSpeed;
|
||||||
|
public float GroundedMovementSharpness;
|
||||||
|
public float AirAcceleration;
|
||||||
|
public float AirMaxSpeed;
|
||||||
|
public float AirDrag;
|
||||||
|
public float JumpSpeed;
|
||||||
|
public float3 Gravity;
|
||||||
|
public bool PreventAirAccelerationAgainstUngroundedHits;
|
||||||
|
public BasicStepAndSlopeHandlingParameters StepAndSlopeHandling;
|
||||||
|
|
||||||
|
public float MinViewAngle;
|
||||||
|
public float MaxViewAngle;
|
||||||
|
|
||||||
|
public Entity ViewEntity;
|
||||||
|
public float ViewPitchDegrees;
|
||||||
|
public quaternion ViewLocalRotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public struct FirstPersonCharacterControl : IComponentData
|
||||||
|
{
|
||||||
|
public float3 MoveVector;
|
||||||
|
public float2 LookDegreesDelta;
|
||||||
|
public bool Jump;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public struct FirstPersonCharacterView : IComponentData
|
||||||
|
{
|
||||||
|
public Entity CharacterEntity;
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 639e80f96b7d5f94bbb37c78f27edecd
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,160 @@
|
|||||||
|
using Unity.Burst;
|
||||||
|
using Unity.Entities;
|
||||||
|
using Unity.Collections;
|
||||||
|
using Unity.Jobs;
|
||||||
|
using Unity.Mathematics;
|
||||||
|
using Unity.Physics;
|
||||||
|
using Unity.Transforms;
|
||||||
|
using Unity.CharacterController;
|
||||||
|
using Unity.Burst.Intrinsics;
|
||||||
|
|
||||||
|
[UpdateInGroup(typeof(KinematicCharacterPhysicsUpdateGroup))]
|
||||||
|
[BurstCompile]
|
||||||
|
public partial struct FirstPersonCharacterPhysicsUpdateSystem : ISystem
|
||||||
|
{
|
||||||
|
private EntityQuery _characterQuery;
|
||||||
|
private FirstPersonCharacterUpdateContext _context;
|
||||||
|
private KinematicCharacterUpdateContext _baseContext;
|
||||||
|
|
||||||
|
[BurstCompile]
|
||||||
|
public void OnCreate(ref SystemState state)
|
||||||
|
{
|
||||||
|
_characterQuery = KinematicCharacterUtilities.GetBaseCharacterQueryBuilder()
|
||||||
|
.WithAll<
|
||||||
|
FirstPersonCharacterComponent,
|
||||||
|
FirstPersonCharacterControl>()
|
||||||
|
.Build(ref state);
|
||||||
|
|
||||||
|
_context = new FirstPersonCharacterUpdateContext();
|
||||||
|
_context.OnSystemCreate(ref state);
|
||||||
|
_baseContext = new KinematicCharacterUpdateContext();
|
||||||
|
_baseContext.OnSystemCreate(ref state);
|
||||||
|
|
||||||
|
state.RequireForUpdate(_characterQuery);
|
||||||
|
state.RequireForUpdate<PhysicsWorldSingleton>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[BurstCompile]
|
||||||
|
public void OnUpdate(ref SystemState state)
|
||||||
|
{
|
||||||
|
_context.OnSystemUpdate(ref state);
|
||||||
|
_baseContext.OnSystemUpdate(ref state, SystemAPI.Time, SystemAPI.GetSingleton<PhysicsWorldSingleton>());
|
||||||
|
|
||||||
|
FirstPersonCharacterPhysicsUpdateJob job = new FirstPersonCharacterPhysicsUpdateJob
|
||||||
|
{
|
||||||
|
Context = _context,
|
||||||
|
BaseContext = _baseContext,
|
||||||
|
};
|
||||||
|
job.ScheduleParallel();
|
||||||
|
}
|
||||||
|
|
||||||
|
[BurstCompile]
|
||||||
|
[WithAll(typeof(Simulate))]
|
||||||
|
public partial struct FirstPersonCharacterPhysicsUpdateJob : IJobEntity, IJobEntityChunkBeginEnd
|
||||||
|
{
|
||||||
|
public FirstPersonCharacterUpdateContext Context;
|
||||||
|
public KinematicCharacterUpdateContext BaseContext;
|
||||||
|
|
||||||
|
void Execute(FirstPersonCharacterAspect characterAspect)
|
||||||
|
{
|
||||||
|
characterAspect.PhysicsUpdate(ref Context, ref BaseContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OnChunkBegin(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
|
||||||
|
{
|
||||||
|
BaseContext.EnsureCreationOfTmpCollections();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnChunkEnd(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask, bool chunkWasExecuted)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[UpdateInGroup(typeof(SimulationSystemGroup))]
|
||||||
|
[UpdateAfter(typeof(FixedStepSimulationSystemGroup))]
|
||||||
|
[UpdateAfter(typeof(FirstPersonPlayerVariableStepControlSystem))]
|
||||||
|
[UpdateBefore(typeof(TransformSystemGroup))]
|
||||||
|
[BurstCompile]
|
||||||
|
public partial struct FirstPersonCharacterVariableUpdateSystem : ISystem
|
||||||
|
{
|
||||||
|
private EntityQuery _characterQuery;
|
||||||
|
private FirstPersonCharacterUpdateContext _context;
|
||||||
|
private KinematicCharacterUpdateContext _baseContext;
|
||||||
|
|
||||||
|
[BurstCompile]
|
||||||
|
public void OnCreate(ref SystemState state)
|
||||||
|
{
|
||||||
|
_characterQuery = KinematicCharacterUtilities.GetBaseCharacterQueryBuilder()
|
||||||
|
.WithAll<
|
||||||
|
FirstPersonCharacterComponent,
|
||||||
|
FirstPersonCharacterControl>()
|
||||||
|
.Build(ref state);
|
||||||
|
|
||||||
|
_context = new FirstPersonCharacterUpdateContext();
|
||||||
|
_context.OnSystemCreate(ref state);
|
||||||
|
_baseContext = new KinematicCharacterUpdateContext();
|
||||||
|
_baseContext.OnSystemCreate(ref state);
|
||||||
|
|
||||||
|
state.RequireForUpdate(_characterQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
[BurstCompile]
|
||||||
|
public void OnUpdate(ref SystemState state)
|
||||||
|
{
|
||||||
|
_context.OnSystemUpdate(ref state);
|
||||||
|
_baseContext.OnSystemUpdate(ref state, SystemAPI.Time, SystemAPI.GetSingleton<PhysicsWorldSingleton>());
|
||||||
|
|
||||||
|
FirstPersonCharacterVariableUpdateJob variableUpdateJob = new FirstPersonCharacterVariableUpdateJob
|
||||||
|
{
|
||||||
|
Context = _context,
|
||||||
|
BaseContext = _baseContext,
|
||||||
|
};
|
||||||
|
variableUpdateJob.ScheduleParallel();
|
||||||
|
|
||||||
|
FirstPersonCharacterViewJob viewJob = new FirstPersonCharacterViewJob
|
||||||
|
{
|
||||||
|
FirstPersonCharacterLookup = SystemAPI.GetComponentLookup<FirstPersonCharacterComponent>(true),
|
||||||
|
};
|
||||||
|
viewJob.ScheduleParallel();
|
||||||
|
}
|
||||||
|
|
||||||
|
[BurstCompile]
|
||||||
|
[WithAll(typeof(Simulate))]
|
||||||
|
public partial struct FirstPersonCharacterVariableUpdateJob : IJobEntity, IJobEntityChunkBeginEnd
|
||||||
|
{
|
||||||
|
public FirstPersonCharacterUpdateContext Context;
|
||||||
|
public KinematicCharacterUpdateContext BaseContext;
|
||||||
|
|
||||||
|
void Execute(FirstPersonCharacterAspect characterAspect)
|
||||||
|
{
|
||||||
|
characterAspect.VariableUpdate(ref Context, ref BaseContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OnChunkBegin(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
|
||||||
|
{
|
||||||
|
BaseContext.EnsureCreationOfTmpCollections();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnChunkEnd(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask, bool chunkWasExecuted)
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
|
||||||
|
[BurstCompile]
|
||||||
|
[WithAll(typeof(Simulate))]
|
||||||
|
public partial struct FirstPersonCharacterViewJob : IJobEntity
|
||||||
|
{
|
||||||
|
[ReadOnly]
|
||||||
|
public ComponentLookup<FirstPersonCharacterComponent> FirstPersonCharacterLookup;
|
||||||
|
|
||||||
|
void Execute(ref LocalTransform localTransform, in FirstPersonCharacterView characterView)
|
||||||
|
{
|
||||||
|
if (FirstPersonCharacterLookup.TryGetComponent(characterView.CharacterEntity, out FirstPersonCharacterComponent character))
|
||||||
|
{
|
||||||
|
localTransform.Rotation = character.ViewLocalRotation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8255af6f295149f41bc8baf529b5b711
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,135 @@
|
|||||||
|
using System;
|
||||||
|
using Unity.Collections;
|
||||||
|
using Unity.Entities;
|
||||||
|
using Unity.Mathematics;
|
||||||
|
using Unity.CharacterController;
|
||||||
|
|
||||||
|
public static class FirstPersonCharacterUtilities
|
||||||
|
{
|
||||||
|
public static quaternion GetCurrentWorldViewRotation(quaternion characterRotation, quaternion localCharacterViewRotation)
|
||||||
|
{
|
||||||
|
return math.mul(characterRotation, localCharacterViewRotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void GetCurrentWorldViewDirectionAndRotation(
|
||||||
|
quaternion characterRotation,
|
||||||
|
quaternion localCharacterViewRotation,
|
||||||
|
out float3 worldCharacterViewDirection,
|
||||||
|
out quaternion worldCharacterViewRotation)
|
||||||
|
{
|
||||||
|
worldCharacterViewRotation = GetCurrentWorldViewRotation(characterRotation, localCharacterViewRotation);
|
||||||
|
worldCharacterViewDirection = math.mul(worldCharacterViewRotation, math.forward());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ComputeFinalRotationsFromTargetLookDirection(
|
||||||
|
ref quaternion characterRotation,
|
||||||
|
ref quaternion localCharacterViewRotation,
|
||||||
|
ref float3 targetLookDirection,
|
||||||
|
ref float viewPitchDegrees,
|
||||||
|
float viewRollDegrees,
|
||||||
|
float minViewPitchDegrees,
|
||||||
|
float maxViewPitchDegrees,
|
||||||
|
float3 characterUp)
|
||||||
|
{
|
||||||
|
// rotate character root to point at look direction on character up plane
|
||||||
|
float3 newCharacterForward = math.normalizesafe(MathUtilities.ProjectOnPlane(targetLookDirection, characterUp));
|
||||||
|
characterRotation = quaternion.LookRotationSafe(newCharacterForward, characterUp);
|
||||||
|
|
||||||
|
// calculate view pitch angles to look at target direction
|
||||||
|
viewPitchDegrees = math.degrees(MathUtilities.AngleRadians(newCharacterForward, targetLookDirection));
|
||||||
|
if (math.dot(characterUp, targetLookDirection) < 0f)
|
||||||
|
{
|
||||||
|
viewPitchDegrees *= -1f;
|
||||||
|
}
|
||||||
|
viewPitchDegrees = math.clamp(viewPitchDegrees, minViewPitchDegrees, maxViewPitchDegrees);
|
||||||
|
|
||||||
|
localCharacterViewRotation = CalculateLocalViewRotation(viewPitchDegrees, viewRollDegrees);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ComputeFinalRotationsFromRotationDelta(
|
||||||
|
ref float viewPitchDegrees,
|
||||||
|
ref float characterRotationYDegrees,
|
||||||
|
float3 characterTransformUp,
|
||||||
|
float2 yawPitchDeltaDegrees,
|
||||||
|
float viewRollDegrees,
|
||||||
|
float minPitchDegrees,
|
||||||
|
float maxPitchDegrees,
|
||||||
|
out quaternion characterRotation,
|
||||||
|
out float canceledPitchDegrees,
|
||||||
|
out quaternion viewLocalRotation)
|
||||||
|
{
|
||||||
|
// Yaw
|
||||||
|
characterRotationYDegrees += yawPitchDeltaDegrees.x;
|
||||||
|
ComputeRotationFromYAngleAndUp(characterRotationYDegrees, characterTransformUp, out characterRotation);
|
||||||
|
|
||||||
|
// Pitch
|
||||||
|
viewPitchDegrees += yawPitchDeltaDegrees.y;
|
||||||
|
float viewPitchAngleDegreesBeforeClamp = viewPitchDegrees;
|
||||||
|
viewPitchDegrees = math.clamp(viewPitchDegrees, minPitchDegrees, maxPitchDegrees);
|
||||||
|
canceledPitchDegrees = yawPitchDeltaDegrees.y - (viewPitchAngleDegreesBeforeClamp - viewPitchDegrees);
|
||||||
|
|
||||||
|
viewLocalRotation = CalculateLocalViewRotation(viewPitchDegrees, viewRollDegrees);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ComputeRotationFromYAngleAndUp(
|
||||||
|
float characterRotationYDegrees,
|
||||||
|
float3 characterTransformUp,
|
||||||
|
out quaternion characterRotation)
|
||||||
|
{
|
||||||
|
characterRotation = math.mul(MathUtilities.CreateRotationWithUpPriority(characterTransformUp, math.forward()), quaternion.Euler(0f, math.radians(characterRotationYDegrees), 0f));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ComputeFinalRotationsFromRotationDelta(
|
||||||
|
ref quaternion characterRotation,
|
||||||
|
ref float viewPitchDegrees,
|
||||||
|
float2 yawPitchDeltaDegrees,
|
||||||
|
float viewRollDegrees,
|
||||||
|
float minPitchDegrees,
|
||||||
|
float maxPitchDegrees,
|
||||||
|
out float canceledPitchDegrees,
|
||||||
|
out quaternion viewLocalRotation)
|
||||||
|
{
|
||||||
|
// Yaw
|
||||||
|
quaternion yawRotation = quaternion.Euler(math.up() * math.radians(yawPitchDeltaDegrees.x));
|
||||||
|
characterRotation = math.mul(characterRotation, yawRotation);
|
||||||
|
|
||||||
|
// Pitch
|
||||||
|
viewPitchDegrees += yawPitchDeltaDegrees.y;
|
||||||
|
float viewPitchAngleDegreesBeforeClamp = viewPitchDegrees;
|
||||||
|
viewPitchDegrees = math.clamp(viewPitchDegrees, minPitchDegrees, maxPitchDegrees);
|
||||||
|
canceledPitchDegrees = yawPitchDeltaDegrees.y - (viewPitchAngleDegreesBeforeClamp - viewPitchDegrees);
|
||||||
|
|
||||||
|
viewLocalRotation = CalculateLocalViewRotation(viewPitchDegrees, viewRollDegrees);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static quaternion CalculateLocalViewRotation(float viewPitchDegrees, float viewRollDegrees)
|
||||||
|
{
|
||||||
|
// Pitch
|
||||||
|
quaternion viewLocalRotation = quaternion.AxisAngle(-math.right(), math.radians(viewPitchDegrees));
|
||||||
|
|
||||||
|
// Roll
|
||||||
|
viewLocalRotation = math.mul(viewLocalRotation, quaternion.AxisAngle(math.forward(), math.radians(viewRollDegrees)));
|
||||||
|
|
||||||
|
return viewLocalRotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float3 ComputeTargetLookDirectionFromRotationAngles(
|
||||||
|
ref float viewPitchDegrees,
|
||||||
|
float minViewPitchDegrees,
|
||||||
|
float maxViewPitchDegrees,
|
||||||
|
float2 pitchYawDegrees,
|
||||||
|
quaternion characterRotation)
|
||||||
|
{
|
||||||
|
// Yaw
|
||||||
|
quaternion yawRotation = quaternion.Euler(math.up() * math.radians(pitchYawDegrees.x));
|
||||||
|
quaternion targetRotation = math.mul(characterRotation, yawRotation);
|
||||||
|
|
||||||
|
// Pitch
|
||||||
|
float tmpViewPitchAngleDegrees = viewPitchDegrees + pitchYawDegrees.y;
|
||||||
|
tmpViewPitchAngleDegrees = math.clamp(tmpViewPitchAngleDegrees, minViewPitchDegrees, maxViewPitchDegrees);
|
||||||
|
quaternion pitchRotation = quaternion.Euler(-math.right() * math.radians(tmpViewPitchAngleDegrees));
|
||||||
|
targetRotation = math.mul(targetRotation, pitchRotation);
|
||||||
|
|
||||||
|
return math.mul(targetRotation, math.forward());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 446b6f888df7be748b79fecd775dff83
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Unity.Entities;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
[DisallowMultipleComponent]
|
||||||
|
public class FirstPersonCharacterViewAuthoring : MonoBehaviour
|
||||||
|
{
|
||||||
|
public GameObject Character;
|
||||||
|
|
||||||
|
public class Baker : Baker<FirstPersonCharacterViewAuthoring>
|
||||||
|
{
|
||||||
|
public override void Bake(FirstPersonCharacterViewAuthoring authoring)
|
||||||
|
{
|
||||||
|
if (authoring.transform.parent != authoring.Character.transform)
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.LogError("ERROR: the Character View must be a direct 1st-level child of the character authoring GameObject. Conversion will be aborted");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Entity entity = GetEntity(TransformUsageFlags.Dynamic);
|
||||||
|
AddComponent(entity, new FirstPersonCharacterView { CharacterEntity = GetEntity(authoring.Character, TransformUsageFlags.Dynamic) });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f3ddd2cb094880b40a1612adcf67e9a2
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using Unity.Collections;
|
||||||
|
using Unity.Entities;
|
||||||
|
using Unity.Mathematics;
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public struct FirstPersonPlayer : IComponentData
|
||||||
|
{
|
||||||
|
public Entity ControlledCharacter;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public struct FirstPersonPlayerInputs : IComponentData
|
||||||
|
{
|
||||||
|
public float2 MoveInput;
|
||||||
|
public float2 LookInput;
|
||||||
|
public FixedInputEvent JumpPressed;
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b475ce53dfa6de64ea0a2e1beac9c141
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using Unity.Entities;
|
||||||
|
|
||||||
|
[DisallowMultipleComponent]
|
||||||
|
public class FirstPersonPlayerAuthoring : MonoBehaviour
|
||||||
|
{
|
||||||
|
public GameObject ControlledCharacter;
|
||||||
|
|
||||||
|
public class Baker : Baker<FirstPersonPlayerAuthoring>
|
||||||
|
{
|
||||||
|
public override void Bake(FirstPersonPlayerAuthoring authoring)
|
||||||
|
{
|
||||||
|
Entity entity = GetEntity(TransformUsageFlags.None);
|
||||||
|
AddComponent(entity, new FirstPersonPlayer
|
||||||
|
{
|
||||||
|
ControlledCharacter = GetEntity(authoring.ControlledCharacter, TransformUsageFlags.Dynamic),
|
||||||
|
});
|
||||||
|
AddComponent<FirstPersonPlayerInputs>(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 98df7776338bbf9418e4d50363a02333
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,113 @@
|
|||||||
|
using Unity.Burst;
|
||||||
|
using Unity.Collections;
|
||||||
|
using Unity.Entities;
|
||||||
|
using Unity.Jobs;
|
||||||
|
using Unity.Mathematics;
|
||||||
|
using Unity.Transforms;
|
||||||
|
using UnityEngine;
|
||||||
|
using Unity.CharacterController;
|
||||||
|
|
||||||
|
[UpdateInGroup(typeof(InitializationSystemGroup))]
|
||||||
|
public partial class FirstPersonPlayerInputsSystem : SystemBase
|
||||||
|
{
|
||||||
|
protected override void OnCreate()
|
||||||
|
{
|
||||||
|
RequireForUpdate<FixedTickSystem.Singleton>();
|
||||||
|
RequireForUpdate(SystemAPI.QueryBuilder().WithAll<FirstPersonPlayer, FirstPersonPlayerInputs>().Build());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnUpdate()
|
||||||
|
{
|
||||||
|
uint tick = SystemAPI.GetSingleton<FixedTickSystem.Singleton>().Tick;
|
||||||
|
|
||||||
|
foreach (var (playerInputs, player) in SystemAPI.Query<RefRW<FirstPersonPlayerInputs>, FirstPersonPlayer>())
|
||||||
|
{
|
||||||
|
playerInputs.ValueRW.MoveInput = new float2
|
||||||
|
{
|
||||||
|
x = (Input.GetKey(KeyCode.D) ? 1f : 0f) + (Input.GetKey(KeyCode.A) ? -1f : 0f),
|
||||||
|
y = (Input.GetKey(KeyCode.W) ? 1f : 0f) + (Input.GetKey(KeyCode.S) ? -1f : 0f),
|
||||||
|
};
|
||||||
|
|
||||||
|
playerInputs.ValueRW.LookInput = new float2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
|
||||||
|
|
||||||
|
if (Input.GetKeyDown(KeyCode.Space))
|
||||||
|
{
|
||||||
|
playerInputs.ValueRW.JumpPressed.Set(tick);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Apply inputs that need to be read at a variable rate
|
||||||
|
/// </summary>
|
||||||
|
[UpdateInGroup(typeof(SimulationSystemGroup))]
|
||||||
|
[UpdateAfter(typeof(FixedStepSimulationSystemGroup))]
|
||||||
|
[BurstCompile]
|
||||||
|
public partial struct FirstPersonPlayerVariableStepControlSystem : ISystem
|
||||||
|
{
|
||||||
|
[BurstCompile]
|
||||||
|
public void OnCreate(ref SystemState state)
|
||||||
|
{
|
||||||
|
state.RequireForUpdate(SystemAPI.QueryBuilder().WithAll<FirstPersonPlayer, FirstPersonPlayerInputs>().Build());
|
||||||
|
}
|
||||||
|
|
||||||
|
[BurstCompile]
|
||||||
|
public void OnUpdate(ref SystemState state)
|
||||||
|
{
|
||||||
|
foreach (var (playerInputs, player) in SystemAPI.Query<FirstPersonPlayerInputs, FirstPersonPlayer>().WithAll<Simulate>())
|
||||||
|
{
|
||||||
|
if (SystemAPI.HasComponent<FirstPersonCharacterControl>(player.ControlledCharacter))
|
||||||
|
{
|
||||||
|
FirstPersonCharacterControl characterControl = SystemAPI.GetComponent<FirstPersonCharacterControl>(player.ControlledCharacter);
|
||||||
|
|
||||||
|
characterControl.LookDegreesDelta = playerInputs.LookInput;
|
||||||
|
|
||||||
|
SystemAPI.SetComponent(player.ControlledCharacter, characterControl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Apply inputs that need to be read at a fixed rate.
|
||||||
|
/// It is necessary to handle this as part of the fixed step group, in case your framerate is lower than the fixed step rate.
|
||||||
|
/// </summary>
|
||||||
|
[UpdateInGroup(typeof(FixedStepSimulationSystemGroup), OrderFirst = true)]
|
||||||
|
[BurstCompile]
|
||||||
|
public partial struct FirstPersonPlayerFixedStepControlSystem : ISystem
|
||||||
|
{
|
||||||
|
[BurstCompile]
|
||||||
|
public void OnCreate(ref SystemState state)
|
||||||
|
{
|
||||||
|
state.RequireForUpdate<FixedTickSystem.Singleton>();
|
||||||
|
state.RequireForUpdate(SystemAPI.QueryBuilder().WithAll<FirstPersonPlayer, FirstPersonPlayerInputs>().Build());
|
||||||
|
}
|
||||||
|
|
||||||
|
[BurstCompile]
|
||||||
|
public void OnUpdate(ref SystemState state)
|
||||||
|
{
|
||||||
|
uint tick = SystemAPI.GetSingleton<FixedTickSystem.Singleton>().Tick;
|
||||||
|
|
||||||
|
foreach (var (playerInputs, player) in SystemAPI.Query<FirstPersonPlayerInputs, FirstPersonPlayer>().WithAll<Simulate>())
|
||||||
|
{
|
||||||
|
if (SystemAPI.HasComponent<FirstPersonCharacterControl>(player.ControlledCharacter))
|
||||||
|
{
|
||||||
|
FirstPersonCharacterControl characterControl = SystemAPI.GetComponent<FirstPersonCharacterControl>(player.ControlledCharacter);
|
||||||
|
|
||||||
|
quaternion characterRotation = SystemAPI.GetComponent<LocalTransform>(player.ControlledCharacter).Rotation;
|
||||||
|
|
||||||
|
// Move
|
||||||
|
float3 characterForward = MathUtilities.GetForwardFromRotation(characterRotation);
|
||||||
|
float3 characterRight = MathUtilities.GetRightFromRotation(characterRotation);
|
||||||
|
characterControl.MoveVector = (playerInputs.MoveInput.y * characterForward) + (playerInputs.MoveInput.x * characterRight);
|
||||||
|
characterControl.MoveVector = MathUtilities.ClampToMaxLength(characterControl.MoveVector, 1f);
|
||||||
|
|
||||||
|
// Jump
|
||||||
|
characterControl.Jump = playerInputs.JumpPressed.IsSet(tick);
|
||||||
|
|
||||||
|
SystemAPI.SetComponent(player.ControlledCharacter, characterControl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 068c7fe0e7567404cb30b0d8715b4560
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 52b9553a57dc1e84fb7958bdbe268b3f
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3618e38bce9ef804a9830edc2f987f2b
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,60 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!1 &7568817337597995144
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 7568817337597995142}
|
||||||
|
- component: {fileID: 7568817337597995143}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: OrbitCamera
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &7568817337597995142
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 7568817337597995144}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 1.09, z: -3.54}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_RootOrder: 0
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!114 &7568817337597995143
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 7568817337597995144}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 70c323b4be4b1fa4089d1a1fd2872754, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
RotationSpeed: 2
|
||||||
|
MaxVAngle: 89
|
||||||
|
MinVAngle: -89
|
||||||
|
RotateWithCharacterParent: 1
|
||||||
|
StartDistance: 5
|
||||||
|
MinDistance: 0
|
||||||
|
MaxDistance: 10
|
||||||
|
DistanceMovementSpeed: 1
|
||||||
|
DistanceMovementSharpness: 20
|
||||||
|
ObstructionRadius: 0.1
|
||||||
|
ObstructionInnerSmoothingSharpness: 3.4028235e+38
|
||||||
|
ObstructionOuterSmoothingSharpness: 5
|
||||||
|
PreventFixedUpdateJitter: 1
|
||||||
|
IgnoredEntities: []
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 492a184cc1501fe4da86d69b5eddc366
|
||||||
|
PrefabImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,332 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!1 &1692896102597148395
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 1692896102597148394}
|
||||||
|
- component: {fileID: 8041698241194078798}
|
||||||
|
- component: {fileID: 6689285571920954877}
|
||||||
|
- component: {fileID: 7542772330835976783}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: ThirdPersonCharacter
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &1692896102597148394
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1692896102597148395}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children:
|
||||||
|
- {fileID: 1692896103431116737}
|
||||||
|
- {fileID: 2861637503494133750}
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_RootOrder: 0
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!136 &8041698241194078798
|
||||||
|
CapsuleCollider:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1692896102597148395}
|
||||||
|
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: 2
|
||||||
|
m_Radius: 0.5
|
||||||
|
m_Height: 2
|
||||||
|
m_Direction: 1
|
||||||
|
m_Center: {x: 0, y: 1, z: 0}
|
||||||
|
--- !u!114 &6689285571920954877
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1692896102597148395}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: c854a728d43c7cf47bec103607a449f9, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
CharacterProperties:
|
||||||
|
CustomPhysicsBodyTags:
|
||||||
|
Tag00: 0
|
||||||
|
Tag01: 0
|
||||||
|
Tag02: 0
|
||||||
|
Tag03: 0
|
||||||
|
Tag04: 0
|
||||||
|
Tag05: 0
|
||||||
|
Tag06: 0
|
||||||
|
Tag07: 0
|
||||||
|
InterpolatePosition: 1
|
||||||
|
InterpolateRotation: 0
|
||||||
|
EvaluateGrounding: 1
|
||||||
|
SnapToGround: 1
|
||||||
|
GroundSnappingDistance: 0.5
|
||||||
|
EnhancedGroundPrecision: 0
|
||||||
|
MaxGroundedSlopeAngle: 60
|
||||||
|
DetectMovementCollisions: 1
|
||||||
|
DecollideFromOverlaps: 1
|
||||||
|
ProjectVelocityOnInitialOverlaps: 0
|
||||||
|
MaxContinuousCollisionsIterations: 8
|
||||||
|
MaxOverlapDecollisionIterations: 2
|
||||||
|
DiscardMovementWhenExceedMaxIterations: 1
|
||||||
|
KillVelocityWhenExceedMaxIterations: 1
|
||||||
|
DetectObstructionsForParentBodyMovement: 0
|
||||||
|
SimulateDynamicBody: 1
|
||||||
|
Mass: 1
|
||||||
|
RotationSharpness: 25
|
||||||
|
GroundMaxSpeed: 10
|
||||||
|
GroundedMovementSharpness: 15
|
||||||
|
AirAcceleration: 50
|
||||||
|
AirMaxSpeed: 10
|
||||||
|
AirDrag: 0
|
||||||
|
JumpSpeed: 10
|
||||||
|
Gravity:
|
||||||
|
x: -0
|
||||||
|
y: -30
|
||||||
|
z: -0
|
||||||
|
PreventAirAccelerationAgainstUngroundedHits: 1
|
||||||
|
StepAndSlopeHandling:
|
||||||
|
StepHandling: 0
|
||||||
|
MaxStepHeight: 0.5
|
||||||
|
ExtraStepChecksDistance: 0.1
|
||||||
|
CharacterWidthForStepGroundingCheck: 1
|
||||||
|
PreventGroundingWhenMovingTowardsNoGrounding: 1
|
||||||
|
HasMaxDownwardSlopeChangeAngle: 0
|
||||||
|
MaxDownwardSlopeChangeAngle: 90
|
||||||
|
ConstrainVelocityToGroundPlane: 1
|
||||||
|
--- !u!114 &7542772330835976783
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1692896102597148395}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: d3a88336df575c34e80048c54a815367, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
Target: {fileID: 2861637503494133753}
|
||||||
|
--- !u!1 &1692896103431116738
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 1692896103431116737}
|
||||||
|
- component: {fileID: 1692896103431116743}
|
||||||
|
- component: {fileID: 1692896103431116736}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: Capsule
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &1692896103431116737
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1692896103431116738}
|
||||||
|
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: 6498846982015491111}
|
||||||
|
m_Father: {fileID: 1692896102597148394}
|
||||||
|
m_RootOrder: 0
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!33 &1692896103431116743
|
||||||
|
MeshFilter:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1692896103431116738}
|
||||||
|
m_Mesh: {fileID: 10208, guid: 0000000000000000e000000000000000, type: 0}
|
||||||
|
--- !u!23 &1692896103431116736
|
||||||
|
MeshRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1692896103431116738}
|
||||||
|
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_RenderingLayerMask: 257
|
||||||
|
m_RendererPriority: 0
|
||||||
|
m_Materials:
|
||||||
|
- {fileID: 2100000, guid: 70c3442346d77cb4781288146feb488a, type: 2}
|
||||||
|
m_StaticBatchInfo:
|
||||||
|
firstSubMesh: 0
|
||||||
|
subMeshCount: 0
|
||||||
|
m_StaticBatchRoot: {fileID: 0}
|
||||||
|
m_ProbeAnchor: {fileID: 0}
|
||||||
|
m_LightProbeVolumeOverride: {fileID: 0}
|
||||||
|
m_ScaleInLightmap: 1
|
||||||
|
m_ReceiveGI: 1
|
||||||
|
m_PreserveUVs: 0
|
||||||
|
m_IgnoreNormalsForChartDetection: 0
|
||||||
|
m_ImportantGI: 0
|
||||||
|
m_StitchLightmapSeams: 1
|
||||||
|
m_SelectedEditorRenderState: 3
|
||||||
|
m_MinimumChartSize: 4
|
||||||
|
m_AutoUVMaxDistance: 0.5
|
||||||
|
m_AutoUVMaxAngle: 89
|
||||||
|
m_LightmapParameters: {fileID: 0}
|
||||||
|
m_SortingLayerID: 0
|
||||||
|
m_SortingLayer: 0
|
||||||
|
m_SortingOrder: 0
|
||||||
|
m_AdditionalVertexStreams: {fileID: 0}
|
||||||
|
--- !u!1 &2787829476024719926
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 6498846982015491111}
|
||||||
|
- component: {fileID: 6362252827327739790}
|
||||||
|
- component: {fileID: 1601238720869374913}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: Cylinder
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &6498846982015491111
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2787829476024719926}
|
||||||
|
m_LocalRotation: {x: -0.70710677, y: -0, z: -0, w: 0.7071068}
|
||||||
|
m_LocalPosition: {x: 0, y: 0.487, z: 0.357}
|
||||||
|
m_LocalScale: {x: 0.78007, y: 0.17738, z: 0.34445}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 1692896103431116737}
|
||||||
|
m_RootOrder: 0
|
||||||
|
m_LocalEulerAnglesHint: {x: -90, y: 0, z: 0}
|
||||||
|
--- !u!33 &6362252827327739790
|
||||||
|
MeshFilter:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2787829476024719926}
|
||||||
|
m_Mesh: {fileID: 10206, guid: 0000000000000000e000000000000000, type: 0}
|
||||||
|
--- !u!23 &1601238720869374913
|
||||||
|
MeshRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2787829476024719926}
|
||||||
|
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_RenderingLayerMask: 257
|
||||||
|
m_RendererPriority: 0
|
||||||
|
m_Materials:
|
||||||
|
- {fileID: 2100000, guid: 70c3442346d77cb4781288146feb488a, type: 2}
|
||||||
|
m_StaticBatchInfo:
|
||||||
|
firstSubMesh: 0
|
||||||
|
subMeshCount: 0
|
||||||
|
m_StaticBatchRoot: {fileID: 0}
|
||||||
|
m_ProbeAnchor: {fileID: 0}
|
||||||
|
m_LightProbeVolumeOverride: {fileID: 0}
|
||||||
|
m_ScaleInLightmap: 1
|
||||||
|
m_ReceiveGI: 1
|
||||||
|
m_PreserveUVs: 0
|
||||||
|
m_IgnoreNormalsForChartDetection: 0
|
||||||
|
m_ImportantGI: 0
|
||||||
|
m_StitchLightmapSeams: 1
|
||||||
|
m_SelectedEditorRenderState: 3
|
||||||
|
m_MinimumChartSize: 4
|
||||||
|
m_AutoUVMaxDistance: 0.5
|
||||||
|
m_AutoUVMaxAngle: 89
|
||||||
|
m_LightmapParameters: {fileID: 0}
|
||||||
|
m_SortingLayerID: 0
|
||||||
|
m_SortingLayer: 0
|
||||||
|
m_SortingOrder: 0
|
||||||
|
m_AdditionalVertexStreams: {fileID: 0}
|
||||||
|
--- !u!1 &2861637503494133753
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 2861637503494133750}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: CameraTarget
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &2861637503494133750
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2861637503494133753}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 1.2, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 1692896102597148394}
|
||||||
|
m_RootOrder: 1
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5fbcc801dea8fd640a004697d22ed448
|
||||||
|
PrefabImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,48 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!1 &4729649056687684238
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 4729649056687684239}
|
||||||
|
- component: {fileID: 5910332505473654983}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: ThirdPersonPlayer
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &4729649056687684239
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 4729649056687684238}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_RootOrder: 0
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!114 &5910332505473654983
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 4729649056687684238}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 3fbdb3174a73a07408595a85d3e7fb6a, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
ControlledCharacter: {fileID: 0}
|
||||||
|
ControlledCamera: {fileID: 0}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 65701a63aea96444fa3a4b2ed4edbb25
|
||||||
|
PrefabImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 160196554b17cd743aac83686c6eb5dc
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d266609e8af72ea41909b7a326478e84
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
using Unity.Collections;
|
||||||
|
using Unity.Entities;
|
||||||
|
using Unity.Mathematics;
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public struct CameraTarget : IComponentData
|
||||||
|
{
|
||||||
|
public Entity TargetEntity;
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 74ff9a59933a5494bbc1bb465a5f2180
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using Unity.Entities;
|
||||||
|
|
||||||
|
[DisallowMultipleComponent]
|
||||||
|
public class CameraTargetAuthoring : MonoBehaviour
|
||||||
|
{
|
||||||
|
public GameObject Target;
|
||||||
|
|
||||||
|
public class Baker : Baker<CameraTargetAuthoring>
|
||||||
|
{
|
||||||
|
public override void Bake(CameraTargetAuthoring authoring)
|
||||||
|
{
|
||||||
|
Entity entity = GetEntity(TransformUsageFlags.Dynamic);
|
||||||
|
AddComponent(entity, new CameraTarget
|
||||||
|
{
|
||||||
|
TargetEntity = GetEntity(authoring.Target, TransformUsageFlags.Dynamic),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d3a88336df575c34e80048c54a815367
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
using System;
|
||||||
|
using Unity.Collections;
|
||||||
|
using Unity.Entities;
|
||||||
|
using Unity.Mathematics;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public struct OrbitCamera : IComponentData
|
||||||
|
{
|
||||||
|
public float RotationSpeed;
|
||||||
|
public float MaxVAngle;
|
||||||
|
public float MinVAngle;
|
||||||
|
public bool RotateWithCharacterParent;
|
||||||
|
|
||||||
|
public float MinDistance;
|
||||||
|
public float MaxDistance;
|
||||||
|
public float DistanceMovementSpeed;
|
||||||
|
public float DistanceMovementSharpness;
|
||||||
|
|
||||||
|
public float ObstructionRadius;
|
||||||
|
public float ObstructionInnerSmoothingSharpness;
|
||||||
|
public float ObstructionOuterSmoothingSharpness;
|
||||||
|
public bool PreventFixedUpdateJitter;
|
||||||
|
|
||||||
|
public float TargetDistance;
|
||||||
|
public float SmoothedTargetDistance;
|
||||||
|
public float ObstructedDistance;
|
||||||
|
public float PitchAngle;
|
||||||
|
public float3 PlanarForward;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public struct OrbitCameraControl : IComponentData
|
||||||
|
{
|
||||||
|
public Entity FollowedCharacterEntity;
|
||||||
|
public float2 LookDegreesDelta;
|
||||||
|
public float ZoomDelta;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public struct OrbitCameraIgnoredEntityBufferElement : IBufferElementData
|
||||||
|
{
|
||||||
|
public Entity Entity;
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 441900b2dca2cda429cba5f372fcf5fe
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,75 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Unity.Entities;
|
||||||
|
using Unity.Mathematics;
|
||||||
|
using Unity.Transforms;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
[DisallowMultipleComponent]
|
||||||
|
public class OrbitCameraAuthoring : MonoBehaviour
|
||||||
|
{
|
||||||
|
[Header("Rotation")]
|
||||||
|
public float RotationSpeed = 2f;
|
||||||
|
public float MaxVAngle = 89f;
|
||||||
|
public float MinVAngle = -89f;
|
||||||
|
public bool RotateWithCharacterParent = true;
|
||||||
|
|
||||||
|
[Header("Distance")]
|
||||||
|
public float StartDistance = 5f;
|
||||||
|
public float MinDistance = 0f;
|
||||||
|
public float MaxDistance = 10f;
|
||||||
|
public float DistanceMovementSpeed = 1f;
|
||||||
|
public float DistanceMovementSharpness = 20f;
|
||||||
|
|
||||||
|
[Header("Obstructions")]
|
||||||
|
public float ObstructionRadius = 0.1f;
|
||||||
|
public float ObstructionInnerSmoothingSharpness = float.MaxValue;
|
||||||
|
public float ObstructionOuterSmoothingSharpness = 5f;
|
||||||
|
public bool PreventFixedUpdateJitter = true;
|
||||||
|
|
||||||
|
[Header("Misc")]
|
||||||
|
public List<GameObject> IgnoredEntities = new List<GameObject>();
|
||||||
|
|
||||||
|
public class Baker : Baker<OrbitCameraAuthoring>
|
||||||
|
{
|
||||||
|
public override void Bake(OrbitCameraAuthoring authoring)
|
||||||
|
{
|
||||||
|
Entity entity = GetEntity(TransformUsageFlags.Dynamic | TransformUsageFlags.WorldSpace);
|
||||||
|
|
||||||
|
AddComponent(entity, new OrbitCamera
|
||||||
|
{
|
||||||
|
RotationSpeed = authoring.RotationSpeed,
|
||||||
|
MaxVAngle = authoring.MaxVAngle,
|
||||||
|
MinVAngle = authoring.MinVAngle,
|
||||||
|
RotateWithCharacterParent = authoring.RotateWithCharacterParent,
|
||||||
|
|
||||||
|
MinDistance = authoring.MinDistance,
|
||||||
|
MaxDistance = authoring.MaxDistance,
|
||||||
|
DistanceMovementSpeed = authoring.DistanceMovementSpeed,
|
||||||
|
DistanceMovementSharpness = authoring.DistanceMovementSharpness,
|
||||||
|
|
||||||
|
ObstructionRadius = authoring.ObstructionRadius,
|
||||||
|
ObstructionInnerSmoothingSharpness = authoring.ObstructionInnerSmoothingSharpness,
|
||||||
|
ObstructionOuterSmoothingSharpness = authoring.ObstructionOuterSmoothingSharpness,
|
||||||
|
PreventFixedUpdateJitter = authoring.PreventFixedUpdateJitter,
|
||||||
|
|
||||||
|
TargetDistance = authoring.StartDistance,
|
||||||
|
SmoothedTargetDistance = authoring.StartDistance,
|
||||||
|
ObstructedDistance = authoring.StartDistance,
|
||||||
|
|
||||||
|
PitchAngle = 0f,
|
||||||
|
PlanarForward = -math.forward(),
|
||||||
|
});
|
||||||
|
|
||||||
|
AddComponent(entity, new OrbitCameraControl());
|
||||||
|
|
||||||
|
DynamicBuffer<OrbitCameraIgnoredEntityBufferElement> ignoredEntitiesBuffer = AddBuffer<OrbitCameraIgnoredEntityBufferElement>(entity);
|
||||||
|
for (int i = 0; i < authoring.IgnoredEntities.Count; i++)
|
||||||
|
{
|
||||||
|
ignoredEntitiesBuffer.Add(new OrbitCameraIgnoredEntityBufferElement
|
||||||
|
{
|
||||||
|
Entity = GetEntity(authoring.IgnoredEntities[i], TransformUsageFlags.None),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 70c323b4be4b1fa4089d1a1fd2872754
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,367 @@
|
|||||||
|
using Unity.Burst;
|
||||||
|
using Unity.Collections;
|
||||||
|
using Unity.Entities;
|
||||||
|
using Unity.Mathematics;
|
||||||
|
using Unity.Physics;
|
||||||
|
using Unity.Transforms;
|
||||||
|
using Unity.CharacterController;
|
||||||
|
|
||||||
|
[UpdateInGroup(typeof(SimulationSystemGroup))]
|
||||||
|
[UpdateAfter(typeof(FixedStepSimulationSystemGroup))]
|
||||||
|
[UpdateAfter(typeof(ThirdPersonPlayerVariableStepControlSystem))]
|
||||||
|
[UpdateAfter(typeof(ThirdPersonCharacterVariableUpdateSystem))]
|
||||||
|
[UpdateBefore(typeof(TransformSystemGroup))]
|
||||||
|
[BurstCompile]
|
||||||
|
public partial struct OrbitCameraSimulationSystem : ISystem
|
||||||
|
{
|
||||||
|
[BurstCompile]
|
||||||
|
public void OnCreate(ref SystemState state)
|
||||||
|
{
|
||||||
|
state.RequireForUpdate(SystemAPI.QueryBuilder().WithAll<OrbitCamera, OrbitCameraControl>().Build());
|
||||||
|
}
|
||||||
|
|
||||||
|
[BurstCompile]
|
||||||
|
public void OnUpdate(ref SystemState state)
|
||||||
|
{
|
||||||
|
OrbitCameraSimulationJob job = new OrbitCameraSimulationJob
|
||||||
|
{
|
||||||
|
DeltaTime = SystemAPI.Time.DeltaTime,
|
||||||
|
LocalTransformLookup = SystemAPI.GetComponentLookup<LocalTransform>(false),
|
||||||
|
ParentLookup = SystemAPI.GetComponentLookup<Parent>(true),
|
||||||
|
PostTransformMatrixLookup = SystemAPI.GetComponentLookup<PostTransformMatrix>(true),
|
||||||
|
CameraTargetLookup = SystemAPI.GetComponentLookup<CameraTarget>(true),
|
||||||
|
KinematicCharacterBodyLookup = SystemAPI.GetComponentLookup<KinematicCharacterBody>(true),
|
||||||
|
};
|
||||||
|
job.Schedule();
|
||||||
|
}
|
||||||
|
|
||||||
|
[BurstCompile]
|
||||||
|
[WithAll(typeof(Simulate))]
|
||||||
|
public partial struct OrbitCameraSimulationJob : IJobEntity
|
||||||
|
{
|
||||||
|
public float DeltaTime;
|
||||||
|
|
||||||
|
public ComponentLookup<LocalTransform> LocalTransformLookup;
|
||||||
|
[ReadOnly] public ComponentLookup<Parent> ParentLookup;
|
||||||
|
[ReadOnly] public ComponentLookup<PostTransformMatrix> PostTransformMatrixLookup;
|
||||||
|
[ReadOnly] public ComponentLookup<CameraTarget> CameraTargetLookup;
|
||||||
|
[ReadOnly] public ComponentLookup<KinematicCharacterBody> KinematicCharacterBodyLookup;
|
||||||
|
|
||||||
|
void Execute(Entity entity, ref OrbitCamera orbitCamera, in OrbitCameraControl cameraControl)
|
||||||
|
{
|
||||||
|
if (OrbitCameraUtilities.TryGetCameraTargetSimulationWorldTransform(
|
||||||
|
cameraControl.FollowedCharacterEntity,
|
||||||
|
ref LocalTransformLookup,
|
||||||
|
ref ParentLookup,
|
||||||
|
ref PostTransformMatrixLookup,
|
||||||
|
ref CameraTargetLookup,
|
||||||
|
out float4x4 targetWorldTransform))
|
||||||
|
{
|
||||||
|
float3 targetUp = targetWorldTransform.Up();
|
||||||
|
float3 targetPosition = targetWorldTransform.Translation();
|
||||||
|
|
||||||
|
// Update planar forward based on target up direction and rotation from parent
|
||||||
|
{
|
||||||
|
quaternion tmpPlanarRotation = MathUtilities.CreateRotationWithUpPriority(targetUp, orbitCamera.PlanarForward);
|
||||||
|
|
||||||
|
// Rotation from character parent
|
||||||
|
if (orbitCamera.RotateWithCharacterParent &&
|
||||||
|
KinematicCharacterBodyLookup.TryGetComponent(cameraControl.FollowedCharacterEntity, out KinematicCharacterBody characterBody))
|
||||||
|
{
|
||||||
|
// Only consider rotation around the character up, since the camera is already adjusting itself to character up
|
||||||
|
quaternion planarRotationFromParent = characterBody.RotationFromParent;
|
||||||
|
KinematicCharacterUtilities.AddVariableRateRotationFromFixedRateRotation(ref tmpPlanarRotation, planarRotationFromParent, DeltaTime, characterBody.LastPhysicsUpdateDeltaTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
orbitCamera.PlanarForward = MathUtilities.GetForwardFromRotation(tmpPlanarRotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Yaw
|
||||||
|
float yawAngleChange = cameraControl.LookDegreesDelta.x * orbitCamera.RotationSpeed;
|
||||||
|
quaternion yawRotation = quaternion.Euler(targetUp * math.radians(yawAngleChange));
|
||||||
|
orbitCamera.PlanarForward = math.rotate(yawRotation, orbitCamera.PlanarForward);
|
||||||
|
|
||||||
|
// Pitch
|
||||||
|
orbitCamera.PitchAngle += -cameraControl.LookDegreesDelta.y * orbitCamera.RotationSpeed;
|
||||||
|
orbitCamera.PitchAngle = math.clamp(orbitCamera.PitchAngle, orbitCamera.MinVAngle, orbitCamera.MaxVAngle);
|
||||||
|
|
||||||
|
// Calculate final rotation
|
||||||
|
quaternion cameraRotation = OrbitCameraUtilities.CalculateCameraRotation(targetUp, orbitCamera.PlanarForward, orbitCamera.PitchAngle);
|
||||||
|
|
||||||
|
// Distance input
|
||||||
|
float desiredDistanceMovementFromInput = cameraControl.ZoomDelta * orbitCamera.DistanceMovementSpeed;
|
||||||
|
orbitCamera.TargetDistance = math.clamp(orbitCamera.TargetDistance + desiredDistanceMovementFromInput, orbitCamera.MinDistance, orbitCamera.MaxDistance);
|
||||||
|
|
||||||
|
// Calculate camera position (no smoothing or obstructions yet; these are done in the camera late update)
|
||||||
|
float3 cameraPosition = OrbitCameraUtilities.CalculateCameraPosition(targetPosition, cameraRotation, orbitCamera.TargetDistance);
|
||||||
|
|
||||||
|
// Write back to component
|
||||||
|
LocalTransformLookup[entity] = LocalTransform.FromPositionRotation(cameraPosition, cameraRotation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[UpdateInGroup(typeof(SimulationSystemGroup))]
|
||||||
|
[UpdateAfter(typeof(TransformSystemGroup))]
|
||||||
|
[BurstCompile]
|
||||||
|
public partial struct OrbitCameraLateUpdateSystem : ISystem
|
||||||
|
{
|
||||||
|
[BurstCompile]
|
||||||
|
public void OnCreate(ref SystemState state)
|
||||||
|
{
|
||||||
|
state.RequireForUpdate<PhysicsWorldSingleton>();
|
||||||
|
state.RequireForUpdate(SystemAPI.QueryBuilder().WithAll<OrbitCamera, OrbitCameraControl>().Build());
|
||||||
|
}
|
||||||
|
|
||||||
|
[BurstCompile]
|
||||||
|
public void OnUpdate(ref SystemState state)
|
||||||
|
{
|
||||||
|
OrbitCameraLateUpdateJob job = new OrbitCameraLateUpdateJob
|
||||||
|
{
|
||||||
|
DeltaTime = SystemAPI.Time.DeltaTime,
|
||||||
|
PhysicsWorld = SystemAPI.GetSingleton<PhysicsWorldSingleton>().PhysicsWorld,
|
||||||
|
LocalToWorldLookup = SystemAPI.GetComponentLookup<LocalToWorld>(false),
|
||||||
|
CameraTargetLookup = SystemAPI.GetComponentLookup<CameraTarget>(true),
|
||||||
|
KinematicCharacterBodyLookup = SystemAPI.GetComponentLookup<KinematicCharacterBody>(true),
|
||||||
|
};
|
||||||
|
job.Schedule();
|
||||||
|
}
|
||||||
|
|
||||||
|
[BurstCompile]
|
||||||
|
[WithAll(typeof(Simulate))]
|
||||||
|
public partial struct OrbitCameraLateUpdateJob : IJobEntity
|
||||||
|
{
|
||||||
|
public float DeltaTime;
|
||||||
|
[ReadOnly]
|
||||||
|
public PhysicsWorld PhysicsWorld;
|
||||||
|
|
||||||
|
public ComponentLookup<LocalToWorld> LocalToWorldLookup;
|
||||||
|
[ReadOnly]
|
||||||
|
public ComponentLookup<CameraTarget> CameraTargetLookup;
|
||||||
|
[ReadOnly]
|
||||||
|
public ComponentLookup<KinematicCharacterBody> KinematicCharacterBodyLookup;
|
||||||
|
|
||||||
|
void Execute(
|
||||||
|
Entity entity,
|
||||||
|
ref OrbitCamera orbitCamera,
|
||||||
|
in OrbitCameraControl cameraControl,
|
||||||
|
in DynamicBuffer<OrbitCameraIgnoredEntityBufferElement> ignoredEntitiesBuffer)
|
||||||
|
{
|
||||||
|
if (OrbitCameraUtilities.TryGetCameraTargetInterpolatedWorldTransform(
|
||||||
|
cameraControl.FollowedCharacterEntity,
|
||||||
|
ref LocalToWorldLookup,
|
||||||
|
ref CameraTargetLookup,
|
||||||
|
out LocalToWorld targetWorldTransform))
|
||||||
|
{
|
||||||
|
quaternion cameraRotation = OrbitCameraUtilities.CalculateCameraRotation(targetWorldTransform.Up, orbitCamera.PlanarForward, orbitCamera.PitchAngle);
|
||||||
|
|
||||||
|
float3 cameraForward = math.mul(cameraRotation, math.forward());
|
||||||
|
float3 targetPosition = targetWorldTransform.Position;
|
||||||
|
|
||||||
|
// Distance smoothing
|
||||||
|
orbitCamera.SmoothedTargetDistance = math.lerp(orbitCamera.SmoothedTargetDistance, orbitCamera.TargetDistance, MathUtilities.GetSharpnessInterpolant(orbitCamera.DistanceMovementSharpness, DeltaTime));
|
||||||
|
|
||||||
|
// Obstruction handling
|
||||||
|
// Obstruction detection is handled here, because we have to adjust the obstruction distance
|
||||||
|
// to match the interpolated physics body transform (as opposed to the "simulation" transform). Otherwise, a
|
||||||
|
// camera getting obstructed by a moving physics body would have visible jitter.
|
||||||
|
if (orbitCamera.ObstructionRadius > 0f)
|
||||||
|
{
|
||||||
|
float obstructionCheckDistance = orbitCamera.SmoothedTargetDistance;
|
||||||
|
|
||||||
|
CameraObstructionHitsCollector collector = new CameraObstructionHitsCollector(cameraControl.FollowedCharacterEntity, ignoredEntitiesBuffer, cameraForward);
|
||||||
|
PhysicsWorld.SphereCastCustom(
|
||||||
|
targetPosition,
|
||||||
|
orbitCamera.ObstructionRadius,
|
||||||
|
-cameraForward,
|
||||||
|
obstructionCheckDistance,
|
||||||
|
ref collector,
|
||||||
|
CollisionFilter.Default,
|
||||||
|
QueryInteraction.IgnoreTriggers);
|
||||||
|
|
||||||
|
float newObstructedDistance = obstructionCheckDistance;
|
||||||
|
if (collector.NumHits > 0)
|
||||||
|
{
|
||||||
|
newObstructedDistance = obstructionCheckDistance * collector.ClosestHit.Fraction;
|
||||||
|
|
||||||
|
// Redo cast with the interpolated body transform to prevent FixedUpdate jitter in obstruction detection
|
||||||
|
if (orbitCamera.PreventFixedUpdateJitter)
|
||||||
|
{
|
||||||
|
RigidBody hitBody = PhysicsWorld.Bodies[collector.ClosestHit.RigidBodyIndex];
|
||||||
|
if (LocalToWorldLookup.TryGetComponent(hitBody.Entity, out LocalToWorld hitBodyLocalToWorld))
|
||||||
|
{
|
||||||
|
// Adjust the rigidbody transform for interpolation, so we can raycast it in that state
|
||||||
|
hitBody.WorldFromBody = new RigidTransform(quaternion.LookRotationSafe(hitBodyLocalToWorld.Forward, hitBodyLocalToWorld.Up), hitBodyLocalToWorld.Position);
|
||||||
|
|
||||||
|
collector = new CameraObstructionHitsCollector(cameraControl.FollowedCharacterEntity, ignoredEntitiesBuffer, cameraForward);
|
||||||
|
hitBody.SphereCastCustom(
|
||||||
|
targetPosition,
|
||||||
|
orbitCamera.ObstructionRadius,
|
||||||
|
-cameraForward,
|
||||||
|
obstructionCheckDistance,
|
||||||
|
ref collector,
|
||||||
|
CollisionFilter.Default,
|
||||||
|
QueryInteraction.IgnoreTriggers);
|
||||||
|
|
||||||
|
if (collector.NumHits > 0)
|
||||||
|
{
|
||||||
|
newObstructedDistance = obstructionCheckDistance * collector.ClosestHit.Fraction;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update current distance based on obstructed distance
|
||||||
|
if (orbitCamera.ObstructedDistance < newObstructedDistance)
|
||||||
|
{
|
||||||
|
// Move outer
|
||||||
|
orbitCamera.ObstructedDistance = math.lerp(orbitCamera.ObstructedDistance, newObstructedDistance, MathUtilities.GetSharpnessInterpolant(orbitCamera.ObstructionOuterSmoothingSharpness, DeltaTime));
|
||||||
|
}
|
||||||
|
else if (orbitCamera.ObstructedDistance > newObstructedDistance)
|
||||||
|
{
|
||||||
|
// Move inner
|
||||||
|
orbitCamera.ObstructedDistance = math.lerp(orbitCamera.ObstructedDistance, newObstructedDistance, MathUtilities.GetSharpnessInterpolant(orbitCamera.ObstructionInnerSmoothingSharpness, DeltaTime));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
orbitCamera.ObstructedDistance = orbitCamera.SmoothedTargetDistance;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Place camera at the final distance (includes smoothing and obstructions)
|
||||||
|
float3 cameraPosition = OrbitCameraUtilities.CalculateCameraPosition(targetPosition, cameraRotation, orbitCamera.ObstructedDistance);
|
||||||
|
|
||||||
|
// Write to LtW
|
||||||
|
LocalToWorldLookup[entity] = new LocalToWorld { Value = new float4x4(cameraRotation, cameraPosition) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class OrbitCameraUtilities
|
||||||
|
{
|
||||||
|
public static bool TryGetCameraTargetSimulationWorldTransform(
|
||||||
|
Entity targetCharacterEntity,
|
||||||
|
ref ComponentLookup<LocalTransform> localTransformLookup,
|
||||||
|
ref ComponentLookup<Parent> parentLookup,
|
||||||
|
ref ComponentLookup<PostTransformMatrix> postTransformMatrixLookup,
|
||||||
|
ref ComponentLookup<CameraTarget> cameraTargetLookup,
|
||||||
|
out float4x4 worldTransform)
|
||||||
|
{
|
||||||
|
bool foundValidCameraTarget = false;
|
||||||
|
worldTransform = float4x4.identity;
|
||||||
|
|
||||||
|
// Camera target is either defined by the CameraTarget component, or if not, the transform of the followed character
|
||||||
|
if (cameraTargetLookup.TryGetComponent(targetCharacterEntity, out CameraTarget cameraTarget) &&
|
||||||
|
localTransformLookup.HasComponent(cameraTarget.TargetEntity))
|
||||||
|
{
|
||||||
|
TransformHelpers.ComputeWorldTransformMatrix(
|
||||||
|
cameraTarget.TargetEntity,
|
||||||
|
out worldTransform,
|
||||||
|
ref localTransformLookup,
|
||||||
|
ref parentLookup,
|
||||||
|
ref postTransformMatrixLookup);
|
||||||
|
foundValidCameraTarget = true;
|
||||||
|
}
|
||||||
|
else if (localTransformLookup.TryGetComponent(targetCharacterEntity, out LocalTransform characterLocalTransform))
|
||||||
|
{
|
||||||
|
worldTransform = float4x4.TRS(characterLocalTransform.Position, characterLocalTransform.Rotation, 1f);
|
||||||
|
foundValidCameraTarget = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return foundValidCameraTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool TryGetCameraTargetInterpolatedWorldTransform(
|
||||||
|
Entity targetCharacterEntity,
|
||||||
|
ref ComponentLookup<LocalToWorld> localToWorldLookup,
|
||||||
|
ref ComponentLookup<CameraTarget> cameraTargetLookup,
|
||||||
|
out LocalToWorld worldTransform)
|
||||||
|
{
|
||||||
|
bool foundValidCameraTarget = false;
|
||||||
|
worldTransform = default;
|
||||||
|
|
||||||
|
// Get the interpolated transform of the target
|
||||||
|
if (cameraTargetLookup.TryGetComponent(targetCharacterEntity, out CameraTarget cameraTarget) &&
|
||||||
|
localToWorldLookup.TryGetComponent(cameraTarget.TargetEntity, out worldTransform))
|
||||||
|
{
|
||||||
|
foundValidCameraTarget = true;
|
||||||
|
}
|
||||||
|
else if (localToWorldLookup.TryGetComponent(targetCharacterEntity, out worldTransform))
|
||||||
|
{
|
||||||
|
foundValidCameraTarget = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return foundValidCameraTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static quaternion CalculateCameraRotation(float3 targetUp, float3 planarForward, float pitchAngle)
|
||||||
|
{
|
||||||
|
quaternion pitchRotation = quaternion.Euler(math.right() * math.radians(pitchAngle));
|
||||||
|
quaternion cameraRotation = MathUtilities.CreateRotationWithUpPriority(targetUp, planarForward);
|
||||||
|
cameraRotation = math.mul(cameraRotation, pitchRotation);
|
||||||
|
return cameraRotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float3 CalculateCameraPosition(float3 targetPosition, quaternion cameraRotation, float distance)
|
||||||
|
{
|
||||||
|
return targetPosition + (-MathUtilities.GetForwardFromRotation(cameraRotation) * distance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct CameraObstructionHitsCollector : ICollector<ColliderCastHit>
|
||||||
|
{
|
||||||
|
public bool EarlyOutOnFirstHit => false;
|
||||||
|
public float MaxFraction => 1f;
|
||||||
|
public int NumHits { get; private set; }
|
||||||
|
|
||||||
|
public ColliderCastHit ClosestHit;
|
||||||
|
|
||||||
|
private float _closestHitFraction;
|
||||||
|
private float3 _cameraDirection;
|
||||||
|
private Entity _followedCharacter;
|
||||||
|
private DynamicBuffer<OrbitCameraIgnoredEntityBufferElement> _ignoredEntitiesBuffer;
|
||||||
|
|
||||||
|
public CameraObstructionHitsCollector(Entity followedCharacter, DynamicBuffer<OrbitCameraIgnoredEntityBufferElement> ignoredEntitiesBuffer, float3 cameraDirection)
|
||||||
|
{
|
||||||
|
NumHits = 0;
|
||||||
|
ClosestHit = default;
|
||||||
|
|
||||||
|
_closestHitFraction = float.MaxValue;
|
||||||
|
_cameraDirection = cameraDirection;
|
||||||
|
_followedCharacter = followedCharacter;
|
||||||
|
_ignoredEntitiesBuffer = ignoredEntitiesBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddHit(ColliderCastHit hit)
|
||||||
|
{
|
||||||
|
if (_followedCharacter == hit.Entity)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (math.dot(hit.SurfaceNormal, _cameraDirection) < 0f || !PhysicsUtilities.IsCollidable(hit.Material))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < _ignoredEntitiesBuffer.Length; i++)
|
||||||
|
{
|
||||||
|
if (_ignoredEntitiesBuffer[i].Entity == hit.Entity)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process valid hit
|
||||||
|
if (hit.Fraction < _closestHitFraction)
|
||||||
|
{
|
||||||
|
_closestHitFraction = hit.Fraction;
|
||||||
|
ClosestHit = hit;
|
||||||
|
}
|
||||||
|
NumHits++;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6d6d36bc694f390408f5683be8de8c7d
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,224 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using Unity.Burst;
|
||||||
|
using Unity.Collections;
|
||||||
|
using Unity.Entities;
|
||||||
|
using Unity.CharacterController;
|
||||||
|
using Unity.Jobs;
|
||||||
|
using Unity.Mathematics;
|
||||||
|
using Unity.Physics;
|
||||||
|
using Unity.Physics.Authoring;
|
||||||
|
using Unity.Physics.Extensions;
|
||||||
|
using Unity.Physics.Systems;
|
||||||
|
using Unity.Transforms;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public struct ThirdPersonCharacterUpdateContext
|
||||||
|
{
|
||||||
|
// Here, you may add additional global data for your character updates, such as ComponentLookups, Singletons, NativeCollections, etc...
|
||||||
|
// The data you add here will be accessible in your character updates and all of your character "callbacks".
|
||||||
|
|
||||||
|
public void OnSystemCreate(ref SystemState state)
|
||||||
|
{
|
||||||
|
// Get lookups
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnSystemUpdate(ref SystemState state)
|
||||||
|
{
|
||||||
|
// Update lookups
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly partial struct ThirdPersonCharacterAspect : IAspect, IKinematicCharacterProcessor<ThirdPersonCharacterUpdateContext>
|
||||||
|
{
|
||||||
|
public readonly KinematicCharacterAspect CharacterAspect;
|
||||||
|
public readonly RefRW<ThirdPersonCharacterComponent> CharacterComponent;
|
||||||
|
public readonly RefRW<ThirdPersonCharacterControl> CharacterControl;
|
||||||
|
|
||||||
|
public void PhysicsUpdate(ref ThirdPersonCharacterUpdateContext context, ref KinematicCharacterUpdateContext baseContext)
|
||||||
|
{
|
||||||
|
ref ThirdPersonCharacterComponent characterComponent = ref CharacterComponent.ValueRW;
|
||||||
|
ref KinematicCharacterBody characterBody = ref CharacterAspect.CharacterBody.ValueRW;
|
||||||
|
ref float3 characterPosition = ref CharacterAspect.LocalTransform.ValueRW.Position;
|
||||||
|
|
||||||
|
// First phase of default character update
|
||||||
|
CharacterAspect.Update_Initialize(in this, ref context, ref baseContext, ref characterBody, baseContext.Time.DeltaTime);
|
||||||
|
CharacterAspect.Update_ParentMovement(in this, ref context, ref baseContext, ref characterBody, ref characterPosition, characterBody.WasGroundedBeforeCharacterUpdate);
|
||||||
|
CharacterAspect.Update_Grounding(in this, ref context, ref baseContext, ref characterBody, ref characterPosition);
|
||||||
|
|
||||||
|
// Update desired character velocity after grounding was detected, but before doing additional processing that depends on velocity
|
||||||
|
HandleVelocityControl(ref context, ref baseContext);
|
||||||
|
|
||||||
|
// Second phase of default character update
|
||||||
|
CharacterAspect.Update_PreventGroundingFromFutureSlopeChange(in this, ref context, ref baseContext, ref characterBody, in characterComponent.StepAndSlopeHandling);
|
||||||
|
CharacterAspect.Update_GroundPushing(in this, ref context, ref baseContext, characterComponent.Gravity);
|
||||||
|
CharacterAspect.Update_MovementAndDecollisions(in this, ref context, ref baseContext, ref characterBody, ref characterPosition);
|
||||||
|
CharacterAspect.Update_MovingPlatformDetection(ref baseContext, ref characterBody);
|
||||||
|
CharacterAspect.Update_ParentMomentum(ref baseContext, ref characterBody);
|
||||||
|
CharacterAspect.Update_ProcessStatefulCharacterHits();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleVelocityControl(ref ThirdPersonCharacterUpdateContext context, ref KinematicCharacterUpdateContext baseContext)
|
||||||
|
{
|
||||||
|
float deltaTime = baseContext.Time.DeltaTime;
|
||||||
|
ref KinematicCharacterBody characterBody = ref CharacterAspect.CharacterBody.ValueRW;
|
||||||
|
ref ThirdPersonCharacterComponent characterComponent = ref CharacterComponent.ValueRW;
|
||||||
|
ref ThirdPersonCharacterControl characterControl = ref CharacterControl.ValueRW;
|
||||||
|
|
||||||
|
// Rotate move input and velocity to take into account parent rotation
|
||||||
|
if(characterBody.ParentEntity != Entity.Null)
|
||||||
|
{
|
||||||
|
characterControl.MoveVector = math.rotate(characterBody.RotationFromParent, characterControl.MoveVector);
|
||||||
|
characterBody.RelativeVelocity = math.rotate(characterBody.RotationFromParent, characterBody.RelativeVelocity);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (characterBody.IsGrounded)
|
||||||
|
{
|
||||||
|
// Move on ground
|
||||||
|
float3 targetVelocity = characterControl.MoveVector * characterComponent.GroundMaxSpeed;
|
||||||
|
CharacterControlUtilities.StandardGroundMove_Interpolated(ref characterBody.RelativeVelocity, targetVelocity, characterComponent.GroundedMovementSharpness, deltaTime, characterBody.GroundingUp, characterBody.GroundHit.Normal);
|
||||||
|
|
||||||
|
// Jump
|
||||||
|
if (characterControl.Jump)
|
||||||
|
{
|
||||||
|
CharacterControlUtilities.StandardJump(ref characterBody, characterBody.GroundingUp * characterComponent.JumpSpeed, true, characterBody.GroundingUp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Move in air
|
||||||
|
float3 airAcceleration = characterControl.MoveVector * characterComponent.AirAcceleration;
|
||||||
|
if (math.lengthsq(airAcceleration) > 0f)
|
||||||
|
{
|
||||||
|
float3 tmpVelocity = characterBody.RelativeVelocity;
|
||||||
|
CharacterControlUtilities.StandardAirMove(ref characterBody.RelativeVelocity, airAcceleration, characterComponent.AirMaxSpeed, characterBody.GroundingUp, deltaTime, false);
|
||||||
|
|
||||||
|
// Cancel air acceleration from input if we would hit a non-grounded surface (prevents air-climbing slopes at high air accelerations)
|
||||||
|
if (characterComponent.PreventAirAccelerationAgainstUngroundedHits && CharacterAspect.MovementWouldHitNonGroundedObstruction(in this, ref context, ref baseContext, characterBody.RelativeVelocity * deltaTime, out ColliderCastHit hit))
|
||||||
|
{
|
||||||
|
characterBody.RelativeVelocity = tmpVelocity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gravity
|
||||||
|
CharacterControlUtilities.AccelerateVelocity(ref characterBody.RelativeVelocity, characterComponent.Gravity, deltaTime);
|
||||||
|
|
||||||
|
// Drag
|
||||||
|
CharacterControlUtilities.ApplyDragToVelocity(ref characterBody.RelativeVelocity, deltaTime, characterComponent.AirDrag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void VariableUpdate(ref ThirdPersonCharacterUpdateContext context, ref KinematicCharacterUpdateContext baseContext)
|
||||||
|
{
|
||||||
|
ref KinematicCharacterBody characterBody = ref CharacterAspect.CharacterBody.ValueRW;
|
||||||
|
ref ThirdPersonCharacterComponent characterComponent = ref CharacterComponent.ValueRW;
|
||||||
|
ref ThirdPersonCharacterControl characterControl = ref CharacterControl.ValueRW;
|
||||||
|
ref quaternion characterRotation = ref CharacterAspect.LocalTransform.ValueRW.Rotation;
|
||||||
|
|
||||||
|
// Add rotation from parent body to the character rotation
|
||||||
|
// (this is for allowing a rotating moving platform to rotate your character as well, and handle interpolation properly)
|
||||||
|
KinematicCharacterUtilities.AddVariableRateRotationFromFixedRateRotation(ref characterRotation, characterBody.RotationFromParent, baseContext.Time.DeltaTime, characterBody.LastPhysicsUpdateDeltaTime);
|
||||||
|
|
||||||
|
// Rotate towards move direction
|
||||||
|
if (math.lengthsq(characterControl.MoveVector) > 0f)
|
||||||
|
{
|
||||||
|
CharacterControlUtilities.SlerpRotationTowardsDirectionAroundUp(ref characterRotation, baseContext.Time.DeltaTime, math.normalizesafe(characterControl.MoveVector), MathUtilities.GetUpFromRotation(characterRotation), characterComponent.RotationSharpness);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Character Processor Callbacks
|
||||||
|
public void UpdateGroundingUp(
|
||||||
|
ref ThirdPersonCharacterUpdateContext context,
|
||||||
|
ref KinematicCharacterUpdateContext baseContext)
|
||||||
|
{
|
||||||
|
ref KinematicCharacterBody characterBody = ref CharacterAspect.CharacterBody.ValueRW;
|
||||||
|
|
||||||
|
CharacterAspect.Default_UpdateGroundingUp(ref characterBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CanCollideWithHit(
|
||||||
|
ref ThirdPersonCharacterUpdateContext context,
|
||||||
|
ref KinematicCharacterUpdateContext baseContext,
|
||||||
|
in BasicHit hit)
|
||||||
|
{
|
||||||
|
return PhysicsUtilities.IsCollidable(hit.Material);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsGroundedOnHit(
|
||||||
|
ref ThirdPersonCharacterUpdateContext context,
|
||||||
|
ref KinematicCharacterUpdateContext baseContext,
|
||||||
|
in BasicHit hit,
|
||||||
|
int groundingEvaluationType)
|
||||||
|
{
|
||||||
|
ThirdPersonCharacterComponent characterComponent = CharacterComponent.ValueRO;
|
||||||
|
|
||||||
|
return CharacterAspect.Default_IsGroundedOnHit(
|
||||||
|
in this,
|
||||||
|
ref context,
|
||||||
|
ref baseContext,
|
||||||
|
in hit,
|
||||||
|
in characterComponent.StepAndSlopeHandling,
|
||||||
|
groundingEvaluationType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnMovementHit(
|
||||||
|
ref ThirdPersonCharacterUpdateContext context,
|
||||||
|
ref KinematicCharacterUpdateContext baseContext,
|
||||||
|
ref KinematicCharacterHit hit,
|
||||||
|
ref float3 remainingMovementDirection,
|
||||||
|
ref float remainingMovementLength,
|
||||||
|
float3 originalVelocityDirection,
|
||||||
|
float hitDistance)
|
||||||
|
{
|
||||||
|
ref KinematicCharacterBody characterBody = ref CharacterAspect.CharacterBody.ValueRW;
|
||||||
|
ref float3 characterPosition = ref CharacterAspect.LocalTransform.ValueRW.Position;
|
||||||
|
ThirdPersonCharacterComponent characterComponent = CharacterComponent.ValueRO;
|
||||||
|
|
||||||
|
CharacterAspect.Default_OnMovementHit(
|
||||||
|
in this,
|
||||||
|
ref context,
|
||||||
|
ref baseContext,
|
||||||
|
ref characterBody,
|
||||||
|
ref characterPosition,
|
||||||
|
ref hit,
|
||||||
|
ref remainingMovementDirection,
|
||||||
|
ref remainingMovementLength,
|
||||||
|
originalVelocityDirection,
|
||||||
|
hitDistance,
|
||||||
|
characterComponent.StepAndSlopeHandling.StepHandling,
|
||||||
|
characterComponent.StepAndSlopeHandling.MaxStepHeight,
|
||||||
|
characterComponent.StepAndSlopeHandling.CharacterWidthForStepGroundingCheck);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OverrideDynamicHitMasses(
|
||||||
|
ref ThirdPersonCharacterUpdateContext context,
|
||||||
|
ref KinematicCharacterUpdateContext baseContext,
|
||||||
|
ref PhysicsMass characterMass,
|
||||||
|
ref PhysicsMass otherMass,
|
||||||
|
BasicHit hit)
|
||||||
|
{
|
||||||
|
// Custom mass overrides
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ProjectVelocityOnHits(
|
||||||
|
ref ThirdPersonCharacterUpdateContext context,
|
||||||
|
ref KinematicCharacterUpdateContext baseContext,
|
||||||
|
ref float3 velocity,
|
||||||
|
ref bool characterIsGrounded,
|
||||||
|
ref BasicHit characterGroundHit,
|
||||||
|
in DynamicBuffer<KinematicVelocityProjectionHit> velocityProjectionHits,
|
||||||
|
float3 originalVelocityDirection)
|
||||||
|
{
|
||||||
|
ThirdPersonCharacterComponent characterComponent = CharacterComponent.ValueRO;
|
||||||
|
|
||||||
|
CharacterAspect.Default_ProjectVelocityOnHits(
|
||||||
|
ref velocity,
|
||||||
|
ref characterIsGrounded,
|
||||||
|
ref characterGroundHit,
|
||||||
|
in velocityProjectionHits,
|
||||||
|
originalVelocityDirection,
|
||||||
|
characterComponent.StepAndSlopeHandling.ConstrainVelocityToGroundPlane);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2e1982b631c39194b8eaa4838ec11284
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,50 @@
|
|||||||
|
using Unity.Entities;
|
||||||
|
using Unity.Mathematics;
|
||||||
|
using Unity.Physics.Authoring;
|
||||||
|
using UnityEngine;
|
||||||
|
using Unity.CharacterController;
|
||||||
|
using Unity.Physics;
|
||||||
|
using UnityEngine.Serialization;
|
||||||
|
|
||||||
|
[DisallowMultipleComponent]
|
||||||
|
public class ThirdPersonCharacterAuthoring : MonoBehaviour
|
||||||
|
{
|
||||||
|
public AuthoringKinematicCharacterProperties CharacterProperties = AuthoringKinematicCharacterProperties.GetDefault();
|
||||||
|
|
||||||
|
public float RotationSharpness = 25f;
|
||||||
|
public float GroundMaxSpeed = 10f;
|
||||||
|
public float GroundedMovementSharpness = 15f;
|
||||||
|
public float AirAcceleration = 50f;
|
||||||
|
public float AirMaxSpeed = 10f;
|
||||||
|
public float AirDrag = 0f;
|
||||||
|
public float JumpSpeed = 10f;
|
||||||
|
public float3 Gravity = math.up() * -30f;
|
||||||
|
public bool PreventAirAccelerationAgainstUngroundedHits = true;
|
||||||
|
public BasicStepAndSlopeHandlingParameters StepAndSlopeHandling = BasicStepAndSlopeHandlingParameters.GetDefault();
|
||||||
|
|
||||||
|
public class Baker : Baker<ThirdPersonCharacterAuthoring>
|
||||||
|
{
|
||||||
|
public override void Bake(ThirdPersonCharacterAuthoring authoring)
|
||||||
|
{
|
||||||
|
KinematicCharacterUtilities.BakeCharacter(this, authoring.gameObject, authoring.CharacterProperties);
|
||||||
|
|
||||||
|
Entity entity = GetEntity(TransformUsageFlags.Dynamic | TransformUsageFlags.WorldSpace);
|
||||||
|
|
||||||
|
AddComponent(entity, new ThirdPersonCharacterComponent
|
||||||
|
{
|
||||||
|
RotationSharpness = authoring.RotationSharpness,
|
||||||
|
GroundMaxSpeed = authoring.GroundMaxSpeed,
|
||||||
|
GroundedMovementSharpness = authoring.GroundedMovementSharpness,
|
||||||
|
AirAcceleration = authoring.AirAcceleration,
|
||||||
|
AirMaxSpeed = authoring.AirMaxSpeed,
|
||||||
|
AirDrag = authoring.AirDrag,
|
||||||
|
JumpSpeed = authoring.JumpSpeed,
|
||||||
|
Gravity = authoring.Gravity,
|
||||||
|
PreventAirAccelerationAgainstUngroundedHits = authoring.PreventAirAccelerationAgainstUngroundedHits,
|
||||||
|
StepAndSlopeHandling = authoring.StepAndSlopeHandling,
|
||||||
|
});
|
||||||
|
AddComponent(entity, new ThirdPersonCharacterControl());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c854a728d43c7cf47bec103607a449f9
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using Unity.Collections;
|
||||||
|
using Unity.Entities;
|
||||||
|
using Unity.Mathematics;
|
||||||
|
using UnityEngine;
|
||||||
|
using Unity.CharacterController;
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public struct ThirdPersonCharacterComponent : IComponentData
|
||||||
|
{
|
||||||
|
public float RotationSharpness;
|
||||||
|
public float GroundMaxSpeed;
|
||||||
|
public float GroundedMovementSharpness;
|
||||||
|
public float AirAcceleration;
|
||||||
|
public float AirMaxSpeed;
|
||||||
|
public float AirDrag;
|
||||||
|
public float JumpSpeed;
|
||||||
|
public float3 Gravity;
|
||||||
|
public bool PreventAirAccelerationAgainstUngroundedHits;
|
||||||
|
public BasicStepAndSlopeHandlingParameters StepAndSlopeHandling;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public struct ThirdPersonCharacterControl : IComponentData
|
||||||
|
{
|
||||||
|
public float3 MoveVector;
|
||||||
|
public bool Jump;
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d8471dfde63584745b2234708055b211
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,137 @@
|
|||||||
|
using Unity.Burst;
|
||||||
|
using Unity.Entities;
|
||||||
|
using Unity.Collections;
|
||||||
|
using Unity.Jobs;
|
||||||
|
using Unity.Mathematics;
|
||||||
|
using Unity.Physics;
|
||||||
|
using Unity.Transforms;
|
||||||
|
using Unity.CharacterController;
|
||||||
|
using Unity.Burst.Intrinsics;
|
||||||
|
|
||||||
|
[UpdateInGroup(typeof(KinematicCharacterPhysicsUpdateGroup))]
|
||||||
|
[BurstCompile]
|
||||||
|
public partial struct ThirdPersonCharacterPhysicsUpdateSystem : ISystem
|
||||||
|
{
|
||||||
|
private EntityQuery _characterQuery;
|
||||||
|
private ThirdPersonCharacterUpdateContext _context;
|
||||||
|
private KinematicCharacterUpdateContext _baseContext;
|
||||||
|
|
||||||
|
[BurstCompile]
|
||||||
|
public void OnCreate(ref SystemState state)
|
||||||
|
{
|
||||||
|
_characterQuery = KinematicCharacterUtilities.GetBaseCharacterQueryBuilder()
|
||||||
|
.WithAll<
|
||||||
|
ThirdPersonCharacterComponent,
|
||||||
|
ThirdPersonCharacterControl>()
|
||||||
|
.Build(ref state);
|
||||||
|
|
||||||
|
_context = new ThirdPersonCharacterUpdateContext();
|
||||||
|
_context.OnSystemCreate(ref state);
|
||||||
|
_baseContext = new KinematicCharacterUpdateContext();
|
||||||
|
_baseContext.OnSystemCreate(ref state);
|
||||||
|
|
||||||
|
state.RequireForUpdate(_characterQuery);
|
||||||
|
state.RequireForUpdate<PhysicsWorldSingleton>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[BurstCompile]
|
||||||
|
public void OnUpdate(ref SystemState state)
|
||||||
|
{
|
||||||
|
_context.OnSystemUpdate(ref state);
|
||||||
|
_baseContext.OnSystemUpdate(ref state, SystemAPI.Time, SystemAPI.GetSingleton<PhysicsWorldSingleton>());
|
||||||
|
|
||||||
|
ThirdPersonCharacterPhysicsUpdateJob job = new ThirdPersonCharacterPhysicsUpdateJob
|
||||||
|
{
|
||||||
|
Context = _context,
|
||||||
|
BaseContext = _baseContext,
|
||||||
|
};
|
||||||
|
job.ScheduleParallel();
|
||||||
|
}
|
||||||
|
|
||||||
|
[BurstCompile]
|
||||||
|
[WithAll(typeof(Simulate))]
|
||||||
|
public partial struct ThirdPersonCharacterPhysicsUpdateJob : IJobEntity, IJobEntityChunkBeginEnd
|
||||||
|
{
|
||||||
|
public ThirdPersonCharacterUpdateContext Context;
|
||||||
|
public KinematicCharacterUpdateContext BaseContext;
|
||||||
|
|
||||||
|
void Execute(ThirdPersonCharacterAspect characterAspect)
|
||||||
|
{
|
||||||
|
characterAspect.PhysicsUpdate(ref Context, ref BaseContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OnChunkBegin(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
|
||||||
|
{
|
||||||
|
BaseContext.EnsureCreationOfTmpCollections();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnChunkEnd(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask, bool chunkWasExecuted)
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[UpdateInGroup(typeof(SimulationSystemGroup))]
|
||||||
|
[UpdateAfter(typeof(FixedStepSimulationSystemGroup))]
|
||||||
|
[UpdateAfter(typeof(ThirdPersonPlayerVariableStepControlSystem))]
|
||||||
|
[UpdateBefore(typeof(TransformSystemGroup))]
|
||||||
|
[BurstCompile]
|
||||||
|
public partial struct ThirdPersonCharacterVariableUpdateSystem : ISystem
|
||||||
|
{
|
||||||
|
private EntityQuery _characterQuery;
|
||||||
|
private ThirdPersonCharacterUpdateContext _context;
|
||||||
|
private KinematicCharacterUpdateContext _baseContext;
|
||||||
|
|
||||||
|
[BurstCompile]
|
||||||
|
public void OnCreate(ref SystemState state)
|
||||||
|
{
|
||||||
|
_characterQuery = KinematicCharacterUtilities.GetBaseCharacterQueryBuilder()
|
||||||
|
.WithAll<
|
||||||
|
ThirdPersonCharacterComponent,
|
||||||
|
ThirdPersonCharacterControl>()
|
||||||
|
.Build(ref state);
|
||||||
|
|
||||||
|
_context = new ThirdPersonCharacterUpdateContext();
|
||||||
|
_context.OnSystemCreate(ref state);
|
||||||
|
_baseContext = new KinematicCharacterUpdateContext();
|
||||||
|
_baseContext.OnSystemCreate(ref state);
|
||||||
|
|
||||||
|
state.RequireForUpdate(_characterQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
[BurstCompile]
|
||||||
|
public void OnUpdate(ref SystemState state)
|
||||||
|
{
|
||||||
|
_context.OnSystemUpdate(ref state);
|
||||||
|
_baseContext.OnSystemUpdate(ref state, SystemAPI.Time, SystemAPI.GetSingleton<PhysicsWorldSingleton>());
|
||||||
|
|
||||||
|
ThirdPersonCharacterVariableUpdateJob job = new ThirdPersonCharacterVariableUpdateJob
|
||||||
|
{
|
||||||
|
Context = _context,
|
||||||
|
BaseContext = _baseContext,
|
||||||
|
};
|
||||||
|
job.ScheduleParallel();
|
||||||
|
}
|
||||||
|
|
||||||
|
[BurstCompile]
|
||||||
|
[WithAll(typeof(Simulate))]
|
||||||
|
public partial struct ThirdPersonCharacterVariableUpdateJob : IJobEntity, IJobEntityChunkBeginEnd
|
||||||
|
{
|
||||||
|
public ThirdPersonCharacterUpdateContext Context;
|
||||||
|
public KinematicCharacterUpdateContext BaseContext;
|
||||||
|
|
||||||
|
void Execute(ThirdPersonCharacterAspect characterAspect)
|
||||||
|
{
|
||||||
|
characterAspect.VariableUpdate(ref Context, ref BaseContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OnChunkBegin(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
|
||||||
|
{
|
||||||
|
BaseContext.EnsureCreationOfTmpCollections();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnChunkEnd(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask, bool chunkWasExecuted)
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b37392a281d8a5f45a770ad4cfd747a6
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using Unity.Collections;
|
||||||
|
using Unity.Entities;
|
||||||
|
using Unity.Mathematics;
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public struct ThirdPersonPlayer : IComponentData
|
||||||
|
{
|
||||||
|
public Entity ControlledCharacter;
|
||||||
|
public Entity ControlledCamera;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public struct ThirdPersonPlayerInputs : IComponentData
|
||||||
|
{
|
||||||
|
public float2 MoveInput;
|
||||||
|
public float2 CameraLookInput;
|
||||||
|
public float CameraZoomInput;
|
||||||
|
public FixedInputEvent JumpPressed;
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8586d18bf7667c040949956b7ff40b6d
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using Unity.Entities;
|
||||||
|
|
||||||
|
[DisallowMultipleComponent]
|
||||||
|
public class ThirdPersonPlayerAuthoring : MonoBehaviour
|
||||||
|
{
|
||||||
|
public GameObject ControlledCharacter;
|
||||||
|
public GameObject ControlledCamera;
|
||||||
|
|
||||||
|
public class Baker : Baker<ThirdPersonPlayerAuthoring>
|
||||||
|
{
|
||||||
|
public override void Bake(ThirdPersonPlayerAuthoring authoring)
|
||||||
|
{
|
||||||
|
Entity entity = GetEntity(TransformUsageFlags.None);
|
||||||
|
AddComponent(entity, new ThirdPersonPlayer
|
||||||
|
{
|
||||||
|
ControlledCharacter = GetEntity(authoring.ControlledCharacter, TransformUsageFlags.Dynamic),
|
||||||
|
ControlledCamera = GetEntity(authoring.ControlledCamera, TransformUsageFlags.Dynamic),
|
||||||
|
});
|
||||||
|
AddComponent<ThirdPersonPlayerInputs>(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3fbdb3174a73a07408595a85d3e7fb6a
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,127 @@
|
|||||||
|
using Unity.Burst;
|
||||||
|
using Unity.Collections;
|
||||||
|
using Unity.Entities;
|
||||||
|
using Unity.Jobs;
|
||||||
|
using Unity.Mathematics;
|
||||||
|
using Unity.Transforms;
|
||||||
|
using UnityEngine;
|
||||||
|
using Unity.CharacterController;
|
||||||
|
|
||||||
|
[UpdateInGroup(typeof(InitializationSystemGroup))]
|
||||||
|
public partial class ThirdPersonPlayerInputsSystem : SystemBase
|
||||||
|
{
|
||||||
|
protected override void OnCreate()
|
||||||
|
{
|
||||||
|
RequireForUpdate<FixedTickSystem.Singleton>();
|
||||||
|
RequireForUpdate(SystemAPI.QueryBuilder().WithAll<ThirdPersonPlayer, ThirdPersonPlayerInputs>().Build());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnUpdate()
|
||||||
|
{
|
||||||
|
uint tick = SystemAPI.GetSingleton<FixedTickSystem.Singleton>().Tick;
|
||||||
|
|
||||||
|
foreach (var (playerInputs, player) in SystemAPI.Query<RefRW<ThirdPersonPlayerInputs>, ThirdPersonPlayer>())
|
||||||
|
{
|
||||||
|
playerInputs.ValueRW.MoveInput = new float2
|
||||||
|
{
|
||||||
|
x = (Input.GetKey(KeyCode.D) ? 1f : 0f) + (Input.GetKey(KeyCode.A) ? -1f : 0f),
|
||||||
|
y = (Input.GetKey(KeyCode.W) ? 1f : 0f) + (Input.GetKey(KeyCode.S) ? -1f : 0f),
|
||||||
|
};
|
||||||
|
|
||||||
|
playerInputs.ValueRW.CameraLookInput = new float2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
|
||||||
|
playerInputs.ValueRW.CameraZoomInput = -Input.mouseScrollDelta.y;
|
||||||
|
|
||||||
|
if (Input.GetKeyDown(KeyCode.Space))
|
||||||
|
{
|
||||||
|
playerInputs.ValueRW.JumpPressed.Set(tick);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Apply inputs that need to be read at a variable rate
|
||||||
|
/// </summary>
|
||||||
|
[UpdateInGroup(typeof(SimulationSystemGroup))]
|
||||||
|
[UpdateAfter(typeof(FixedStepSimulationSystemGroup))]
|
||||||
|
[BurstCompile]
|
||||||
|
public partial struct ThirdPersonPlayerVariableStepControlSystem : ISystem
|
||||||
|
{
|
||||||
|
[BurstCompile]
|
||||||
|
public void OnCreate(ref SystemState state)
|
||||||
|
{
|
||||||
|
state.RequireForUpdate(SystemAPI.QueryBuilder().WithAll<ThirdPersonPlayer, ThirdPersonPlayerInputs>().Build());
|
||||||
|
}
|
||||||
|
|
||||||
|
[BurstCompile]
|
||||||
|
public void OnUpdate(ref SystemState state)
|
||||||
|
{
|
||||||
|
foreach (var (playerInputs, player) in SystemAPI.Query<ThirdPersonPlayerInputs, ThirdPersonPlayer>().WithAll<Simulate>())
|
||||||
|
{
|
||||||
|
if (SystemAPI.HasComponent<OrbitCameraControl>(player.ControlledCamera))
|
||||||
|
{
|
||||||
|
OrbitCameraControl cameraControl = SystemAPI.GetComponent<OrbitCameraControl>(player.ControlledCamera);
|
||||||
|
|
||||||
|
cameraControl.FollowedCharacterEntity = player.ControlledCharacter;
|
||||||
|
cameraControl.LookDegreesDelta = playerInputs.CameraLookInput;
|
||||||
|
cameraControl.ZoomDelta = playerInputs.CameraZoomInput;
|
||||||
|
|
||||||
|
SystemAPI.SetComponent(player.ControlledCamera, cameraControl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Apply inputs that need to be read at a fixed rate.
|
||||||
|
/// It is necessary to handle this as part of the fixed step group, in case your framerate is lower than the fixed step rate.
|
||||||
|
/// </summary>
|
||||||
|
[UpdateInGroup(typeof(FixedStepSimulationSystemGroup), OrderFirst = true)]
|
||||||
|
[BurstCompile]
|
||||||
|
public partial struct ThirdPersonPlayerFixedStepControlSystem : ISystem
|
||||||
|
{
|
||||||
|
[BurstCompile]
|
||||||
|
public void OnCreate(ref SystemState state)
|
||||||
|
{
|
||||||
|
state.RequireForUpdate<FixedTickSystem.Singleton>();
|
||||||
|
state.RequireForUpdate(SystemAPI.QueryBuilder().WithAll<ThirdPersonPlayer, ThirdPersonPlayerInputs>().Build());
|
||||||
|
}
|
||||||
|
|
||||||
|
[BurstCompile]
|
||||||
|
public void OnUpdate(ref SystemState state)
|
||||||
|
{
|
||||||
|
uint tick = SystemAPI.GetSingleton<FixedTickSystem.Singleton>().Tick;
|
||||||
|
|
||||||
|
foreach (var (playerInputs, player) in SystemAPI.Query<ThirdPersonPlayerInputs, ThirdPersonPlayer>().WithAll<Simulate>())
|
||||||
|
{
|
||||||
|
if (SystemAPI.HasComponent<ThirdPersonCharacterControl>(player.ControlledCharacter))
|
||||||
|
{
|
||||||
|
ThirdPersonCharacterControl characterControl = SystemAPI.GetComponent<ThirdPersonCharacterControl>(player.ControlledCharacter);
|
||||||
|
|
||||||
|
float3 characterUp = MathUtilities.GetUpFromRotation(SystemAPI.GetComponent<LocalTransform>(player.ControlledCharacter).Rotation);
|
||||||
|
|
||||||
|
// Get camera rotation, since our movement is relative to it.
|
||||||
|
quaternion cameraRotation = quaternion.identity;
|
||||||
|
if (SystemAPI.HasComponent<OrbitCamera>(player.ControlledCamera))
|
||||||
|
{
|
||||||
|
// Camera rotation is calculated rather than gotten from transform, because this allows us to
|
||||||
|
// reduce the size of the camera ghost state in a netcode prediction context.
|
||||||
|
// If not using netcode prediction, we could simply get rotation from transform here instead.
|
||||||
|
OrbitCamera orbitCamera = SystemAPI.GetComponent<OrbitCamera>(player.ControlledCamera);
|
||||||
|
cameraRotation = OrbitCameraUtilities.CalculateCameraRotation(characterUp, orbitCamera.PlanarForward, orbitCamera.PitchAngle);
|
||||||
|
}
|
||||||
|
float3 cameraForwardOnUpPlane = math.normalizesafe(MathUtilities.ProjectOnPlane(MathUtilities.GetForwardFromRotation(cameraRotation), characterUp));
|
||||||
|
float3 cameraRight = MathUtilities.GetRightFromRotation(cameraRotation);
|
||||||
|
|
||||||
|
// Move
|
||||||
|
characterControl.MoveVector = (playerInputs.MoveInput.y * cameraForwardOnUpPlane) + (playerInputs.MoveInput.x * cameraRight);
|
||||||
|
characterControl.MoveVector = MathUtilities.ClampToMaxLength(characterControl.MoveVector, 1f);
|
||||||
|
|
||||||
|
// Jump
|
||||||
|
characterControl.Jump = playerInputs.JumpPressed.IsSet(tick);
|
||||||
|
|
||||||
|
SystemAPI.SetComponent(player.ControlledCharacter, characterControl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 427fac77ddc96db4a87e6d5b4a31555f
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
Assets/SceneDependencyCache.meta
Normal file
8
Assets/SceneDependencyCache.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a0b48755420c5d74dbf2fba8044413a2
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Binary file not shown.
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0979dfe7cb3e80e7351c0769b5c07853
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Binary file not shown.
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7ba88fd50001830e271c153fafd8f272
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user