using Assets.Scripts.Enums;
|
using System.Collections;
|
using System.Collections.Generic;
|
using TMPro;
|
using UnityEngine;
|
using UnityEngine.InputSystem;
|
using UnityEngine.SceneManagement;
|
using UnityEngine.Tilemaps;
|
|
public class GameManager : SettingsManager
|
{
|
public GameObject damageTextPrefab;
|
public GameObject healthTextPrefab;
|
public Canvas playerUI;
|
public Canvas pauseMenuUI;
|
public Tilemap tilemap;
|
|
private void Awake()
|
{
|
SoundManager.instance.ChangeMusic(SoundName.MusicHappy);
|
}
|
|
private void OnEnable()
|
{
|
// add listen events
|
CharacterEvents.characterDamaged += (CharacterTookDamange);
|
CharacterEvents.characterHealed += (CharacterHealed);
|
CharacterEvents.characterDrill += (CharacterDrill);
|
|
}
|
|
private void OnDisable()
|
{
|
// remove listen events
|
CharacterEvents.characterDamaged -= (CharacterTookDamange);
|
CharacterEvents.characterHealed -= (CharacterHealed);
|
CharacterEvents.characterDrill -= (CharacterDrill);
|
}
|
|
public void CharacterTookDamange(GameObject character, int damageReceived)
|
{
|
// Create damage text at character
|
Vector3 spawnPosition = Camera.main.WorldToScreenPoint(character.transform.position);
|
|
TMP_Text tmpText = Instantiate(damageTextPrefab, spawnPosition, Quaternion.identity, pauseMenuUI.transform).GetComponent<TMP_Text>();
|
|
tmpText.text = damageReceived.ToString();
|
|
}
|
public void CharacterHealed(GameObject character, int healthRestored)
|
{
|
// Create heal text at character
|
Vector3 spawnPosition = Camera.main.WorldToScreenPoint(character.transform.position);
|
|
TMP_Text tmpText = Instantiate(healthTextPrefab, spawnPosition, Quaternion.identity, pauseMenuUI.transform).GetComponent<TMP_Text>();
|
|
tmpText.text = healthRestored.ToString();
|
|
}
|
public void CharacterDrill(ContactPoint2D contact, DrillDirection drillDirection)
|
{
|
Vector3Int cellCoord = tilemap.transform.GetComponentInParent<GridLayout>().WorldToCell(contact.point);
|
switch(drillDirection)
|
{
|
case DrillDirection.Left:
|
cellCoord.x = cellCoord.x - 1;
|
break;
|
case DrillDirection.Right:
|
cellCoord.x = cellCoord.x + 1;
|
break;
|
case DrillDirection.Down:
|
cellCoord.y = cellCoord.y - 1;
|
break;
|
}
|
tilemap.SetTile(cellCoord, null);
|
}
|
public void GameLoaded()
|
{
|
pauseMenuUI.GetComponent<Animator>().SetTrigger("GameLoaded");
|
}
|
}
|