This commit is contained in:
j.mei7
2022-03-06 21:15:54 +01:00
parent 386a0db5ff
commit e884e44c54
41 changed files with 25259 additions and 22520 deletions

35
Assets/Scripts/Area.cs Normal file
View File

@@ -0,0 +1,35 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Area : MonoBehaviour
{
[SerializeField] bool accessable = false;
[SerializeField] GameObject tile;
List<Tile> tiles = new List<Tile>();
int height = 16;
int width = 16;
void Start()
{
GetComponent<SpriteRenderer>().color = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);
//GenerateGrid();
}
void GenerateGrid()
{
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
GameObject currentTile= Instantiate(tile);
currentTile.transform.position = new Vector3(x - width/2, y-height/2, 1);
//currentTile.transform.SetParent(transform);
tiles.Add(currentTile.GetComponent<Tile>());
}
}
}
}

View File

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

View File

@@ -12,11 +12,14 @@ public class City : MonoBehaviour
[SerializeField] List<Person> citizens = new List<Person>();
[SerializeField] List<House> houses = new List<House>();
[SerializeField] List<Company> companies = new List<Company>();
[SerializeField] List<Workplace> workplaces = new List<Workplace>();
[SerializeField] List<Store> stores = new List<Store>();
[SerializeField] List<FreeTimeObject> freeTimeObjects = new List<FreeTimeObject>();
public List<Store> GetStores() => stores;
public List<FreeTimeObject> GetFreeTimeObjects() => freeTimeObjects;
public List<House> GetHouses() => houses;
public List<Workplace> GetWorkplaces() => workplaces;
public void AddCitizen(Person citizen)
{
@@ -106,4 +109,21 @@ public class City : MonoBehaviour
Debug.Log("FreeTimeObject demolished in " + cityName);
}
}
public void AddWorkplace(Workplace workplace)
{
if (!workplaces.Contains(workplace))
{
workplaces.Add(workplace);
Debug.Log("workplaces built in " + cityName);
}
}
public void RemoveWorkplace(Workplace workplace)
{
if (workplaces.Contains(workplace))
{
workplaces.Remove(workplace);
Debug.Log("workplaces demolished in " + cityName);
}
}
}

View File

@@ -6,7 +6,7 @@ public class House : MonoBehaviour
{
[Header("House")]
[SerializeField]
int space = 1;
int space = 4;
[SerializeField]
List<Person> persons = new List<Person>();
@@ -14,18 +14,22 @@ public class House : MonoBehaviour
[SerializeField]
City city;
public int GetAvaiableSpace() => space - persons.Count;
void Awake()
{
city.AddHouse(this);
}
public void AddPerson(Person person)
public bool AddPerson(Person person)
{
if (!persons.Contains(person) && persons.Count < space)
{
persons.Add(person);
Debug.Log(person.GetFullName() + " now lives in house");
return true;
}
return false;
}
public void RemovePerson(Person person)

View File

@@ -0,0 +1,39 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AreaManager : MonoBehaviour
{
[SerializeField] int areaSize = 16;
[SerializeField] int width = 8;
[SerializeField] int height = 8;
[SerializeField] GameObject area;
[SerializeField] List<Area> areas;
private void Start()
{
GenerateGrid();
}
void GenerateGrid()
{
for(int x = 0; x < width; x++)
{
for(int y = 0; y < height; y++)
{
GameObject currentArea = Instantiate(area);
currentArea.transform.position = new Vector3(16*x, 16*y, 1);
areas.Add(currentArea.GetComponent<Area>());
}
}
}
private void OnDrawGizmos()
{
Gizmos.color = Color.blue;
Gizmos.DrawWireCube(Vector3Int.zero, new Vector3Int(areaSize, areaSize, 1));
}
}

View File

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

View File

@@ -34,13 +34,38 @@ public class Person : MonoBehaviour
void Awake()
{
city.AddCitizen(this);
house.AddPerson(this);
workplace.AddWorker(this);
city.AddCitizen(this);
}
void Start()
{
foreach (Workplace w in city.GetWorkplaces())
{
if(workplace == null)
{
if (w.AddWorker(this))
{
workplace = w;
Debug.Log("Workplace added to " + GetFullName());
}
}
}
foreach (House h in city.GetHouses())
{
if(house == null)
{
if (h.AddPerson(this))
{
house = h;
Debug.Log("House added to " + GetFullName());
}
}
}
movement = GetComponent<PersonMovement>();
indicators = GetComponent<PersonIndicators>();
@@ -48,7 +73,7 @@ public class Person : MonoBehaviour
TimeManager.OnDayUpdate += OnDayUpdate;
SetBehaivorDateTimes();
FreeTime();
Sleep();
}
void OnDayUpdate()
{
@@ -80,7 +105,7 @@ public class Person : MonoBehaviour
status = PersonStatus.FREETIME;
}
}
else
else if (status != PersonStatus.PARK)
{
status = PersonStatus.FREETIME;
}
@@ -91,9 +116,9 @@ public class Person : MonoBehaviour
Debug.Log(city.GetStores().Count - 1);
movement.SetTarget(city.GetStores()[Random.Range(0, city.GetStores().Count-1)].transform);
}
else if(status == PersonStatus.FREETIME)
else if(status != PersonStatus.PARK)
{
status = PersonStatus.PARK;
status = PersonStatus.PARK;// Check if any Object exsits
movement.SetTarget(city.GetFreeTimeObjects()[Random.Range(0, city.GetFreeTimeObjects().Count)].transform);
}
}

12
Assets/Scripts/Tile.cs Normal file
View File

@@ -0,0 +1,12 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tile : MonoBehaviour
{
void Start()
{
GetComponent<SpriteRenderer>().color = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);
}
}

View File

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

View File

@@ -12,6 +12,8 @@ public class Company : MonoBehaviour
[SerializeField] List<Workplace> workplaces= new List<Workplace>();
public City GetCity() => city;
void Awake()
{
city.AddCompany(this);

View File

@@ -5,21 +5,22 @@ using UnityEngine;
public class Workplace : MonoBehaviour
{
[Header("Workplace")]
[SerializeField] int space = 1;
[SerializeField] int space = 4;
[SerializeField] float salary = 4.5f;
[SerializeField] List<Person> workers = new List<Person>();
[SerializeField] List<Person> activeWorkers = new List<Person>(); // Workers which are currently present and working
[SerializeField] Company company;
public void SetCompany(Company _company) => company = _company;
public void AddActiveWorker(Person worker) => activeWorkers.Add(worker);
public void RemoveActiveWorker(Person worker) => activeWorkers.Remove(worker);
public int GetAvaiableSpace() => space - workers.Count;
void Awake()
{
company.AddWorkplace(this);
company.GetCity().AddWorkplace(this);
}
void Start()