From 3d15c0dc4cb9dcb412e7488515fa7aac6f087a81 Mon Sep 17 00:00:00 2001 From: LikhenkoVG <106115719+LikhenkoVG@users.noreply.github.com> Date: Tue, 10 Dec 2024 20:01:30 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BA=D1=80=D0=B8=D0=BF=D1=82=20=D0=B3?= =?UTF-8?q?=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D0=B8=20=D0=BA=D0=B0?= =?UTF-8?q?=D1=80=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Почти готовый скрипт генерации карты - готова генерация при запуске сцены, создаётся заданное число тайлов. Начал писать удаление и создание новых тайлов по тому, пока идёт игрок. --- .../Scenes/Test/Scripts/SpawnTileScript.cs | 26 +++-- .../Scenes/Test/Scripts/TileManagerScript.cs | 104 ++++++++++++++++++ .../Test/Scripts}/TileManagerScript.cs.meta | 0 .../Scenes/Test/Test Generate Map.unity | 10 +- Assets/TileManagerScript.cs | 42 ------- 5 files changed, 126 insertions(+), 56 deletions(-) create mode 100644 Assets/Crossy Road VR/Scenes/Test/Scripts/TileManagerScript.cs rename Assets/{ => Crossy Road VR/Scenes/Test/Scripts}/TileManagerScript.cs.meta (100%) delete mode 100644 Assets/TileManagerScript.cs diff --git a/Assets/Crossy Road VR/Scenes/Test/Scripts/SpawnTileScript.cs b/Assets/Crossy Road VR/Scenes/Test/Scripts/SpawnTileScript.cs index e0ce06e..e717a38 100644 --- a/Assets/Crossy Road VR/Scenes/Test/Scripts/SpawnTileScript.cs +++ b/Assets/Crossy Road VR/Scenes/Test/Scripts/SpawnTileScript.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; using UnityEngine; +using UnityEngine.UIElements; public class SpawnTileScript : MonoBehaviour { @@ -17,19 +18,20 @@ public class SpawnTileScript : MonoBehaviour } - private void OnTriggerEnter(Collider other) - { - if (other.gameObject.tag == "Player") - { - if (_Instantiated) - { - GenerateTile(_Tiles[0]); - } - } - } + //private void OnTriggerEnter(Collider other) + //{ + // if (other.gameObject.tag == "Player") + // { + // if (_Instantiated) + // { + // GenerateTile(_Tiles[0]); + // } + // } + //} - private void GenerateTile(GameObject tile) + public void GenerateTile(GameObject tile, Vector3 pos, Quaternion rot) { - Instantiate(tile, new Vector3(_CurrentTile.transform.position.x, _CurrentTile.transform.position.y, _CurrentTile.transform.position.z+20), _CurrentTile.transform.rotation); + //Instantiate(tile, new Vector3(_CurrentTile.transform.position.x, _CurrentTile.transform.position.y, _CurrentTile.transform.position.z+20), _CurrentTile.transform.rotation); + Instantiate(tile, pos, rot); } } diff --git a/Assets/Crossy Road VR/Scenes/Test/Scripts/TileManagerScript.cs b/Assets/Crossy Road VR/Scenes/Test/Scripts/TileManagerScript.cs new file mode 100644 index 0000000..3514db1 --- /dev/null +++ b/Assets/Crossy Road VR/Scenes/Test/Scripts/TileManagerScript.cs @@ -0,0 +1,104 @@ +using System.Collections.Generic; +using System.Linq; +using Unity.VisualScripting; +using UnityEngine; + +/// +/// менеджер тайлов +/// инициализация, создание новых, удаление, отслеживание кол-ва тайлов +/// +public class TileManagerScript : MonoBehaviour +{ + /// + /// число тайлов, которые будут созданы + /// + [SerializeField] + private int _NumTile; + + /// + /// номер текущего тайла + /// + public int CurrentTile; + + // + [SerializeField] + private float _DistanceTiles; + + [SerializeField] + private List _TilesPref = new List(); + + /// + /// поле массива тайлов + /// + private List _Tiles; + + // при запуске сцены, создание новых тайлов + private void Awake() + { + Debug.Log($"NumTile = {_NumTile}"); + // создание массива + _Tiles = new List(_NumTile); + Debug.Log($"_Tiles = {_Tiles.Count}"); + // запихивание в массив тайлов null, чтобы понимать, что там пусто + for (int i = 0; i < _Tiles.Count; i++) + { + _Tiles[i] = null; + } + Debug.Log($"_Tiles = {_Tiles.Count}"); + float z = (_NumTile/2) * _DistanceTiles; + Debug.Log($"z = {z}"); + + // создание тайлов назад от игрока, где i номер тайла, а z координата transfrom.position.z + for (int i = 0; i < _NumTile; i++) + { + + GenerateTile(new Vector3(0, 0, z), new Quaternion(0, 0, 0, 0)); + z -= _DistanceTiles; + } + } + + + /// + /// Генератор тайлов с собственным положением + /// + /// + /// + /// + public void GenerateTile(Vector3 pos, Quaternion rot) + { + Instantiate(_TilesPref[0], pos, rot); + } + /// + /// Генератор тайлов за последним + /// + public void GenerateTile() + { + Vector3 pos = _Tiles.Last().transform.position; + Quaternion rot = _Tiles.Last().transform.rotation; + Vector3 newVector = new Vector3(pos.x, pos.y, pos.z + _DistanceTiles); + Instantiate(_TilesPref[0], new Vector3(), rot); + DeleteTile(); + } + + /// + /// Удалитель тайлов + /// + /// + public void DeleteTile() + { + Destroy(_Tiles[0]); + _Tiles.RemoveAt(0); + //GenerateTile(); + } + + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/TileManagerScript.cs.meta b/Assets/Crossy Road VR/Scenes/Test/Scripts/TileManagerScript.cs.meta similarity index 100% rename from Assets/TileManagerScript.cs.meta rename to Assets/Crossy Road VR/Scenes/Test/Scripts/TileManagerScript.cs.meta diff --git a/Assets/Crossy Road VR/Scenes/Test/Test Generate Map.unity b/Assets/Crossy Road VR/Scenes/Test/Test Generate Map.unity index cf291dd..bb1b791 100644 --- a/Assets/Crossy Road VR/Scenes/Test/Test Generate Map.unity +++ b/Assets/Crossy Road VR/Scenes/Test/Test Generate Map.unity @@ -425,6 +425,10 @@ PrefabInstance: propertyPath: m_Name value: Floor (Black) objectReference: {fileID: 0} + - target: {fileID: 8202227058476080034, guid: d113347864294f441883149abd377a24, type: 3} + propertyPath: m_IsActive + value: 0 + objectReference: {fileID: 0} m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] @@ -565,9 +569,11 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 673f57172fdd6084f8c03e4433c6967c, type: 3} m_Name: m_EditorClassIdentifier: - _NumTile: 3 + _NumTile: 6 CurrentTile: 0 - _Tiles: [] + _DistanceTiles: 20 + _TilesPref: + - {fileID: 8202227058476080034, guid: d113347864294f441883149abd377a24, type: 3} --- !u!4 &1034189939 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/TileManagerScript.cs b/Assets/TileManagerScript.cs deleted file mode 100644 index 8deadc1..0000000 --- a/Assets/TileManagerScript.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class TileManagerScript : MonoBehaviour -{ - [SerializeField] - private int _NumTile = 3; - public int CurrentTile; - - [SerializeField] - private List _Tiles; - - // Start is called before the first frame update - - private void Awake() - { - _Tiles = new List(_NumTile); - CurrentTile = _NumTile / 2; - - for (int i = 0; i < _Tiles.Count; i++) - { - _Tiles[i] = null; - } - - for (int i = 0; i < _Tiles.Count; i++) - { - - } - } - - void Start() - { - - } - - // Update is called once per frame - void Update() - { - - } -}