fix: first clicks now are properly detected
This commit is contained in:
parent
db839ea96d
commit
2cddb7a7b9
13 changed files with 99 additions and 30 deletions
16
Assets/Scripts/View/Collections/InputCallbackCollection.cs
Normal file
16
Assets/Scripts/View/Collections/InputCallbackCollection.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using Presenter;
|
||||
|
||||
namespace View.Collections {
|
||||
public class InputCallbackCollection : IInputCallback {
|
||||
private readonly IInputCallback[] _inputs;
|
||||
|
||||
public InputCallbackCollection(IInputCallback[] inputs) {
|
||||
_inputs = inputs;
|
||||
}
|
||||
|
||||
public void OnInputReceived() {
|
||||
foreach (IInputCallback input in _inputs)
|
||||
input.OnInputReceived();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
using Presenter;
|
||||
|
||||
namespace View.Collections {
|
||||
public class ScoreViewCollection : IScoreView {
|
||||
private readonly IScoreView[] _inputs;
|
||||
|
||||
public ScoreViewCollection(IScoreView[] inputs) {
|
||||
_inputs = inputs;
|
||||
}
|
||||
|
||||
public void UpdateView(int score) {
|
||||
foreach (IScoreView input in _inputs)
|
||||
input.UpdateView(score);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,21 +20,21 @@ namespace View {
|
|||
Score = new Score(10, 10);
|
||||
|
||||
IScoreView input = FindObjectOfType<ScoreView>();
|
||||
IScoreView visibility = FindObjectOfType<UIVisibility>();
|
||||
IScoreView inputCollections = new ScoreViewCollection(new[] { input, visibility });
|
||||
|
||||
IRoseSpawner spawner = FindObjectOfType<RoseSpawner>();
|
||||
|
||||
IInputCallback visibility = FindObjectOfType<UIVisibility>();
|
||||
IInputCallback growParticles = FindObjectOfType<GrowParticlesSpawner>();
|
||||
IInputCallback inputCallback = new InputCallbackCollection(new[] { visibility, growParticles });
|
||||
IRoseGrow growAnimation = FindObjectOfType<GrowAnimation>();
|
||||
|
||||
ExpressionClick = new ExpressionClick(Score, inputCollections, spawner, growAnimation, growParticles);
|
||||
ExpressionClick = new ExpressionClick(Score, input, spawner, growAnimation, inputCallback);
|
||||
|
||||
CustomInput = new CustomInput();
|
||||
|
||||
PlayerPrefsRepository repository = new();
|
||||
Saver = new SaveGame(repository, Score);
|
||||
Loader = new LoadGame(repository, Score, inputCollections, spawner, growAnimation);
|
||||
Loader = new LoadGame(repository, Score, input, spawner, growAnimation);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ using Random = UnityEngine.Random;
|
|||
namespace View {
|
||||
public class RoseSpawner : MonoBehaviour, IRoseSpawner {
|
||||
[SerializeField] private Rect spawnerRegion;
|
||||
[SerializeField] private float initialSpawnerAvoidedRegion;
|
||||
[SerializeField] private GameObject rose;
|
||||
|
||||
public void SpawnRose() {
|
||||
|
@ -14,11 +15,35 @@ namespace View {
|
|||
spawnerRegion.position.y + Random.Range(-spawnerRegion.size.y / 2f, spawnerRegion.size.y / 2f)
|
||||
);
|
||||
|
||||
Instantiate(rose, spawnPos, Quaternion.identity);
|
||||
Spawn(spawnPos);
|
||||
}
|
||||
|
||||
public void SpawnInitialRose() {
|
||||
bool spawnOnRight = Random.Range(0, 2) == 0;
|
||||
Vector2 spawnPos;
|
||||
if (spawnOnRight) {
|
||||
spawnPos = new Vector2(
|
||||
spawnerRegion.position.x + Random.Range(initialSpawnerAvoidedRegion / 2f, spawnerRegion.size.x / 2f),
|
||||
spawnerRegion.position.y + Random.Range(-spawnerRegion.size.y / 2f, spawnerRegion.size.y / 2f)
|
||||
);
|
||||
} else {
|
||||
spawnPos = new Vector2(
|
||||
spawnerRegion.position.x + Random.Range(-spawnerRegion.size.x / 2f, -initialSpawnerAvoidedRegion / 2f),
|
||||
spawnerRegion.position.y + Random.Range(-spawnerRegion.size.y / 2f, spawnerRegion.size.y / 2f)
|
||||
);
|
||||
}
|
||||
|
||||
Spawn(spawnPos);
|
||||
}
|
||||
|
||||
private void Spawn(Vector2 pos) {
|
||||
Instantiate(rose, pos, Quaternion.identity);
|
||||
}
|
||||
|
||||
private void OnDrawGizmos() {
|
||||
Gizmos.DrawWireCube(spawnerRegion.position, spawnerRegion.size);
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawWireCube(spawnerRegion.position, new Vector2(initialSpawnerAvoidedRegion, spawnerRegion.size.y));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@ namespace View.Scene {
|
|||
[SerializeField] private EventReference gloomEvent;
|
||||
|
||||
private Score _score;
|
||||
private bool _firstUpdate;
|
||||
private bool _firstUpdate = true;
|
||||
|
||||
private void Start() {
|
||||
_score = FindObjectOfType<Dependencies>().Score;
|
||||
|
@ -41,7 +41,7 @@ namespace View.Scene {
|
|||
public void GrowStep() {
|
||||
if (animator.CurrentAnimation == "Rosa_Grow") {
|
||||
animator.PlayUntil(IsLastGrowState(_score.Value, _score.GrowPercentage) ? 1f : _score.GrowPercentage);
|
||||
if (_score.GrowPercentage < 1f)
|
||||
if (_score.GrowPercentage < 1f && !_firstUpdate)
|
||||
RuntimeManager.PlayOneShot(growEvent);
|
||||
}
|
||||
_firstUpdate = false;
|
||||
|
|
|
@ -5,7 +5,7 @@ using UnityEngine.EventSystems;
|
|||
using UnityEngine.UI;
|
||||
|
||||
namespace View.UI {
|
||||
public class UIVisibility : MonoBehaviour, IScoreView {
|
||||
public class UIVisibility : MonoBehaviour, IInputCallback {
|
||||
[SerializeField] private CanvasGroup ui;
|
||||
[SerializeField] private float fadeDuration = .5f;
|
||||
|
||||
|
@ -31,7 +31,7 @@ namespace View.UI {
|
|||
}
|
||||
}
|
||||
|
||||
public void UpdateView(int score) {
|
||||
public void OnInputReceived() {
|
||||
if (!_titleVisible) return;
|
||||
_titleVisible = false;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue