From 864f78562e629da7717d6a13116cf0b91ecddf74 Mon Sep 17 00:00:00 2001 From: Nikita Kruglickiy Date: Wed, 20 Mar 2024 15:39:48 +0300 Subject: [PATCH] Empty light settings for procedural scene; --- Assets/Prefabs/Characters/Player.prefab | 11 +- Assets/Scenes/Procedural.lighting | 64 ++++++++++++ Assets/Scenes/Procedural.lighting.meta | 8 ++ Assets/Scenes/Procedural.unity | 4 +- Assets/Scenes/Procedural/LightingData.asset | Bin 0 -> 24439 bytes .../Scenes/Procedural/LightingData.asset.meta | 8 ++ .../Scenes/Procedural/Lightmap-0_comp_dir.png | 3 + .../Procedural/Lightmap-0_comp_dir.png.meta | 98 ++++++++++++++++++ .../Procedural/Lightmap-0_comp_light.exr | 3 + .../Procedural/Lightmap-0_comp_light.exr.meta | 98 ++++++++++++++++++ .../Scenes/Procedural/Lightmap-1_comp_dir.png | 3 + .../Procedural/Lightmap-1_comp_dir.png.meta | 98 ++++++++++++++++++ .../Procedural/Lightmap-1_comp_light.exr | 3 + .../Procedural/Lightmap-1_comp_light.exr.meta | 98 ++++++++++++++++++ .../Scenes/Procedural/Lightmap-2_comp_dir.png | 3 + .../Procedural/Lightmap-2_comp_dir.png.meta | 98 ++++++++++++++++++ .../Procedural/Lightmap-2_comp_light.exr | 3 + .../Procedural/Lightmap-2_comp_light.exr.meta | 98 ++++++++++++++++++ .../Scenes/Procedural/ReflectionProbe-0.exr | 3 + .../Procedural/ReflectionProbe-0.exr.meta | 98 ++++++++++++++++++ Assets/Scripts/Characters/Enemy/Enemy.cs | 20 +++- .../Characters/Enemy/States/ChaseState.cs | 2 + .../Characters/Enemy/States/PatrolState.cs | 2 + Assets/Scripts/Characters/Pawn.cs | 44 +------- .../PersonController/PersonController.cs | 30 +++++- Assets/Scripts/Extensions.cs | 15 +++ Assets/Scripts/Extensions.cs.meta | 3 + .../Level/BuildModules/ProceduralPrefabs.cs | 8 ++ Assets/Scripts/Level/NavmeshBaker.cs | 7 +- Assets/Scripts/StateMachine/StateMachine.cs | 1 - 30 files changed, 872 insertions(+), 62 deletions(-) create mode 100644 Assets/Scenes/Procedural.lighting create mode 100644 Assets/Scenes/Procedural.lighting.meta create mode 100644 Assets/Scenes/Procedural/LightingData.asset create mode 100644 Assets/Scenes/Procedural/LightingData.asset.meta create mode 100644 Assets/Scenes/Procedural/Lightmap-0_comp_dir.png create mode 100644 Assets/Scenes/Procedural/Lightmap-0_comp_dir.png.meta create mode 100644 Assets/Scenes/Procedural/Lightmap-0_comp_light.exr create mode 100644 Assets/Scenes/Procedural/Lightmap-0_comp_light.exr.meta create mode 100644 Assets/Scenes/Procedural/Lightmap-1_comp_dir.png create mode 100644 Assets/Scenes/Procedural/Lightmap-1_comp_dir.png.meta create mode 100644 Assets/Scenes/Procedural/Lightmap-1_comp_light.exr create mode 100644 Assets/Scenes/Procedural/Lightmap-1_comp_light.exr.meta create mode 100644 Assets/Scenes/Procedural/Lightmap-2_comp_dir.png create mode 100644 Assets/Scenes/Procedural/Lightmap-2_comp_dir.png.meta create mode 100644 Assets/Scenes/Procedural/Lightmap-2_comp_light.exr create mode 100644 Assets/Scenes/Procedural/Lightmap-2_comp_light.exr.meta create mode 100644 Assets/Scenes/Procedural/ReflectionProbe-0.exr create mode 100644 Assets/Scenes/Procedural/ReflectionProbe-0.exr.meta create mode 100644 Assets/Scripts/Extensions.cs create mode 100644 Assets/Scripts/Extensions.cs.meta diff --git a/Assets/Prefabs/Characters/Player.prefab b/Assets/Prefabs/Characters/Player.prefab index feb1ee4..f61350c 100644 --- a/Assets/Prefabs/Characters/Player.prefab +++ b/Assets/Prefabs/Characters/Player.prefab @@ -2356,14 +2356,8 @@ MonoBehaviour: m_EditorClassIdentifier: syncMode: 0 syncInterval: 0.02 - health: 100 Alive: 1 _speedMul: 1 - _cinemachineTargetPitch: 0 - RotationSpeed: 1 - BottomClamp: -90 - TopClamp: 90 - CinemachineCameraTarget: {fileID: 8691963221834896074} headPosition: {fileID: 1762678065726348224} floatingInfo: {fileID: 3575501728372586808} nicknameInput: {fileID: 3502686228214059428} @@ -2390,6 +2384,11 @@ MonoBehaviour: mainCamera: {fileID: 8591369834395964051} playerName: gunColor: {r: 0, g: 0, b: 0, a: 0} + _cinemachineTargetPitch: 0 + CinemachineCameraTarget: {fileID: 8691963221834896074} + RotationSpeed: 1 + BottomClamp: -90 + TopClamp: 90 currentEnergy: 100 shootDepletion: 25 _flashLightDepletion: 0.3 diff --git a/Assets/Scenes/Procedural.lighting b/Assets/Scenes/Procedural.lighting new file mode 100644 index 0000000..03cbeb5 --- /dev/null +++ b/Assets/Scenes/Procedural.lighting @@ -0,0 +1,64 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!850595691 &4890085278179872738 +LightingSettings: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: Procedural + serializedVersion: 4 + m_GIWorkflowMode: 1 + m_EnableBakedLightmaps: 1 + m_EnableRealtimeLightmaps: 0 + m_RealtimeEnvironmentLighting: 1 + m_BounceScale: 1 + m_AlbedoBoost: 1 + m_IndirectOutputScale: 1 + m_UsingShadowmask: 1 + m_BakeBackend: 2 + m_LightmapMaxSize: 1024 + m_BakeResolution: 40 + m_Padding: 2 + m_LightmapCompression: 3 + m_AO: 0 + m_AOMaxDistance: 1 + m_CompAOExponent: 1 + m_CompAOExponentDirect: 0 + m_ExtractAO: 0 + m_MixedBakeMode: 2 + m_LightmapsBakeMode: 1 + m_FilterMode: 1 + m_LightmapParameters: {fileID: 15204, guid: 0000000000000000f000000000000000, type: 0} + m_ExportTrainingData: 0 + m_TrainingDataDestination: TrainingData + m_RealtimeResolution: 2 + m_ForceWhiteAlbedo: 0 + m_ForceUpdates: 0 + m_FinalGather: 0 + m_FinalGatherRayCount: 256 + m_FinalGatherFiltering: 1 + m_PVRCulling: 1 + m_PVRSampling: 1 + m_PVRDirectSampleCount: 32 + m_PVRSampleCount: 512 + m_PVREnvironmentSampleCount: 256 + m_PVREnvironmentReferencePointCount: 2048 + m_LightProbeSampleCountMultiplier: 4 + m_PVRBounces: 2 + m_PVRMinBounces: 1 + m_PVREnvironmentMIS: 1 + m_PVRFilteringMode: 1 + m_PVRDenoiserTypeDirect: 1 + m_PVRDenoiserTypeIndirect: 1 + m_PVRDenoiserTypeAO: 1 + m_PVRFilterTypeDirect: 0 + m_PVRFilterTypeIndirect: 0 + m_PVRFilterTypeAO: 0 + m_PVRFilteringGaussRadiusDirect: 1 + m_PVRFilteringGaussRadiusIndirect: 5 + m_PVRFilteringGaussRadiusAO: 2 + m_PVRFilteringAtrousPositionSigmaDirect: 0.5 + m_PVRFilteringAtrousPositionSigmaIndirect: 2 + m_PVRFilteringAtrousPositionSigmaAO: 1 + m_PVRTiledBaking: 0 diff --git a/Assets/Scenes/Procedural.lighting.meta b/Assets/Scenes/Procedural.lighting.meta new file mode 100644 index 0000000..562d28b --- /dev/null +++ b/Assets/Scenes/Procedural.lighting.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 49cca1d38c3581042a44320df3b196f3 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 4890085278179872738 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Procedural.unity b/Assets/Scenes/Procedural.unity index a49a436..4a610bc 100644 --- a/Assets/Scenes/Procedural.unity +++ b/Assets/Scenes/Procedural.unity @@ -97,8 +97,8 @@ LightmapSettings: m_ExportTrainingData: 0 m_TrainingDataDestination: TrainingData m_LightProbeSampleCountMultiplier: 4 - m_LightingDataAsset: {fileID: 0} - m_LightingSettings: {fileID: 0} + m_LightingDataAsset: {fileID: 112000000, guid: d6e02588841a5c84993d1ffdabeaa5d2, type: 2} + m_LightingSettings: {fileID: 4890085278179872738, guid: 49cca1d38c3581042a44320df3b196f3, type: 2} --- !u!196 &4 NavMeshSettings: serializedVersion: 2 diff --git a/Assets/Scenes/Procedural/LightingData.asset b/Assets/Scenes/Procedural/LightingData.asset new file m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JkNgIy3)JC z&Q{KOq3P|HV3pt=oE-cVI|;MIy2s%E;$k=Jy?f8Idl^?I&wy2B``AhLBm0aUS;`L2 z<)6Ipn0Ir^gOd_?o89$pv+wy4@9P=mB<9+=-}Cjou0tFa^e5btCM_@S3&x~SiO?$K_W=qUBX0=0Y5IC_Lg9=1@I z(9;g*CR2*S+qI{GxZm>rO0KJin^8cEL2>#V;?|{p$3^WjnmD*~bao zI&b#6YuH^h=^1|hJ@yMf^E~@kGv3Zg^TYhqZ1(Ah1?=ao-kteRu@e$maB88$ zKAFVNu&=y(HE18!#m__Q5NhS0va=L(a>QPK<~?@fwRyNF;TK=^y7M=8Gq8#+TR4kIvKI>z4A zlCqy_Sob{X^W%FbFGg@j9}GcN#mJB!?A>4o`?gJ~*>G1Wy_57XJd?g*qjbZ?edjk_ zTxXa=f?qCWANTE$h?>wEb~Dvi`Nf$Seq!3Zv2%xFxsTE+2_@LJ2gb}^SYO@ z%YUWj{IkY`ZDRNn*Jhj^T_4w1oo8Fj_h|+Hr@cpaW8Mw^53C{Qu>DI1zr+5?x>n$R z3{N|i&tM-BjMDLy*FckEpF*h24$)PX>{r*=c?}$9_Q0M=FD8cFDUp zb*O`)bes}PhNg`fW*h@OtUn|njb*;V$_svvffcV)NN z#lC6vt_}%e+vxuO6Lw*D6+0GcNp^@INBekP6Zu(oXHCG5%kX%IJ@?N75~ z^XjHN8^n>=gX}IE1G`4-Xjx5=6t~vSkE6{H+6KeE*XJmQpZo?w>(hAZdxdy{V9=~- zZPVJE(0^L5NaE;;Q+gPQoo;DrYQf1H38l|i`1)A~I)xmJ&!afn-(); _networkGameManager = NetworkGameManager.singleton; _footstepClip = Resources.Load("Audio/EnemySounds/Steps/monsterStep1"); + _navMeshPath = new(); networkAnimator = GetComponent(); @@ -123,14 +125,24 @@ namespace Characters.Enemy ChangeState(EnemyState.Stunned); } + [Server] public void ChangeState(EnemyState newState) { state = newState; + + RpcChangeState(newState); + } + + [ClientRpc] + private void RpcChangeState(EnemyState newState) + { stateMachine.SetCurrentState(newState); } public Transform GetClosestTarget() { + if (!agent.isOnNavMesh) return null; + var alivePlayers = _networkManager.alive; if (HasTarget && alivePlayers.Count == 1 && alivePlayers[0].transform == targetTransform) @@ -140,12 +152,14 @@ namespace Characters.Enemy Transform closestTarget = null; - float sortDistance = float.MaxValue; + var sortDistance = float.MaxValue; foreach (var player in _networkManager.alive) { - float distance = Vector3.Distance(player.transform.position, transform.position); + var targetPosition = player.transform.position; + var distance = Vector3.Distance(targetPosition, transform.position); + var canReachTarget = agent.CalculatePath(targetPosition, _navMeshPath) && _navMeshPath.status == NavMeshPathStatus.PathComplete; - if (distance <= aggressionDistance && distance < sortDistance && agent.SetDestination(player.transform.position)) + if (distance <= aggressionDistance && distance < sortDistance && canReachTarget) { sortDistance = distance; closestTarget = player.transform; diff --git a/Assets/Scripts/Characters/Enemy/States/ChaseState.cs b/Assets/Scripts/Characters/Enemy/States/ChaseState.cs index 61272d4..5c81d53 100644 --- a/Assets/Scripts/Characters/Enemy/States/ChaseState.cs +++ b/Assets/Scripts/Characters/Enemy/States/ChaseState.cs @@ -53,6 +53,8 @@ namespace Characters.Enemy.States } else { + _enemy.targetTransform = null; + _enemy.ChangeState(EnemyState.Idle); } } diff --git a/Assets/Scripts/Characters/Enemy/States/PatrolState.cs b/Assets/Scripts/Characters/Enemy/States/PatrolState.cs index e447dc5..41b8d40 100644 --- a/Assets/Scripts/Characters/Enemy/States/PatrolState.cs +++ b/Assets/Scripts/Characters/Enemy/States/PatrolState.cs @@ -46,6 +46,8 @@ namespace Characters.Enemy.States [Server] void SetRandomDestination() { + if (!_enemy.agent.isOnNavMesh) return; + _enemy.agent.destination = GetRandomLocation(); } diff --git a/Assets/Scripts/Characters/Pawn.cs b/Assets/Scripts/Characters/Pawn.cs index 944a78d..045beab 100644 --- a/Assets/Scripts/Characters/Pawn.cs +++ b/Assets/Scripts/Characters/Pawn.cs @@ -8,21 +8,12 @@ namespace Characters { public event Action OnDamage; public event Action OnLiveState; - public int health = 100; public bool Alive = true; - void Start() - { - RotationSpeed = PlayerPrefs.GetFloat("Sensitivity"); - } - [SyncVar] public float _speedMul = 1f; - public virtual void TakeDamage() - { - OnDamage?.Invoke(this); - } + public virtual void TakeDamage() {} [Command] public void CmdDie() @@ -53,38 +44,5 @@ namespace Characters { _speedMul = mul; } - - private Vector2 _mouseLook; - [SyncVar] - public float _cinemachineTargetPitch; - private float _rotationVelocity; - public float RotationSpeed = 1f; - public float BottomClamp = -90.0f; - public float TopClamp = 90.0f; - public GameObject CinemachineCameraTarget; - - - public void CameraRotation() - { - if (Cursor.lockState == CursorLockMode.None) return; - - _mouseLook = new Vector2(Input.GetAxis("Mouse X"), -Input.GetAxis("Mouse Y")); - _cinemachineTargetPitch += _mouseLook.y * RotationSpeed; - _rotationVelocity = _mouseLook.x * RotationSpeed; - - _cinemachineTargetPitch = ClampAngle(_cinemachineTargetPitch, BottomClamp, TopClamp); - - transform.Rotate(Vector3.up * _rotationVelocity); - - CinemachineCameraTarget.transform.localRotation = Quaternion.Euler(_cinemachineTargetPitch, 0.0f, 0.0f); - // CmdSetCameraPitch(_cinemachineTargetPitch); - } - - private static float ClampAngle(float lfAngle, float lfMin, float lfMax) - { - if (lfAngle < -360f) lfAngle += 360f; - if (lfAngle > 360f) lfAngle -= 360f; - return Mathf.Clamp(lfAngle, lfMin, lfMax); - } } } \ No newline at end of file diff --git a/Assets/Scripts/Characters/PersonController/PersonController.cs b/Assets/Scripts/Characters/PersonController/PersonController.cs index c92dfd4..dfc0b77 100644 --- a/Assets/Scripts/Characters/PersonController/PersonController.cs +++ b/Assets/Scripts/Characters/PersonController/PersonController.cs @@ -3,6 +3,7 @@ using Mirror; using TMPro; using Characters; using Debuffs; +using Koptilnya; /* Note: animations are called via the controller for both the character and capsule using animator null checks */ @@ -95,6 +96,16 @@ namespace StarterAssets public Color gunColor; private Vector3 _position; + + private float _rotationVelocity; + private Vector2 _mouseLook; + [SyncVar] + public float _cinemachineTargetPitch; + public GameObject CinemachineCameraTarget; + public float RotationSpeed = 1f; + public float BottomClamp = -90.0f; + public float TopClamp = 90.0f; + [Command] public void CmdSetupPlayer(string _name, float r, float g, float b) @@ -121,6 +132,7 @@ namespace StarterAssets private void Start() { + RotationSpeed = PlayerPrefs.GetFloat("Sensitivity"); _controller = GetComponent(); this.OnDamage += OnTakeDamage; @@ -153,7 +165,7 @@ namespace StarterAssets if (!isLocalPlayer) { - if (netIdentity.isActiveAndEnabled && floatingInfo != null) + if (netIdentity.isActiveAndEnabled && floatingInfo != null && Camera.main) floatingInfo.transform.LookAt(Camera.main.transform); return; } @@ -180,6 +192,22 @@ namespace StarterAssets CameraRotation(); SetCamToHeadPos(); } + + void CameraRotation() + { + if (Cursor.lockState == CursorLockMode.None) return; + + _mouseLook = new Vector2(Input.GetAxis("Mouse X"), -Input.GetAxis("Mouse Y")); + _cinemachineTargetPitch += _mouseLook.y * RotationSpeed; + _rotationVelocity = _mouseLook.x * RotationSpeed; + + _cinemachineTargetPitch = _cinemachineTargetPitch.ClampAngle(BottomClamp, TopClamp); + + transform.Rotate(Vector3.up * _rotationVelocity); + + CinemachineCameraTarget.transform.localRotation = Quaternion.Euler(_cinemachineTargetPitch, 0.0f, 0.0f); + // CmdSetCameraPitch(_cinemachineTargetPitch); + } private void SetCamToHeadPos() { diff --git a/Assets/Scripts/Extensions.cs b/Assets/Scripts/Extensions.cs new file mode 100644 index 0000000..88711e5 --- /dev/null +++ b/Assets/Scripts/Extensions.cs @@ -0,0 +1,15 @@ +using UnityEngine; + +namespace Koptilnya +{ + public static class Extensions + { + public static float ClampAngle(this float value, float min, float max) + { + if (value < -360f) value += 360f; + if (value > 360f) value -= 360f; + + return Mathf.Clamp(value, min, max); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Extensions.cs.meta b/Assets/Scripts/Extensions.cs.meta new file mode 100644 index 0000000..a24bde0 --- /dev/null +++ b/Assets/Scripts/Extensions.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 58a54aa31ac945f98b665526ac0849f8 +timeCreated: 1710931930 \ No newline at end of file diff --git a/Assets/Scripts/Level/BuildModules/ProceduralPrefabs.cs b/Assets/Scripts/Level/BuildModules/ProceduralPrefabs.cs index c1971e8..1f246dd 100644 --- a/Assets/Scripts/Level/BuildModules/ProceduralPrefabs.cs +++ b/Assets/Scripts/Level/BuildModules/ProceduralPrefabs.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; using Mirror; +using Unity.AI.Navigation; using UnityEngine; using UnityEngine.Serialization; using Random = UnityEngine.Random; @@ -15,6 +16,7 @@ namespace Level.BuildModules [FormerlySerializedAs("StartingRoom")] public Room startingRoom; private Room[,] _spawnedRooms; + private List _flattenSpawnedRooms = new(); private int _size; @@ -43,6 +45,11 @@ namespace Level.BuildModules PlaceOneRoom(); } + + foreach (var room in _flattenSpawnedRooms) + { + room.GetComponent().BuildNavMesh(); + } if (enemyList.Count == networkManager.maxMonsters) return; @@ -92,6 +99,7 @@ namespace Level.BuildModules { newRoom.transform.position = new Vector3(position.x - _startCellX, 0, position.y - _startCellY) * newRoom.roomSize; _spawnedRooms[position.x, position.y] = newRoom; + _flattenSpawnedRooms.Add(newRoom); return; } } diff --git a/Assets/Scripts/Level/NavmeshBaker.cs b/Assets/Scripts/Level/NavmeshBaker.cs index 0279c49..4de188b 100644 --- a/Assets/Scripts/Level/NavmeshBaker.cs +++ b/Assets/Scripts/Level/NavmeshBaker.cs @@ -7,12 +7,7 @@ public class NavmeshBaker : MonoBehaviour { public NavMeshSurface Surface; - private void Start() - { - // yield return new WaitForSeconds(1); - Surface.BuildNavMesh(); - } - void Update() + void Start() { } diff --git a/Assets/Scripts/StateMachine/StateMachine.cs b/Assets/Scripts/StateMachine/StateMachine.cs index a043765..f45b8c2 100644 --- a/Assets/Scripts/StateMachine/StateMachine.cs +++ b/Assets/Scripts/StateMachine/StateMachine.cs @@ -53,7 +53,6 @@ namespace Koptilnya.StateMachine if (mCurrentState != null) { - Debug.Log($"{mCurrentState.ID} -> {state.ID}"); mCurrentState.Exit(); }