Selling Functionality, Picking up items, Basic computer
This commit is contained in:
64
Assets/HUDManager.cs
Normal file
64
Assets/HUDManager.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class HUDManager : MonoBehaviour {
|
||||
public static HUDManager Instance { get; private set; }
|
||||
|
||||
[SerializeField] private GameObject _computerHUD;
|
||||
[SerializeField] private GameObject _sellScreenHUD;
|
||||
|
||||
private GameObject _currentHUD;
|
||||
|
||||
public bool isUiOpen => _currentHUD != null;
|
||||
|
||||
private void Awake() {
|
||||
if (Instance != null) {
|
||||
Debug.LogError("What? 2 HudManagers crazy!!!");
|
||||
}
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
private void Update() {
|
||||
CheckClose();
|
||||
}
|
||||
|
||||
public void ShowComputerHUD() {
|
||||
ShowHUD(_computerHUD);
|
||||
}
|
||||
|
||||
public void ShowSellScreenHUD(SellCounter counter) {
|
||||
ShowHUD(_sellScreenHUD);
|
||||
}
|
||||
|
||||
private void ShowHUD(GameObject hud) {
|
||||
if (_currentHUD != null) {
|
||||
_currentHUD.SetActive(false);
|
||||
}
|
||||
_currentHUD = hud;
|
||||
_currentHUD.SetActive(true);
|
||||
}
|
||||
|
||||
public void HideCurrentHUD() {
|
||||
if (_currentHUD != null) {
|
||||
_currentHUD.SetActive(false);
|
||||
_currentHUD = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void CheckClose() {
|
||||
if (!Input.GetKeyDown(KeyCode.Escape)) return;
|
||||
if (_currentHUD == null) return;
|
||||
|
||||
HideCurrentHUD();
|
||||
}
|
||||
|
||||
|
||||
//TODO: ask if its matters if i just return a SellSCreenBehaviour, or route them through the HUDManager
|
||||
public void SellItem(SellCounter counter, Object sellingObject) {
|
||||
Debug.Log(_sellScreenHUD.GetComponent<SellScreenController>());
|
||||
this.ShowSellScreenHUD(counter);
|
||||
_sellScreenHUD.GetComponent<SellScreenController>().SetItem(counter, sellingObject);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user