mirror of
https://github.com/DerTyp7/grow-ai-unity.git
synced 2025-10-30 21:07:09 +01:00
added freetime etc
This commit is contained in:
27
Assets/Scripts/Work/Company.cs
Normal file
27
Assets/Scripts/Work/Company.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Company : MonoBehaviour
|
||||
{
|
||||
[Header("Company")]
|
||||
[SerializeField] string companyName = "Company";
|
||||
[SerializeField] int level = 1;
|
||||
|
||||
[SerializeField] City city;
|
||||
|
||||
[SerializeField] List<Workplace> workplaces= new List<Workplace>();
|
||||
|
||||
void Awake()
|
||||
{
|
||||
city.AddCompany(this);
|
||||
}
|
||||
|
||||
public void AddWorkplace(Workplace wp)
|
||||
{
|
||||
if (!workplaces.Contains(wp))
|
||||
{
|
||||
workplaces.Add(wp);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Work/Company.cs.meta
Normal file
11
Assets/Scripts/Work/Company.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c8213916d698eaf4dbbeed4f986c72e4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
81
Assets/Scripts/Work/Workplace.cs
Normal file
81
Assets/Scripts/Work/Workplace.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Workplace : MonoBehaviour
|
||||
{
|
||||
[Header("Workplace")]
|
||||
[SerializeField] int space = 1;
|
||||
[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);
|
||||
|
||||
void Awake()
|
||||
{
|
||||
company.AddWorkplace(this);
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
TimeManager.OnHourUpdate += OnHourUpdate;
|
||||
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
if(collision.GetComponent<Person>() != null)
|
||||
{
|
||||
if (workers.Contains(collision.GetComponent<Person>()))
|
||||
{
|
||||
if (!activeWorkers.Contains(collision.GetComponent<Person>()))
|
||||
{
|
||||
activeWorkers.Add(collision.GetComponent<Person>());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerExit2D(Collider2D collision)
|
||||
{
|
||||
if (collision.GetComponent<Person>() != null)
|
||||
{
|
||||
if (activeWorkers.Contains(collision.GetComponent<Person>()))
|
||||
{
|
||||
activeWorkers.Remove(collision.GetComponent<Person>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnHourUpdate()
|
||||
{
|
||||
EconomyManager.instance.AddMoney(salary * activeWorkers.Count);
|
||||
}
|
||||
|
||||
public bool AddWorker(Person worker) // True: Worker is added - False: no enough space for worker
|
||||
{
|
||||
if (!workers.Contains(worker) && workers.Count < space)
|
||||
{
|
||||
workers.Add(worker);
|
||||
Debug.Log(worker.GetFullName() + " now works");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public void RemoveWorker(Person worker)
|
||||
{
|
||||
if (workers.Contains(worker))
|
||||
{
|
||||
workers.Remove(worker);
|
||||
Debug.Log(worker.GetFullName() + " does not work anymore");
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Work/Workplace.cs.meta
Normal file
11
Assets/Scripts/Work/Workplace.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b0d700ec6a861f499e0c4bf7220bb68
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user