From 9485a34ab0337f1ef4cd576655cc04aa871242cb Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 19 May 2023 13:58:00 +0300 Subject: [PATCH 1/5] fix: reduce spawn time --- .../Scripts/Battlefield/BattleFieldBuilder.cs | 15 +++++++++--- .../Battlefield/NavMeshSurfaceExtensions.cs | 24 +++++++++++++++++++ .../NavMeshSurfaceExtensions.cs.meta | 3 +++ .../CharacterSelection/CharacterSelector.cs | 18 ++++++++++++++ Assets/Scripts/Hud/HealthBar.cs | 2 ++ 5 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 Assets/Scripts/Battlefield/NavMeshSurfaceExtensions.cs create mode 100644 Assets/Scripts/Battlefield/NavMeshSurfaceExtensions.cs.meta diff --git a/Assets/Scripts/Battlefield/BattleFieldBuilder.cs b/Assets/Scripts/Battlefield/BattleFieldBuilder.cs index 76b90334..9395cc59 100644 --- a/Assets/Scripts/Battlefield/BattleFieldBuilder.cs +++ b/Assets/Scripts/Battlefield/BattleFieldBuilder.cs @@ -1,9 +1,9 @@ +using System.Collections; using System.Collections.Generic; using Environment; using Misc; using UnityEngine; using UnityEngine.AI; -using UnityEngine.Serialization; using Random = System.Random; namespace Battlefield @@ -37,6 +37,7 @@ public class BattleFieldBuilder : MonoBehaviour private readonly Random _rnd = new Random(); private float xCorrection; private float zCorrection; + private void OnValidate() { this.CheckIfNull(_wall, _border, _grass, _ground); @@ -49,6 +50,12 @@ private void Start() zCorrection = -_fieldWidth * _tileSize; BuildTerrain(); BakeNavMesh(); + + Invoke(nameof(Spawn), 0.1f); + } + + private void Spawn() + { PlaceBots(); ObjectsPool.Instance.SetPlayerSpawnPosition(GetPlayerSpotCoordinates()); ObjectsPool.Instance.SetHeroes(Heroes); @@ -95,7 +102,7 @@ private void BuildTerrain() Instantiate(_border, new Vector3(xCorrection + i * _tileSize, 0, zCorrection + j * _tileSize), Quaternion.identity); - _navMeshSurfaces.Add(createdObject.GetComponent()); + // _navMeshSurfaces.Add(createdObject.GetComponent()); break; case 3: Instantiate(_grass, @@ -153,7 +160,9 @@ private void BakeNavMesh() { foreach (var navMeshSurface in _navMeshSurfaces) { - navMeshSurface.BuildNavMesh(); + navMeshSurface.collectObjects = CollectObjects.All; + navMeshSurface.useGeometry = NavMeshCollectGeometry.RenderMeshes; + navMeshSurface.BuildNavMeshAsync(); } } } diff --git a/Assets/Scripts/Battlefield/NavMeshSurfaceExtensions.cs b/Assets/Scripts/Battlefield/NavMeshSurfaceExtensions.cs new file mode 100644 index 00000000..9455af20 --- /dev/null +++ b/Assets/Scripts/Battlefield/NavMeshSurfaceExtensions.cs @@ -0,0 +1,24 @@ +using UnityEngine; +using UnityEngine.AI; + +namespace Battlefield +{ + public static class NavMeshSurfaceExtensions + { + public static AsyncOperation BuildNavMeshAsync(this NavMeshSurface surface) + { + surface.RemoveData(); + surface.navMeshData = new NavMeshData(surface.agentTypeID) + { + name = surface.gameObject.name, + position = surface.transform.position, + rotation = surface.transform.rotation + }; + + if (surface.isActiveAndEnabled) + surface.AddData(); + + return surface.UpdateNavMesh(surface.navMeshData); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Battlefield/NavMeshSurfaceExtensions.cs.meta b/Assets/Scripts/Battlefield/NavMeshSurfaceExtensions.cs.meta new file mode 100644 index 00000000..dc2290a3 --- /dev/null +++ b/Assets/Scripts/Battlefield/NavMeshSurfaceExtensions.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 748d0ef1d8ef4c48afd8557f7b9316a9 +timeCreated: 1684491300 \ No newline at end of file diff --git a/Assets/Scripts/CharacterSelection/CharacterSelector.cs b/Assets/Scripts/CharacterSelection/CharacterSelector.cs index 804ea641..aee71baf 100644 --- a/Assets/Scripts/CharacterSelection/CharacterSelector.cs +++ b/Assets/Scripts/CharacterSelection/CharacterSelector.cs @@ -6,6 +6,7 @@ using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.SceneManagement; +using UnityEngine.UI; namespace CharacterSelection { @@ -15,6 +16,9 @@ public class CharacterSelector : MonoBehaviour [SerializeField] private float _shiftDistance = 2f; [SerializeField] private float _shiftSpeed = 2f; [SerializeField] private GameEvent _onCharacterNameChanged; + + [Header("Scene Loading")] + [SerializeField] private GameObject _loadingScreen; private int _selectedCharacterIndex = 0; private bool _isMoving = false; @@ -28,7 +32,21 @@ private void Start() public void SelectCharacter() { SceneManager.sceneLoaded += OnSceneLoaded; + _loadingScreen.SetActive(true); SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1); + // StartCoroutine(LoadSceneAsync(SceneManager.GetActiveScene().buildIndex + 1)); + } + + private IEnumerator LoadSceneAsync(int sceneIndex) + { + AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(sceneIndex); + + _loadingScreen.SetActive(true); + + while (!asyncOperation.isDone) + { + yield return null; + } } private void OnSceneLoaded(Scene scene, LoadSceneMode mode) diff --git a/Assets/Scripts/Hud/HealthBar.cs b/Assets/Scripts/Hud/HealthBar.cs index 8ef71f61..cb46cdc2 100644 --- a/Assets/Scripts/Hud/HealthBar.cs +++ b/Assets/Scripts/Hud/HealthBar.cs @@ -34,6 +34,8 @@ private void Update() { if (_isHud is false) { + if (_camera == null) _camera = Camera.main; + _objectToRotate.transform.rotation = Quaternion.LookRotation(transform.position - _camera.transform.position); } } From 62d15db0316f22c4fa70931ed677d8f3aa243987 Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 19 May 2023 13:58:09 +0300 Subject: [PATCH 2/5] chore: update scenes --- Assets/Scenes/BattleField.unity | 4 - Assets/Scenes/CharacterChoice.unity | 137 ++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+), 4 deletions(-) diff --git a/Assets/Scenes/BattleField.unity b/Assets/Scenes/BattleField.unity index 80830f5f..995bc005 100644 --- a/Assets/Scenes/BattleField.unity +++ b/Assets/Scenes/BattleField.unity @@ -493,10 +493,6 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} - - target: {fileID: 8942223173646349031, guid: 00ef75323699d3b4b8c135a5653bacf2, type: 3} - propertyPath: _heroesCount - value: 30 - objectReference: {fileID: 0} - target: {fileID: 8942223173646349032, guid: 00ef75323699d3b4b8c135a5653bacf2, type: 3} propertyPath: m_Name value: BattleFieldBuilder diff --git a/Assets/Scenes/CharacterChoice.unity b/Assets/Scenes/CharacterChoice.unity index 3cfde1c7..46ba53b0 100644 --- a/Assets/Scenes/CharacterChoice.unity +++ b/Assets/Scenes/CharacterChoice.unity @@ -313,6 +313,7 @@ MonoBehaviour: _shiftDistance: 5 _shiftSpeed: 0.7 _onCharacterNameChanged: {fileID: 11400000, guid: 63d411f892bc38c46b1a256f96df4c24, type: 2} + _loadingScreen: {fileID: 2096120882} --- !u!1 &240939033 GameObject: m_ObjectHideFlags: 0 @@ -1380,6 +1381,7 @@ RectTransform: - {fileID: 551379757} - {fileID: 1347588887} - {fileID: 923484636} + - {fileID: 2096120883} m_Father: {fileID: 0} m_RootOrder: 9 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -3861,6 +3863,141 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2036183229} m_CullTransparentMesh: 1 +--- !u!1 &2096120882 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2096120883} + - component: {fileID: 2096120885} + - component: {fileID: 2096120884} + m_Layer: 5 + m_Name: Loading + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 0 +--- !u!224 &2096120883 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2096120882} + 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: 584174524} + m_RootOrder: 3 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: -613.5, y: -418.3} + m_SizeDelta: {x: 485.08, y: 50} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &2096120884 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2096120882} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_text: Map is generating... + m_isRightToLeft: 0 + m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_fontSharedMaterials: [] + m_fontMaterial: {fileID: 0} + m_fontMaterials: [] + m_fontColor32: + serializedVersion: 2 + rgba: 4294967295 + m_fontColor: {r: 1, g: 1, b: 1, a: 1} + m_enableVertexGradient: 0 + m_colorMode: 3 + m_fontColorGradient: + topLeft: {r: 1, g: 1, b: 1, a: 1} + topRight: {r: 1, g: 1, b: 1, a: 1} + bottomLeft: {r: 1, g: 1, b: 1, a: 1} + bottomRight: {r: 1, g: 1, b: 1, a: 1} + m_fontColorGradientPreset: {fileID: 0} + m_spriteAsset: {fileID: 0} + m_tintAllSprites: 0 + m_StyleSheet: {fileID: 0} + m_TextStyleHashCode: -1183493901 + m_overrideHtmlColors: 0 + m_faceColor: + serializedVersion: 2 + rgba: 4294967295 + m_fontSize: 29.8 + m_fontSizeBase: 29.8 + m_fontWeight: 400 + m_enableAutoSizing: 0 + m_fontSizeMin: 18 + m_fontSizeMax: 72 + m_fontStyle: 1 + m_HorizontalAlignment: 2 + m_VerticalAlignment: 256 + m_textAlignment: 65535 + m_characterSpacing: 0 + m_wordSpacing: 0 + m_lineSpacing: 0 + m_lineSpacingMax: 0 + m_paragraphSpacing: 0 + m_charWidthMaxAdj: 0 + m_enableWordWrapping: 1 + m_wordWrappingRatios: 0.4 + m_overflowMode: 0 + m_linkedTextComponent: {fileID: 0} + parentLinkedComponent: {fileID: 0} + m_enableKerning: 1 + m_enableExtraPadding: 0 + checkPaddingRequired: 0 + m_isRichText: 1 + m_parseCtrlCharacters: 1 + m_isOrthographic: 1 + m_isCullingEnabled: 0 + m_horizontalMapping: 0 + m_verticalMapping: 0 + m_uvLineOffset: 0 + m_geometrySortingOrder: 0 + m_IsTextObjectScaleStatic: 0 + m_VertexBufferAutoSizeReduction: 0 + m_useMaxVisibleDescender: 1 + m_pageToDisplay: 1 + m_margin: {x: 0, y: 0, z: 0, w: 0} + m_isUsingLegacyAnimationComponent: 0 + m_isVolumetricText: 0 + m_hasFontAssetChanged: 0 + m_baseMaterial: {fileID: 0} + m_maskOffset: {x: 0, y: 0, z: 0, w: 0} +--- !u!222 &2096120885 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2096120882} + m_CullTransparentMesh: 1 --- !u!1 &2130229080 GameObject: m_ObjectHideFlags: 0 From 3dc73e3d952cfac3f008904baaf4e6b97b8d60bd Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 19 May 2023 13:58:20 +0300 Subject: [PATCH 3/5] chore: increase player health --- Assets/Prefabs/Heroes/Characters/Player.prefab | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/Prefabs/Heroes/Characters/Player.prefab b/Assets/Prefabs/Heroes/Characters/Player.prefab index 2fce38c3..f8346bc0 100644 --- a/Assets/Prefabs/Heroes/Characters/Player.prefab +++ b/Assets/Prefabs/Heroes/Characters/Player.prefab @@ -654,8 +654,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 27626dbb1b1e46aebdd4bbab6ae8858d, type: 3} m_Name: m_EditorClassIdentifier: - _maxHealthPoints: 250 - _healthPoints: 250 + _maxHealthPoints: 400 + _healthPoints: 400 _onDeath: {fileID: 11400000, guid: 68d23cd08d27b8e44b38090202c53f2f, type: 2} _onHealthChanged: {fileID: 11400000, guid: eddf2d5640e89e646a041d096b9c5341, type: 2} --- !u!114 &4340838794852804689 From d693f30ae264d34cea856b48178feee8e95af950 Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 19 May 2023 13:58:32 +0300 Subject: [PATCH 4/5] chore: configure builder --- Assets/Prefabs/BattleField Builder.prefab | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Assets/Prefabs/BattleField Builder.prefab b/Assets/Prefabs/BattleField Builder.prefab index 0723200c..5a768a52 100644 --- a/Assets/Prefabs/BattleField Builder.prefab +++ b/Assets/Prefabs/BattleField Builder.prefab @@ -58,8 +58,9 @@ MonoBehaviour: _fieldLength: 30 _fieldWidth: 30 _tileSize: 2 - _wallDensity: 0.1 + _wallDensity: 0.0404 _bushesDensity: 0.03 _maxBushSize: 3 _potsCount: 9 - _heroesCount: 14 + _heroesCount: 20 + _spawnDistance: 8 From 9afecb23b8c3b681ed197dbfcb8c54896f3b30be Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 19 May 2023 13:58:46 +0300 Subject: [PATCH 5/5] fix: update env prefabs --- Assets/Prefabs/Environment/Ground.prefab | 6 +++--- Assets/Prefabs/Environment/Wall.prefab | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Assets/Prefabs/Environment/Ground.prefab b/Assets/Prefabs/Environment/Ground.prefab index 86e038b5..f2196591 100644 --- a/Assets/Prefabs/Environment/Ground.prefab +++ b/Assets/Prefabs/Environment/Ground.prefab @@ -26,8 +26,8 @@ Transform: m_GameObject: {fileID: 3321912436738672957} 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_LocalScale: {x: 11.809999, y: 11.809999, z: 11.809999} + m_ConstrainProportionsScale: 1 m_Children: - {fileID: 4241119107875755153} m_Father: {fileID: 0} @@ -90,7 +90,7 @@ Transform: m_GameObject: {fileID: 6908426290981875276} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 20, y: 1, z: 20} + m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 1992661901449262017} diff --git a/Assets/Prefabs/Environment/Wall.prefab b/Assets/Prefabs/Environment/Wall.prefab index 3bcc99f1..aa32a20a 100644 --- a/Assets/Prefabs/Environment/Wall.prefab +++ b/Assets/Prefabs/Environment/Wall.prefab @@ -10,6 +10,7 @@ GameObject: m_Component: - component: {fileID: 4227798970065305816} - component: {fileID: 3622335821436744679} + - component: {fileID: 5044149668879186811} m_Layer: 0 m_Name: Wall m_TagString: Untagged @@ -62,6 +63,22 @@ MonoBehaviour: m_VoxelSize: 0.16666667 m_BuildHeightMesh: 0 m_NavMeshData: {fileID: 0} +--- !u!114 &5044149668879186811 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4459002749115364136} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1e3fdca004f2d45fe8abbed571a8abd5, type: 3} + m_Name: + m_EditorClassIdentifier: + m_OverrideArea: 1 + m_Area: 1 + m_IgnoreFromBuild: 0 + m_AffectedAgents: ffffffff --- !u!1 &4903476772157447637 GameObject: m_ObjectHideFlags: 0