Skip to content

Commit

Permalink
[Add] Add UI event and bind it
Browse files Browse the repository at this point in the history
  • Loading branch information
SeungHuLee committed Dec 4, 2019
1 parent a8089f0 commit 18f5bb9
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 2 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion MissileCommander/Assets/_Scripts/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ public class GameManager : MonoBehaviour

[Header("Scores")]
[SerializeField] private int scorePerMissile = 50;

[SerializeField] private int scorePerBuilding = 5000;

[Header("UI")]
[SerializeField] private UIRoot UIRoot;

private MouseGameController _mouseGameController;
private BulletLauncher _launcher;
private BuildingManager _buildingMgr;
Expand Down Expand Up @@ -70,6 +72,8 @@ private void BindEvents()
_timeMgr.onGameStart += _buildingMgr.OnGameStart;
_timeMgr.onGameStart += _launcher.OnGameStart;
_timeMgr.onGameStart += _missileMgr.OnGameStart;
_timeMgr.onGameStart += UIRoot.OnGameStart;
_scoreMgr.onScoreChanged += UIRoot.OnScoreChanged;
_missileMgr.onMissileDestroyed += _scoreMgr.OnMissileDestroyed;
}

Expand All @@ -79,6 +83,8 @@ private void UnbindEvents()
_timeMgr.onGameStart -= _buildingMgr.OnGameStart;
_timeMgr.onGameStart -= _launcher.OnGameStart;
_timeMgr.onGameStart -= _missileMgr.OnGameStart;
_timeMgr.onGameStart -= UIRoot.OnGameStart;
_scoreMgr.onScoreChanged -= UIRoot.OnScoreChanged;
_missileMgr.onMissileDestroyed -= _scoreMgr.OnMissileDestroyed;
}
}
Expand Down
1 change: 0 additions & 1 deletion MissileCommander/Assets/_Scripts/ScoreManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public void OnMissileDestroyed()
{
_score += _scorePerMissile;
onScoreChanged?.Invoke(_score);
Debug.Log($"Score : {_score}");
}

public void OnGameOver()
Expand Down
27 changes: 27 additions & 0 deletions MissileCommander/Assets/_Scripts/UIRoot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using UnityEngine;
using TMPro;

namespace MissileCommander
{
public class UIRoot : MonoBehaviour
{
[SerializeField] private TextMeshProUGUI scoreText;

private void Awake()
{
scoreText.gameObject.SetActive(false);
}

public void OnGameStart()
{
scoreText.gameObject.SetActive(true);
scoreText.text = $"Score : { 0 }";
}

public void OnScoreChanged(int score)
{
scoreText.text = $"Score : { score }";
}
}
}
3 changes: 3 additions & 0 deletions MissileCommander/Assets/_Scripts/UIRoot.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 18f5bb9

Please sign in to comment.