feat: hide title when game starts

This commit is contained in:
Gerard Gascón 2024-04-15 17:50:28 +02:00
parent 0bed7bbea4
commit 58ec07b1a0
5 changed files with 42 additions and 8 deletions

View file

@ -346,6 +346,8 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
ui: {fileID: 311490074} ui: {fileID: 311490074}
fadeDuration: 0.5 fadeDuration: 0.5
titleImage: {fileID: 1127832730}
titleFadeDuration: 1
--- !u!1 &379057220 --- !u!1 &379057220
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -380,7 +382,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1} m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 0, y: -7.7999} m_AnchoredPosition: {x: 0, y: -7.7999268}
m_SizeDelta: {x: 122.1659, y: 51.509} m_SizeDelta: {x: 122.1659, y: 51.509}
m_Pivot: {x: 0, y: 1} m_Pivot: {x: 0, y: 1}
--- !u!114 &379057222 --- !u!114 &379057222

View file

@ -13,7 +13,10 @@ namespace View {
Model = new Model(0); Model = new Model(0);
IExpressionInput input = FindObjectOfType<ExpressionInput>(); IExpressionInput input = FindObjectOfType<ExpressionInput>();
ExpressionClick = new ExpressionClick(Model, input); IExpressionInput visibility = FindObjectOfType<UIVisibility>();
IExpressionInput inputCollections = new ExpressionInputCollection(new[] { input, visibility });
ExpressionClick = new ExpressionClick(Model, inputCollections);
CustomInput = new CustomInput(); CustomInput = new CustomInput();
} }

View file

@ -0,0 +1,16 @@
using Presenter;
namespace View {
public class ExpressionInputCollection : IExpressionInput {
private readonly IExpressionInput[] _inputs;
public ExpressionInputCollection(IExpressionInput[] inputs) {
_inputs = inputs;
}
public void UpdateView(int score) {
foreach (IExpressionInput input in _inputs)
input.UpdateView(score);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ae095e86bb524331a6f001ba71000218
timeCreated: 1713195784

View file

@ -1,31 +1,41 @@
using System;
using DG.Tweening; using DG.Tweening;
using Presenter;
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using UnityEngine.UI; using UnityEngine.UI;
namespace View { namespace View {
public class UIVisibility : MonoBehaviour { public class UIVisibility : MonoBehaviour, IExpressionInput {
[SerializeField] private CanvasGroup ui; [SerializeField] private CanvasGroup ui;
[SerializeField] private float fadeDuration = .5f; [SerializeField] private float fadeDuration = .5f;
[Space]
[SerializeField] private Image titleImage;
[SerializeField] private float titleFadeDuration = 1f;
private bool _wasVisible = true; private bool _wasVisible = true;
private bool _titleVisible = true;
private Tween _fadeTween; private Tween _fadeTween;
private void Update() { private void Update() {
bool isPointerOver = EventSystem.current.IsPointerOverGameObject(); bool isPointerOver = EventSystem.current.IsPointerOverGameObject();
if (_wasVisible && !isPointerOver) { if (_wasVisible && !isPointerOver) {
_fadeTween?.Kill(); _fadeTween?.Kill();
_fadeTween = ui.DOFade(0, fadeDuration).SetDelay(5f); _fadeTween = ui.DOFade(0, fadeDuration).SetDelay(5f);
_wasVisible = false; _wasVisible = false;
return; } else if (!_wasVisible && isPointerOver) {
}
if (!_wasVisible && isPointerOver) {
_fadeTween?.Kill(); _fadeTween?.Kill();
_fadeTween = ui.DOFade(1, fadeDuration); _fadeTween = ui.DOFade(1, fadeDuration);
_wasVisible = true; _wasVisible = true;
return;
} }
} }
public void UpdateView(int score) {
if (!_titleVisible) return;
_titleVisible = false;
titleImage.DOFade(0, titleFadeDuration);
}
} }
} }