1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using UnityEngine;
- using System.Collections;
- using TMPro;
- public class ScoreManager : MonoBehaviour
- {
- public TextMeshProUGUI label;
- public Transform bonusesAnchor;
- public PoolObject hitPointsBonusPrefab;
- Pool _hitPointsBonusPool;
- void Awake()
- {
- _hitPointsBonusPool = Pool.Get(hitPointsBonusPrefab);
- NotificationCenter.AddListener(OnGameStart, NotificationType.GameStart);
- NotificationCenter.AddListener(OnAddToScore, NotificationType.AddToScore);
- NotificationCenter.AddListener(OnUpdateScoreLabel, NotificationType.UpdateScoreLabel);
- }
- void OnDestroy()
- {
- NotificationCenter.RemoveListener(OnGameStart, NotificationType.GameStart);
- NotificationCenter.RemoveListener(OnAddToScore, NotificationType.AddToScore);
- NotificationCenter.RemoveListener(OnUpdateScoreLabel, NotificationType.UpdateScoreLabel);
- }
- void OnGameStart(Notification note)
- {
- UpdateLabel();
- }
- void OnAddToScore(Notification note)
- {
- ScoreChangeData data = (ScoreChangeData)note.data;
- if (data.source == ScoreChangeData.Source.Enemy)
- {
- if(_hitPointsBonusPool!= null)
- {
- TextAnnouncement hitPointsBonus = _hitPointsBonusPool.Spawn().GetComponent<TextAnnouncement>();
- Transform hitPointsBonusTransform = hitPointsBonus.transform;
- hitPointsBonusTransform.parent = bonusesAnchor;
- hitPointsBonus.SetText(data.scoreDelta.ToString());
- hitPointsBonusTransform.position = data.position;
- //reset the local z
- Vector3 localPos = hitPointsBonusTransform.localPosition;
- localPos.z = 0;
- hitPointsBonusTransform.localPosition = localPos;
- }
-
- }
- }
- void OnUpdateScoreLabel(Notification note)
- {
- UpdateLabel();
- }
- void UpdateLabel()
- {
- label.text = GameDataManager.Instance.Score.ToString("00000");
- }
- }
|