mirror of
https://github.com/DerTyp7/grow-ai-unity.git
synced 2025-10-30 21:07:09 +01:00
a
This commit is contained in:
@@ -31,14 +31,151 @@ public class Person : MonoBehaviour
|
||||
|
||||
System.DateTime goToWorkDateTime;
|
||||
|
||||
|
||||
void Awake()
|
||||
|
||||
// DEBUG
|
||||
private void Update()
|
||||
{
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.G))
|
||||
{
|
||||
movement.SetTarget(Camera.main.ScreenToWorldPoint(Input.mousePosition));
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
Register();
|
||||
movement = gameObject.GetComponent<PersonMovement>();
|
||||
indicators = gameObject.GetComponent<PersonIndicators>();
|
||||
transform.position = house.transform.position;
|
||||
|
||||
TimeManager.OnDayUpdate += DestroyInactive;
|
||||
TimeManager.OnDayUpdate += CheckWorkplace;
|
||||
TimeManager.OnDayUpdate += OnDayUpdate;
|
||||
TimeManager.OnMinuteUpdate += OnMinuteUpdate;
|
||||
|
||||
SetBehaivorDateTimes();
|
||||
}
|
||||
|
||||
void Register()
|
||||
{
|
||||
// Register To City
|
||||
city = GameObject.Find("GameManager").GetComponent<City>();
|
||||
city.AddPerson(this);
|
||||
// Register To House
|
||||
house = city.GetAvaiableHouse();
|
||||
if(house != null)
|
||||
house.AddPerson(this);
|
||||
// Register To Workplace
|
||||
workplace = city.GetAvaiableWorkplace();
|
||||
if(workplace != null)
|
||||
workplace.AddWorker(this);
|
||||
}
|
||||
|
||||
void CheckWorkplace()
|
||||
{
|
||||
if (workplace == null)
|
||||
{
|
||||
workplace = city.GetAvaiableWorkplace();
|
||||
workplace.AddWorker(this);
|
||||
}
|
||||
}
|
||||
void DestroyInactive()
|
||||
{
|
||||
// Destroy a person if they do not find a house anymore
|
||||
if (house == null)
|
||||
{
|
||||
if(city != null)
|
||||
city.RemovePerson(this);
|
||||
if (workplace != null)
|
||||
workplace.RemoveWorker(this);
|
||||
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OnDayUpdate()
|
||||
{
|
||||
SetBehaivorDateTimes();
|
||||
}
|
||||
void OnMinuteUpdate()
|
||||
{
|
||||
|
||||
// Work -> FreeTime -> Sleep
|
||||
|
||||
if (TimeManager.instance.GetDateTime() > goToWorkDateTime.AddHours(12)) // Sleep
|
||||
{
|
||||
Sleep();
|
||||
}
|
||||
else if (TimeManager.instance.GetDateTime() > goToWorkDateTime.AddHours(8)) // FreeTime
|
||||
{
|
||||
FreeTime();
|
||||
}
|
||||
else if (TimeManager.instance.GetDateTime() > goToWorkDateTime) // Work
|
||||
{
|
||||
Work();
|
||||
}
|
||||
}
|
||||
void FreeTime()
|
||||
{
|
||||
if (status == PersonStatus.STORE)
|
||||
{
|
||||
if (indicators.GetSupplied() == 1.0f)
|
||||
{
|
||||
status = PersonStatus.FREETIME;
|
||||
}
|
||||
}
|
||||
else if (status != PersonStatus.PARK)
|
||||
{
|
||||
status = PersonStatus.FREETIME;
|
||||
}
|
||||
|
||||
if (indicators.GetSupplied() < 0.3f || status == PersonStatus.STORE)
|
||||
{
|
||||
status = PersonStatus.STORE;
|
||||
Debug.Log(city.GetStores().Count - 1);
|
||||
//movement.SetTarget(city.GetStores()[Random.Range(0, city.GetStores().Count - 1)].transform.position);
|
||||
}
|
||||
else if (status != PersonStatus.PARK)
|
||||
{
|
||||
status = PersonStatus.PARK;// Check if any Object exsits
|
||||
//movement.SetTarget(city.GetFreeTimeObjects()[Random.Range(0, city.GetFreeTimeObjects().Count)].transform.position);
|
||||
}
|
||||
}
|
||||
|
||||
void Work()
|
||||
{
|
||||
status = PersonStatus.WORK;
|
||||
movement.SetTarget(workplace.transform.position);
|
||||
}
|
||||
|
||||
void Sleep()
|
||||
{
|
||||
status = PersonStatus.SLEEP;
|
||||
Debug.Log(house.transform.position);
|
||||
movement.SetTarget(house.transform.position);
|
||||
}
|
||||
|
||||
void SetBehaivorDateTimes()
|
||||
{
|
||||
System.DateTime currentDateTime = TimeManager.instance.GetDateTime();
|
||||
goToWorkDateTime = new System.DateTime(currentDateTime.Year,
|
||||
currentDateTime.Month,
|
||||
currentDateTime.Day,
|
||||
Random.Range(4, 9),
|
||||
Random.Range(0, 59),
|
||||
currentDateTime.Second);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
void Start ()
|
||||
{
|
||||
|
||||
city.AddCitizen(this);
|
||||
house.AddPerson(this);
|
||||
workplace.AddWorker(this);
|
||||
@@ -66,7 +203,7 @@ public class Person : MonoBehaviour
|
||||
Debug.Log("House added to " + GetFullName());
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
movement = GetComponent<PersonMovement>();
|
||||
@@ -79,6 +216,8 @@ public class Person : MonoBehaviour
|
||||
Sleep();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void OnDayUpdate()
|
||||
{
|
||||
SetBehaivorDateTimes();
|
||||
@@ -150,5 +289,5 @@ public class Person : MonoBehaviour
|
||||
Random.Range(0, 59),
|
||||
currentDateTime.Second);
|
||||
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ public class PersonMovement : MonoBehaviour
|
||||
{
|
||||
private int currentPathIndex;
|
||||
[SerializeField] private List<Vector3> pathVectorList = new List<Vector3>();
|
||||
private const float speed = 40f;
|
||||
private const float speed = 5f;
|
||||
Rigidbody2D rigidbody;
|
||||
|
||||
private void Awake()
|
||||
|
||||
Reference in New Issue
Block a user