56 lines
1.4 KiB
C#
56 lines
1.4 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BrewMonster.Scripts.UI
|
|
{
|
|
public class WorldMapUI : MonoBehaviour
|
|
{
|
|
[SerializeField] private Button _buttonClose;
|
|
[SerializeField] private RectTransform _hostPlayerIcon;
|
|
|
|
[Header("Map Setup")]
|
|
[SerializeField] private int nRow; // get these numbers from configs/instance.txt
|
|
[SerializeField] private int nCol;
|
|
|
|
|
|
private CECHostPlayer _hostPlayer;
|
|
private float _mapWidth;
|
|
private float _mapHeight;
|
|
|
|
private void Awake()
|
|
{
|
|
_buttonClose.onClick.AddListener(OnButtonCloseClicked);
|
|
|
|
_mapWidth = nCol * 1024;
|
|
_mapHeight = nRow * 1024;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
UpdateWorldMap();
|
|
}
|
|
|
|
void UpdateWorldMap()
|
|
{
|
|
_hostPlayer = GetHostPlayer();
|
|
if (_hostPlayer == null) return;
|
|
|
|
Vector3 vecPosHost = _hostPlayer.transform.position;
|
|
_hostPlayerIcon.anchoredPosition = new Vector2(vecPosHost.x / nCol, vecPosHost.z / nRow);
|
|
}
|
|
|
|
private CECHostPlayer GetHostPlayer()
|
|
{
|
|
return CECGameRun.Instance.GetHostPlayer();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Close the World Map when user click the close button
|
|
/// </summary>
|
|
private void OnButtonCloseClicked()
|
|
{
|
|
gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|