From 6eb981cf59a8b9cbb9b5d52ccba7dfe8d50b3d4b Mon Sep 17 00:00:00 2001 From: dddushesss <37773701+dddushesss@users.noreply.github.com> Date: Thu, 6 Jan 2022 12:04:20 +0300 Subject: [PATCH] effect for rounding --- Assets/Scripts/HexFiled/HexCell.cs | 2 ++ Assets/Scripts/HexFiled/PaintedController.cs | 17 ++++++++-- Assets/{ => Scripts/Items}/TowerView.cs | 0 Assets/{ => Scripts/Items}/TowerView.cs.meta | 0 Assets/Scripts/TimerHelper.cs | 35 ++++++++++++++++++-- Assets/Scripts/Units/Unit.cs | 3 +- 6 files changed, 49 insertions(+), 8 deletions(-) rename Assets/{ => Scripts/Items}/TowerView.cs (100%) rename Assets/{ => Scripts/Items}/TowerView.cs.meta (100%) diff --git a/Assets/Scripts/HexFiled/HexCell.cs b/Assets/Scripts/HexFiled/HexCell.cs index 9bc4c105..bc23f3c1 100644 --- a/Assets/Scripts/HexFiled/HexCell.cs +++ b/Assets/Scripts/HexFiled/HexCell.cs @@ -64,6 +64,8 @@ namespace HexFiled _renderer.material.mainTexture = HexGrid.Colors[color].Texture; _color = color; + MusicController.Instance.PlayRandomClip(MusicController.Instance.MusicData.SfxMusic.Captures, + gameObject); Instantiate(HexGrid.Colors[color].VFXPrefab, transform); onHexPainted?.Invoke(this); } diff --git a/Assets/Scripts/HexFiled/PaintedController.cs b/Assets/Scripts/HexFiled/PaintedController.cs index 3988ea02..a0b5a771 100644 --- a/Assets/Scripts/HexFiled/PaintedController.cs +++ b/Assets/Scripts/HexFiled/PaintedController.cs @@ -1,7 +1,10 @@ +using System; using System.Collections.Generic; using System.Linq; using Data; -using UnityEngine; +using DefaultNamespace; +using Units; +using Random = UnityEngine.Random; namespace HexFiled { @@ -75,7 +78,8 @@ namespace HexFiled where !path.hasPath select path) { - path.field.ForEach(x => x.PaintHex(UnitColor.GREY)); + TryPaintHexList(path, UnitColor.GREY); + } } } @@ -86,7 +90,14 @@ namespace HexFiled { if (!path.hasPath) { - path.field.ForEach(y => y.PaintHex(color)); + List> actions = new List>(); + + path.field.ForEach(x => + { + actions.Add(x.PaintHex); + }); + + TimerHelper.Instance.StartTimer(actions, 0.05f, color); } return path.hasPath; diff --git a/Assets/TowerView.cs b/Assets/Scripts/Items/TowerView.cs similarity index 100% rename from Assets/TowerView.cs rename to Assets/Scripts/Items/TowerView.cs diff --git a/Assets/TowerView.cs.meta b/Assets/Scripts/Items/TowerView.cs.meta similarity index 100% rename from Assets/TowerView.cs.meta rename to Assets/Scripts/Items/TowerView.cs.meta diff --git a/Assets/Scripts/TimerHelper.cs b/Assets/Scripts/TimerHelper.cs index 06e9af0b..68c0fe41 100644 --- a/Assets/Scripts/TimerHelper.cs +++ b/Assets/Scripts/TimerHelper.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using UnityEngine; namespace DefaultNamespace @@ -9,26 +10,54 @@ namespace DefaultNamespace private static TimerHelper _instance; public static TimerHelper Instance => _instance; + public static List OnCorutineEndedList; private void Start() { if (_instance == null) + { _instance = this; + OnCorutineEndedList = new List(); + } else { Destroy(this); } } - public void StartTimer(Action action, int time) + public void StartTimer(Action action, float time) { StartCoroutine(Timer(action, time)); } - - IEnumerator Timer(Action action, int time) + public void StartTimer(Action action, float time, T param) + { + StartCoroutine(Timer(action, time, param)); + } + + public void StartTimer(List> actions, float time, T param) + { + StartCoroutine(Timer(actions, time, param)); + } + + IEnumerator Timer(Action action, float time) { yield return new WaitForSeconds(time); action.Invoke(); } + + IEnumerator Timer(Action action, float time, T param) + { + yield return new WaitForSeconds(time); + action.Invoke(param); + } + + IEnumerator Timer(List> actions, float time, T param) + { + foreach (var action in actions) + { + yield return new WaitForSeconds(time); + action.Invoke(param); + } + } } } \ No newline at end of file diff --git a/Assets/Scripts/Units/Unit.cs b/Assets/Scripts/Units/Unit.cs index a473036d..68b16bd9 100644 --- a/Assets/Scripts/Units/Unit.cs +++ b/Assets/Scripts/Units/Unit.cs @@ -220,8 +220,7 @@ namespace Units else { CaptureHex(); - MusicController.Instance.PlayRandomClip(MusicController.Instance.MusicData.SfxMusic.Captures, - _cell.gameObject); + } _isHardToCapture = false;