Compare commits

...

2 Commits

4 changed files with 121 additions and 14 deletions
+81 -2
View File
@@ -170,6 +170,7 @@ MonoBehaviour:
_grassBlockPrefab: {fileID: 1673662010218982673, guid: 8dd20c91f0d7a7b419f6bedcd1870cba, type: 3}
_pathStart: {fileID: 1415278839}
_pathEnd: {fileID: 761061820}
_resetBlockTime: 0.03
_pathFinish:
- {fileID: 1987853413}
- {fileID: 1569763699}
@@ -7536,7 +7537,6 @@ MonoBehaviour:
m_EditorClassIdentifier: Assembly-CSharp::GameMenuButtons
_gameManager: {fileID: 1875710079}
_sandPathBuildService: {fileID: 305503}
_wallet: {fileID: 1030979928}
_mainMenuButton: {fileID: 512672405}
_nextLevelButton: {fileID: 769732337}
_resetPathButton: {fileID: 1026163394}
@@ -14184,6 +14184,84 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 8d6715c95501a4f49bd34c8832850f32, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::BlockScript
--- !u!1001 &1522202350
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 1739395622}
m_Modifications:
- target: {fileID: 1506208594825835263, guid: f43f402f15b1069488b837e6f472a868, type: 3}
propertyPath: m_LocalScale.x
value: 0.73
objectReference: {fileID: 0}
- target: {fileID: 1506208594825835263, guid: f43f402f15b1069488b837e6f472a868, type: 3}
propertyPath: m_LocalScale.y
value: 0.73
objectReference: {fileID: 0}
- target: {fileID: 1506208594825835263, guid: f43f402f15b1069488b837e6f472a868, type: 3}
propertyPath: m_LocalScale.z
value: 0.73
objectReference: {fileID: 0}
- target: {fileID: 1506208594825835263, guid: f43f402f15b1069488b837e6f472a868, type: 3}
propertyPath: m_LocalPosition.x
value: -1.774
objectReference: {fileID: 0}
- target: {fileID: 1506208594825835263, guid: f43f402f15b1069488b837e6f472a868, type: 3}
propertyPath: m_LocalPosition.y
value: -0.71799994
objectReference: {fileID: 0}
- target: {fileID: 1506208594825835263, guid: f43f402f15b1069488b837e6f472a868, type: 3}
propertyPath: m_LocalPosition.z
value: -0.506
objectReference: {fileID: 0}
- target: {fileID: 1506208594825835263, guid: f43f402f15b1069488b837e6f472a868, type: 3}
propertyPath: m_LocalRotation.w
value: 0.7071068
objectReference: {fileID: 0}
- target: {fileID: 1506208594825835263, guid: f43f402f15b1069488b837e6f472a868, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1506208594825835263, guid: f43f402f15b1069488b837e6f472a868, type: 3}
propertyPath: m_LocalRotation.y
value: -0.7071068
objectReference: {fileID: 0}
- target: {fileID: 1506208594825835263, guid: f43f402f15b1069488b837e6f472a868, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1506208594825835263, guid: f43f402f15b1069488b837e6f472a868, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1506208594825835263, guid: f43f402f15b1069488b837e6f472a868, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: -90
objectReference: {fileID: 0}
- target: {fileID: 1506208594825835263, guid: f43f402f15b1069488b837e6f472a868, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1506208594825835263, guid: f43f402f15b1069488b837e6f472a868, type: 3}
propertyPath: m_ConstrainProportionsScale
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2282463062789957701, guid: f43f402f15b1069488b837e6f472a868, type: 3}
propertyPath: m_Name
value: door_1a (1)
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: f43f402f15b1069488b837e6f472a868, type: 3}
--- !u!4 &1522202351 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 1506208594825835263, guid: f43f402f15b1069488b837e6f472a868, type: 3}
m_PrefabInstance: {fileID: 1522202350}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &1543141569
PrefabInstance:
m_ObjectHideFlags: 0
@@ -15108,7 +15186,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 1506208594825835263, guid: f43f402f15b1069488b837e6f472a868, type: 3}
propertyPath: m_LocalPosition.x
value: 1.961
value: 1.986
objectReference: {fileID: 0}
- target: {fileID: 1506208594825835263, guid: f43f402f15b1069488b837e6f472a868, type: 3}
propertyPath: m_LocalPosition.y
@@ -15919,6 +15997,7 @@ Transform:
m_Children:
- {fileID: 692742697}
- {fileID: 1642372930}
- {fileID: 1522202351}
m_Father: {fileID: 35686721}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!54 &1739395623
+5 -2
View File
@@ -16,8 +16,11 @@ public class BlockDestoyReward : MonoBehaviour
_sandPathBuildService.OnBlockDestroy -= OnBlockDestroy;
}
private void OnBlockDestroy(BlockScript _)
private void OnBlockDestroy(BlockScript block)
{
_wallet.AddMoney(_reward);
if (block.Type == BlockScript.BlockType.Grass)
_wallet.AddMoney(_reward);
else if (block.Type == BlockScript.BlockType.Sand)
_wallet.TakeMoney(_reward);
}
}
+35 -8
View File
@@ -2,6 +2,7 @@ using UnityEngine;
using UnityEngine.Events;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
public class SandPathBuildService : MonoBehaviour
{
@@ -11,6 +12,7 @@ public class SandPathBuildService : MonoBehaviour
[SerializeField] private BlockScript _grassBlockPrefab;
[SerializeField] private BlockScript _pathStart;
[SerializeField] private BlockScript _pathEnd;
[SerializeField] private float _resetBlockTime = 0.5f;
[SerializeField] private BlockScript[] _pathFinish;
[SerializeField] private BlockScript[] _predefinedBlocks;
@@ -31,6 +33,8 @@ public class SandPathBuildService : MonoBehaviour
private BlockScript _currentBlock;
private readonly List<BlockScript> _blocksInPath = new();
private bool _canBuild = true;
private void Start() => InitBlocks();
private void InitBlocks()
@@ -54,23 +58,46 @@ public class SandPathBuildService : MonoBehaviour
_blockDetector.OnBlockClicked -= OnBlockDetected;
}
public void ResetPath()
public void ResetPath() => StartCoroutine(ResetPathCoroutine());
public void ResetLastBlock()
{
for (int i = _predefinedBlocks.Length; i < _blocksInPath.Count; i++)
if (_predefinedBlocks.Contains(_currentBlock))
return;
_blocksInPath.Remove(_currentBlock);
Instantiate(_grassBlockPrefab,
_currentBlock.transform.position,
_currentBlock.transform.localRotation,
_currentBlock.transform.parent);
DestroyBlock(_currentBlock);
_currentBlock = _blocksInPath.LastOrDefault();
}
private IEnumerator ResetPathCoroutine()
{
_canBuild = false;
var wait = new WaitForSeconds(_resetBlockTime);
while (_blocksInPath.Count > _predefinedBlocks.Length)
{
var block = _blocksInPath[i];
Instantiate(_grassBlockPrefab, block.transform.position, block.transform.localRotation, block.transform.parent);
Destroy(block.gameObject);
yield return wait;
ResetLastBlock();
}
_blocksInPath.Clear();
InitBlocks();
_canBuild = true;
}
private void OnBlockDetected(BlockScript block)
{
if (_gameManager.CurrentState != GameManager.GameState.BuildingPath)
if (_gameManager.CurrentState != GameManager.GameState.BuildingPath || !_canBuild)
return;
if (block == _currentBlock)
{
ResetLastBlock();
return;
}
if (!block.CompareTag("GrassBlock") ||
!_currentBlock.GetNeighbors().Contains(block) ||
block.GetNeighbors().Count((o) => o.Type == BlockScript.BlockType.Sand) > 1)
-2
View File
@@ -5,7 +5,6 @@ public class GameMenuButtons : MonoBehaviour
{
[SerializeField] private GameManager _gameManager;
[SerializeField] private SandPathBuildService _sandPathBuildService;
[SerializeField] private Wallet _wallet;
[SerializeField] private Button _mainMenuButton;
[SerializeField] private Button _nextLevelButton;
[SerializeField] private Button _resetPathButton;
@@ -49,7 +48,6 @@ public class GameMenuButtons : MonoBehaviour
private void OnResetButtonClick()
{
_sandPathBuildService.ResetPath();
_wallet.TakeMoney(_wallet.Money);
_gameManager.CurrentState = GameManager.GameState.BuildingPath;
}