added freetime etc

This commit is contained in:
j.mei7
2022-03-06 16:04:18 +01:00
parent a95431b836
commit 386a0db5ff
39 changed files with 7480 additions and 199 deletions

View File

@@ -0,0 +1,124 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum PersonStatus
{
WORK,
SLEEP,
FREETIME,
PARK,
STORE,
}
public class Person : MonoBehaviour
{
[Header("Person")]
[SerializeField] string firstName = "";
[SerializeField] string lastName = "";
[SerializeField] City city;
[SerializeField] House house;
[SerializeField] Workplace workplace;
public PersonStatus status;
PersonMovement movement;
PersonIndicators indicators;
public string GetFirstName() => firstName;
public string GetLastName() => lastName;
public string GetFullName() => firstName + " " + lastName;
System.DateTime goToWorkDateTime;
void Awake()
{
city.AddCitizen(this);
house.AddPerson(this);
workplace.AddWorker(this);
}
void Start()
{
movement = GetComponent<PersonMovement>();
indicators = GetComponent<PersonIndicators>();
TimeManager.OnMinuteUpdate += OnMinuteUpdate;
TimeManager.OnDayUpdate += OnDayUpdate;
SetBehaivorDateTimes();
FreeTime();
}
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
{
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);
}
else if(status == PersonStatus.FREETIME)
{
status = PersonStatus.PARK;
movement.SetTarget(city.GetFreeTimeObjects()[Random.Range(0, city.GetFreeTimeObjects().Count)].transform);
}
}
void Work()
{
status = PersonStatus.WORK;
movement.SetTarget(workplace.transform);
}
void Sleep()
{
status = PersonStatus.SLEEP;
movement.SetTarget(house.transform);
}
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);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8647d87746af05e41a97676f479a8da8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,71 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PersonIndicators : MonoBehaviour
{
[Header("Person Indicators")]
[SerializeField] float happiness = 1f;
[SerializeField] float supplied = 1f;
[Header("Decay Modifiers")]
[SerializeField] float suppliedDecayModifier = 0.4f;
[SerializeField] float happinessDecayModifier = 0.1f;
public float GetHappiness() => happiness;
public float GetSupplied() => supplied;
void Start()
{
TimeManager.OnDayUpdate += OnDayUpdate;
}
void OnDayUpdate()
{
DecreaseSupplied(Random.Range(0.0f, suppliedDecayModifier)); // Random Percentage probability
if (supplied <= 0.2f)
{
DecreaseHappiness(happinessDecayModifier);
}
}
public void IncreaseHappiness(float value)
{
if(happiness + value <= 1f)
{
happiness += value;
}
else
{
happiness = 1f;
}
}
public void DecreaseHappiness(float value)
{
if(happiness - value >= 0f)
{
happiness -= value;
}
}
public void IncreaseSupplied(float value)
{
if (supplied + value <= 1f)
{
supplied += value;
}
else
{
supplied = 1f;
}
}
public void DecreaseSupplied(float value)
{
if (supplied - value >= 0f)
{
supplied -= value;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d96c0dcd94a2a7848973dd95d150cc51
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,22 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class PersonMovement : MonoBehaviour
{
NavMeshAgent agent;
private void Awake()
{
agent = GetComponent<NavMeshAgent>();
agent.updateRotation = false;
agent.updateUpAxis = false;
//agent.avoidancePriority = Random.Range(1, 100);
}
public void SetTarget(Transform target)
{
agent.SetDestination(target.position);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 92efa8c0fa40ca1429bb33b689b384ea
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: