mirror of
https://github.com/ryzij/Cube-Tower-Defense.git
synced 2026-07-14 01:56:57 +00:00
Добавил визуализацию сброса пути
This commit is contained in:
@@ -170,6 +170,7 @@ MonoBehaviour:
|
|||||||
_grassBlockPrefab: {fileID: 1673662010218982673, guid: 8dd20c91f0d7a7b419f6bedcd1870cba, type: 3}
|
_grassBlockPrefab: {fileID: 1673662010218982673, guid: 8dd20c91f0d7a7b419f6bedcd1870cba, type: 3}
|
||||||
_pathStart: {fileID: 1415278839}
|
_pathStart: {fileID: 1415278839}
|
||||||
_pathEnd: {fileID: 761061820}
|
_pathEnd: {fileID: 761061820}
|
||||||
|
_resetBlockTime: 0.03
|
||||||
_pathFinish:
|
_pathFinish:
|
||||||
- {fileID: 1987853413}
|
- {fileID: 1987853413}
|
||||||
- {fileID: 1569763699}
|
- {fileID: 1569763699}
|
||||||
@@ -7536,7 +7537,6 @@ MonoBehaviour:
|
|||||||
m_EditorClassIdentifier: Assembly-CSharp::GameMenuButtons
|
m_EditorClassIdentifier: Assembly-CSharp::GameMenuButtons
|
||||||
_gameManager: {fileID: 1875710079}
|
_gameManager: {fileID: 1875710079}
|
||||||
_sandPathBuildService: {fileID: 305503}
|
_sandPathBuildService: {fileID: 305503}
|
||||||
_wallet: {fileID: 1030979928}
|
|
||||||
_mainMenuButton: {fileID: 512672405}
|
_mainMenuButton: {fileID: 512672405}
|
||||||
_nextLevelButton: {fileID: 769732337}
|
_nextLevelButton: {fileID: 769732337}
|
||||||
_resetPathButton: {fileID: 1026163394}
|
_resetPathButton: {fileID: 1026163394}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using UnityEngine;
|
|||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
public class SandPathBuildService : MonoBehaviour
|
public class SandPathBuildService : MonoBehaviour
|
||||||
{
|
{
|
||||||
@@ -11,6 +12,7 @@ public class SandPathBuildService : MonoBehaviour
|
|||||||
[SerializeField] private BlockScript _grassBlockPrefab;
|
[SerializeField] private BlockScript _grassBlockPrefab;
|
||||||
[SerializeField] private BlockScript _pathStart;
|
[SerializeField] private BlockScript _pathStart;
|
||||||
[SerializeField] private BlockScript _pathEnd;
|
[SerializeField] private BlockScript _pathEnd;
|
||||||
|
[SerializeField] private float _resetBlockTime = 0.5f;
|
||||||
[SerializeField] private BlockScript[] _pathFinish;
|
[SerializeField] private BlockScript[] _pathFinish;
|
||||||
[SerializeField] private BlockScript[] _predefinedBlocks;
|
[SerializeField] private BlockScript[] _predefinedBlocks;
|
||||||
|
|
||||||
@@ -31,6 +33,8 @@ public class SandPathBuildService : MonoBehaviour
|
|||||||
private BlockScript _currentBlock;
|
private BlockScript _currentBlock;
|
||||||
private readonly List<BlockScript> _blocksInPath = new();
|
private readonly List<BlockScript> _blocksInPath = new();
|
||||||
|
|
||||||
|
private bool _canBuild = true;
|
||||||
|
|
||||||
private void Start() => InitBlocks();
|
private void Start() => InitBlocks();
|
||||||
|
|
||||||
private void InitBlocks()
|
private void InitBlocks()
|
||||||
@@ -54,18 +58,7 @@ public class SandPathBuildService : MonoBehaviour
|
|||||||
_blockDetector.OnBlockClicked -= OnBlockDetected;
|
_blockDetector.OnBlockClicked -= OnBlockDetected;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResetPath()
|
public void ResetPath() => StartCoroutine(ResetPathCoroutine());
|
||||||
{
|
|
||||||
for (int i = _predefinedBlocks.Length; i < _blocksInPath.Count; i++)
|
|
||||||
{
|
|
||||||
var block = _blocksInPath[i];
|
|
||||||
Instantiate(_grassBlockPrefab, block.transform.position, block.transform.localRotation, block.transform.parent);
|
|
||||||
DestroyBlock(block);
|
|
||||||
}
|
|
||||||
|
|
||||||
_blocksInPath.Clear();
|
|
||||||
InitBlocks();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ResetLastBlock()
|
public void ResetLastBlock()
|
||||||
{
|
{
|
||||||
@@ -82,9 +75,23 @@ public class SandPathBuildService : MonoBehaviour
|
|||||||
_currentBlock = _blocksInPath.LastOrDefault();
|
_currentBlock = _blocksInPath.LastOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IEnumerator ResetPathCoroutine()
|
||||||
|
{
|
||||||
|
_canBuild = false;
|
||||||
|
var wait = new WaitForSeconds(_resetBlockTime);
|
||||||
|
|
||||||
|
while (_blocksInPath.Count > _predefinedBlocks.Length)
|
||||||
|
{
|
||||||
|
yield return wait;
|
||||||
|
ResetLastBlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
_canBuild = true;
|
||||||
|
}
|
||||||
|
|
||||||
private void OnBlockDetected(BlockScript block)
|
private void OnBlockDetected(BlockScript block)
|
||||||
{
|
{
|
||||||
if (_gameManager.CurrentState != GameManager.GameState.BuildingPath)
|
if (_gameManager.CurrentState != GameManager.GameState.BuildingPath || !_canBuild)
|
||||||
return;
|
return;
|
||||||
if (block == _currentBlock)
|
if (block == _currentBlock)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user