51 lines
1.1 KiB
C#
51 lines
1.1 KiB
C#
using UnityEngine;
|
|
|
|
public class BuildingManager : MonoBehaviour
|
|
{
|
|
public bool IsOpen { get; set; }
|
|
public bool IsInside { get; set; }
|
|
|
|
private string _address;
|
|
public IndoorSO Indoor;
|
|
|
|
public void BuildingInteract(IndoorSO indoor)
|
|
{
|
|
|
|
if (!IsInside)
|
|
{
|
|
EnterBuilding(indoor);
|
|
}
|
|
else
|
|
{
|
|
ExitBuilding(indoor);
|
|
}
|
|
}
|
|
|
|
private void EnterBuilding(IndoorSO indoor)
|
|
{
|
|
IsOpen = CheckIsOpen(indoor?.OpenHoursFrom, indoor?.OpenHoursTo);
|
|
if (IsOpen)
|
|
{
|
|
Indoor = indoor;
|
|
IsInside = true;
|
|
GameManager.Instance.Scene.Change("indoor");
|
|
}
|
|
}
|
|
|
|
public void ExitBuilding(IndoorSO indoor)
|
|
{
|
|
IsInside = false;
|
|
GameManager.Instance.Scene.Change("city",indoor.BuidingName);
|
|
}
|
|
|
|
private bool CheckIsOpen(int? from, int? to)
|
|
{
|
|
if (from.HasValue && to.HasValue)
|
|
{
|
|
return GameManager.Instance.Time.CurrentTime.Hours >= from
|
|
&& GameManager.Instance.Time.CurrentTime.Hours <= to;
|
|
}
|
|
return true;
|
|
}
|
|
}
|