diff --git a/Assets/Materials/DefaultBoxMaterial.mat b/Assets/Materials/DefaultBoxMaterial.mat index c06f717c..95166066 100644 --- a/Assets/Materials/DefaultBoxMaterial.mat +++ b/Assets/Materials/DefaultBoxMaterial.mat @@ -23,7 +23,7 @@ Material: m_Name: DefaultBoxMaterial m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3} m_Parent: {fileID: 2100000, guid: 40e6df53a7ed41a44866ad9827990809, type: 2} - m_ModifiedSerializedProperties: 0 + m_ModifiedSerializedProperties: 8 m_ValidKeywords: - _SPECULAR_SETUP m_InvalidKeywords: [] @@ -48,6 +48,7 @@ Material: m_Offset: {x: 0, y: 0} m_Ints: [] m_Floats: + - _Cull: 2 - _Metallic: 0 - _Smoothness: 0 - _WorkflowMode: 0 diff --git a/Assets/Meshes.meta b/Assets/Meshes.meta new file mode 100644 index 00000000..12897f35 --- /dev/null +++ b/Assets/Meshes.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9630c5592e3e140499df0381fad26035 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Meshes/plane.fbx b/Assets/Meshes/plane.fbx new file mode 100644 index 00000000..3714e5e7 Binary files /dev/null and b/Assets/Meshes/plane.fbx differ diff --git a/Assets/Meshes/plane.fbx.meta b/Assets/Meshes/plane.fbx.meta new file mode 100644 index 00000000..a8011bfd --- /dev/null +++ b/Assets/Meshes/plane.fbx.meta @@ -0,0 +1,109 @@ +fileFormatVersion: 2 +guid: b783776a69528e745a7fc3b886c598ab +ModelImporter: + serializedVersion: 22200 + internalIDToNameTable: [] + externalObjects: {} + materials: + materialImportMode: 2 + materialName: 0 + materialSearch: 1 + materialLocation: 1 + animations: + legacyGenerateAnimations: 4 + bakeSimulation: 0 + resampleCurves: 1 + optimizeGameObjects: 0 + removeConstantScaleCurves: 0 + motionNodeName: + rigImportErrors: + rigImportWarnings: + animationImportErrors: + animationImportWarnings: + animationRetargetingWarnings: + animationDoRetargetingWarnings: 0 + importAnimatedCustomProperties: 0 + importConstraints: 0 + animationCompression: 1 + animationRotationError: 0.5 + animationPositionError: 0.5 + animationScaleError: 0.5 + animationWrapMode: 0 + extraExposedTransformPaths: [] + extraUserProperties: [] + clipAnimations: [] + isReadable: 0 + meshes: + lODScreenPercentages: [] + globalScale: 1 + meshCompression: 0 + addColliders: 0 + useSRGBMaterialColor: 1 + sortHierarchyByName: 0 + importPhysicalCameras: 1 + importVisibility: 0 + importBlendShapes: 0 + importCameras: 0 + importLights: 0 + nodeNameCollisionStrategy: 1 + fileIdsGeneration: 2 + swapUVChannels: 0 + generateSecondaryUV: 0 + useFileUnits: 1 + keepQuads: 0 + weldVertices: 0 + bakeAxisConversion: 1 + preserveHierarchy: 0 + skinWeightsMode: 0 + maxBonesPerVertex: 4 + minBoneWeight: 0.001 + optimizeBones: 1 + meshOptimizationFlags: -1 + indexFormat: 0 + secondaryUVAngleDistortion: 8 + secondaryUVAreaDistortion: 15.000001 + secondaryUVHardAngle: 88 + secondaryUVMarginMethod: 1 + secondaryUVMinLightmapResolution: 40 + secondaryUVMinObjectScale: 1 + secondaryUVPackMargin: 4 + useFileScale: 0 + strictVertexDataChecks: 0 + tangentSpace: + normalSmoothAngle: 60 + normalImportMode: 0 + tangentImportMode: 3 + normalCalculationMode: 4 + legacyComputeAllNormalsFromSmoothingGroupsWhenMeshHasBlendShapes: 0 + blendShapeNormalImportMode: 1 + normalSmoothingSource: 0 + referencedClips: [] + importAnimation: 1 + humanDescription: + serializedVersion: 3 + human: [] + skeleton: [] + armTwist: 0.5 + foreArmTwist: 0.5 + upperLegTwist: 0.5 + legTwist: 0.5 + armStretch: 0.05 + legStretch: 0.05 + feetSpacing: 0 + globalScale: 1 + rootMotionBoneName: + hasTranslationDoF: 0 + hasExtraRoot: 0 + skeletonHasParents: 1 + lastHumanDescriptionAvatarSource: {instanceID: 0} + autoGenerateAvatarMappingIfUnspecified: 1 + animationType: 2 + humanoidOversampling: 1 + avatarSetup: 0 + addHumanoidExtraRootOnlyWhenUsingAvatar: 1 + importBlendShapeDeformPercent: 1 + remapMaterialsIfMaterialImportModeIsNone: 0 + additionalBone: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/TerrainFace.prefab b/Assets/Prefabs/TerrainFace.prefab index 75bac347..8e6fe4d9 100644 --- a/Assets/Prefabs/TerrainFace.prefab +++ b/Assets/Prefabs/TerrainFace.prefab @@ -29,7 +29,7 @@ Transform: m_GameObject: {fileID: 8123702849073069357} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 0.1, y: 0.1, z: 0.1} + m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} @@ -42,7 +42,7 @@ MeshFilter: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8123702849073069357} - m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} + m_Mesh: {fileID: -462981019419857548, guid: b783776a69528e745a7fc3b886c598ab, type: 3} --- !u!23 &1616570936911530320 MeshRenderer: m_ObjectHideFlags: 0 @@ -106,7 +106,7 @@ MeshCollider: serializedVersion: 5 m_Convex: 0 m_CookingOptions: 30 - m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} + m_Mesh: {fileID: -462981019419857548, guid: b783776a69528e745a7fc3b886c598ab, type: 3} --- !u!114 &-7653684817171243984 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 05743bff..8e9211e6 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -135,6 +135,7 @@ GameObject: - component: {fileID: 330585545} - component: {fileID: 330585544} - component: {fileID: 330585547} + - component: {fileID: 330585548} m_Layer: 0 m_Name: Main Camera m_TagString: MainCamera @@ -260,6 +261,18 @@ MonoBehaviour: mipBias: 0 varianceClampScale: 0.9 contrastAdaptiveSharpening: 0 +--- !u!114 &330585548 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 330585543} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0b52457eaabc47a3a7737f7a651c57b9, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &367044023 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/SampleScene/SampleSubScene.unity b/Assets/Scenes/SampleScene/SampleSubScene.unity index 68ec1559..816d8ea2 100644 --- a/Assets/Scenes/SampleScene/SampleSubScene.unity +++ b/Assets/Scenes/SampleScene/SampleSubScene.unity @@ -176,7 +176,7 @@ MonoBehaviour: x: 1 y: 1 z: 1 - maxChunkSpawnsPerTick: 8 + maxChunkSpawnsPerTick: 10 blocksPerChunkSide: 4 YBounds: x: 0 diff --git a/Assets/Scripts/Networking/ConnectionPositionSystem.cs b/Assets/Scripts/Networking/ConnectionPositionSystem.cs new file mode 100644 index 00000000..08b9c484 --- /dev/null +++ b/Assets/Scripts/Networking/ConnectionPositionSystem.cs @@ -0,0 +1,48 @@ +using Unity.Burst; +using Unity.Collections; +using Unity.Entities; +using Unity.Mathematics; +using Unity.NetCode; + +[BurstCompile] +[RequireMatchingQueriesForUpdate] +[WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation)] +//[UpdateAfter(typeof(PlayerMovementSystem))] +public partial struct ConnectionPositionSystem : ISystem +{ + public void OnCreate(ref SystemState state) + { + var grid = state.EntityManager.CreateEntity(); + var m_ScaleFunctionPointer = GhostDistanceImportance.ScaleFunctionPointer; + state.EntityManager.SetName(grid, "GhostImportanceSingleton"); + state.EntityManager.AddComponentData(grid, new GhostDistanceData + { + TileSize = new int3(5, 5, 5), + TileCenter = new int3(0, 0, 0), + TileBorderWidth = new float3(1f, 1f, 1f), + }); + state.EntityManager.AddComponentData(grid, new GhostImportance + { + ScaleImportanceFunction = m_ScaleFunctionPointer, + GhostConnectionComponentType = ComponentType.ReadOnly(), + GhostImportanceDataType = ComponentType.ReadOnly(), + GhostImportancePerChunkDataType = ComponentType.ReadOnly(), + }); + } + + [BurstCompile] + public void OnUpdate(ref SystemState state) + { + foreach (var (nID, ghostConnPos) in SystemAPI.Query>()) + { + foreach (var player in SystemAPI.Query().WithAll()) + { + if (player.OwnerNetworkId == nID.Value) + { + ghostConnPos.ValueRW.Position = player.Transform.ValueRO.Position; + break; + } + } + } + } +} diff --git a/Assets/Scripts/Networking/ConnectionPositionSystem.cs.meta b/Assets/Scripts/Networking/ConnectionPositionSystem.cs.meta new file mode 100644 index 00000000..4636b0f3 --- /dev/null +++ b/Assets/Scripts/Networking/ConnectionPositionSystem.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d45ae935f176423ca59c54efdfd29c9a +timeCreated: 1685446831 \ No newline at end of file diff --git a/Assets/Scripts/Networking/GoInGame.cs b/Assets/Scripts/Networking/GoInGame.cs index fb12be05..da2fb960 100644 --- a/Assets/Scripts/Networking/GoInGame.cs +++ b/Assets/Scripts/Networking/GoInGame.cs @@ -71,6 +71,7 @@ public void OnUpdate(ref SystemState state) foreach (var (reqSrc, reqEntity) in SystemAPI.Query>().WithAll().WithEntityAccess()) { commandBuffer.AddComponent(reqSrc.ValueRO.SourceConnection); + commandBuffer.AddComponent(reqSrc.ValueRO.SourceConnection, new GhostConnectionPosition{ Position = new float3() }); var networkId = networkIdFromEntity[reqSrc.ValueRO.SourceConnection]; UnityEngine.Debug.Log($"'{worldName}' setting connection '{networkId.Value}' to in game!"); diff --git a/Assets/Scripts/Player/CameraSingleton.cs b/Assets/Scripts/Player/CameraSingleton.cs new file mode 100644 index 00000000..65d74b0f --- /dev/null +++ b/Assets/Scripts/Player/CameraSingleton.cs @@ -0,0 +1,11 @@ +using UnityEngine; + +public class CameraSingleton : MonoBehaviour +{ + public static Camera Instance; + + void Awake() + { + Instance = GetComponent(); + } +} \ No newline at end of file diff --git a/Assets/Scripts/Player/CameraSingleton.cs.meta b/Assets/Scripts/Player/CameraSingleton.cs.meta new file mode 100644 index 00000000..f9149a58 --- /dev/null +++ b/Assets/Scripts/Player/CameraSingleton.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 0b52457eaabc47a3a7737f7a651c57b9 +timeCreated: 1685469994 \ No newline at end of file diff --git a/Assets/Scripts/Player/CameraSystem.cs b/Assets/Scripts/Player/CameraSystem.cs new file mode 100644 index 00000000..d7d9b79d --- /dev/null +++ b/Assets/Scripts/Player/CameraSystem.cs @@ -0,0 +1,35 @@ +using Unity.Burst; +using Unity.Entities; +using Unity.Mathematics; +using Unity.NetCode; +using Unity.Transforms; + +[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation)] +[UpdateInGroup(typeof(PresentationSystemGroup))] +[BurstCompile] +partial struct CameraSystem : ISystem +{ + public static readonly float3 k_CameraOffset = new float3(0, 2, -5); + + [BurstCompile] + public void OnCreate(ref SystemState state) + { + state.RequireForUpdate(); + state.RequireForUpdate(); + } + + public void OnUpdate(ref SystemState state) + { + var camera = CameraSingleton.Instance; + //We need to access the LocalToWorld matrix to match the position of the player in term of presentation. + //Because Physics can be either Interpolated or Predicted, we the LocalToWorld can be different than the real world position + //of the entity. + foreach (var (localToWorld, input) in SystemAPI.Query, RefRO>().WithAll()) + { + camera.transform.rotation = math.mul(quaternion.RotateY(input.ValueRO.Yaw), quaternion.RotateX(-input.ValueRO.Pitch)); + var offset = math.rotate(camera.transform.rotation, k_CameraOffset); + camera.transform.position = localToWorld.ValueRO.Position + offset; + } + } +} + diff --git a/Assets/Scripts/Player/CameraSystem.cs.meta b/Assets/Scripts/Player/CameraSystem.cs.meta new file mode 100644 index 00000000..7ed27535 --- /dev/null +++ b/Assets/Scripts/Player/CameraSystem.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e45aebd6bb3e43d584b5c2eb62784aa3 +timeCreated: 1685466057 \ No newline at end of file diff --git a/Assets/Scripts/Player/PlayerInputSystem.cs b/Assets/Scripts/Player/PlayerInputSystem.cs index 0df6a5cb..feef9a75 100644 --- a/Assets/Scripts/Player/PlayerInputSystem.cs +++ b/Assets/Scripts/Player/PlayerInputSystem.cs @@ -33,11 +33,10 @@ public void OnUpdate(ref SystemState state) } commandBuffer.Playback(state.EntityManager); } - - bool left = Input.GetKey("left"); - bool right = Input.GetKey("right"); - bool down = Input.GetKey("down"); - bool up = Input.GetKey("up"); + bool left = Input.GetKey("a"); + bool right = Input.GetKey("d"); + bool down = Input.GetKey("s"); + bool up = Input.GetKey("w"); bool space = Input.GetKeyDown("space"); bool mouse1 = Input.GetKeyDown(KeyCode.Mouse0); bool mouse2 = Input.GetKeyDown(KeyCode.Mouse1); diff --git a/Assets/Scripts/Player/PlayerSpawnerSystem.cs b/Assets/Scripts/Player/PlayerSpawnerSystem.cs index 26f0b579..a0877eb6 100644 --- a/Assets/Scripts/Player/PlayerSpawnerSystem.cs +++ b/Assets/Scripts/Player/PlayerSpawnerSystem.cs @@ -7,6 +7,7 @@ using Unity.Collections; using Unity.Logging; using Unity.Networking.Transport; +using UnityEngine.UIElements; public struct SpawnPlayerRequest : IRpcCommand { @@ -62,7 +63,7 @@ public void OnUpdate(ref SystemState state) } connectionsSeen[index] = reqSrc.ValueRO.SourceConnection; - var networkId = networkIdFromEntity[reqSrc.ValueRO.SourceConnection]; + NetworkId networkId = networkIdFromEntity[reqSrc.ValueRO.SourceConnection]; commandBuffer.AddComponent(reqSrc.ValueRO.SourceConnection); diff --git a/Assets/Scripts/Rendering/RenderTerrainSystem.cs b/Assets/Scripts/Rendering/RenderTerrainSystem.cs index 7d7bfbbe..b44ee738 100644 --- a/Assets/Scripts/Rendering/RenderTerrainSystem.cs +++ b/Assets/Scripts/Rendering/RenderTerrainSystem.cs @@ -226,7 +226,14 @@ private int3 GetBlockNeighboringAreas(int3 location) private void SpawnFace(int3 location, float3 direction) { Entity newFace = ecb.Instantiate(1, face); - quaternion rotation = quaternion.LookRotationSafe( math.down(), direction); + // Returns identity if colinear, so math.up as direction functions as intended if the mesh is already facing up :) + quaternion rotation = quaternion.LookRotationSafe( math.up(), direction); + if (direction.Equals(math.down())) + { + // Rotations are in radians + rotation = quaternion.RotateZ(math.PI); + } + LocalTransform lt = new LocalTransform() { Position = location + 0.5f * direction + new float3(0.5f), Rotation = rotation, Scale = 1.0f}; ecb.SetComponent(1, newFace, lt); }