Started working on Builder job and building buildings
This commit is contained in:
@@ -6,15 +6,16 @@ public class GameManager : MonoBehaviour
|
||||
{
|
||||
public Dictionary<Resource.ResourceType, int> statistics = new Dictionary<Resource.ResourceType, int>();
|
||||
public static GameManager Instance;
|
||||
[SerializeField]private float money, citizens, wood, stone, metal;
|
||||
[SerializeField]private float money, population, wood, stone, metal;
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
CalculatePopulation();
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
@@ -37,8 +38,8 @@ public class GameManager : MonoBehaviour
|
||||
case Resource.ResourceType.Money:
|
||||
money += amountToAdd;
|
||||
break;
|
||||
case Resource.ResourceType.Citizens:
|
||||
citizens += amountToAdd;
|
||||
case Resource.ResourceType.Population:
|
||||
population += amountToAdd;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -54,9 +55,19 @@ public class GameManager : MonoBehaviour
|
||||
return metal;
|
||||
case Resource.ResourceType.Money:
|
||||
return money;
|
||||
case Resource.ResourceType.Citizens:
|
||||
return citizens;
|
||||
case Resource.ResourceType.Population:
|
||||
return population;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public void CalculatePopulation()
|
||||
{
|
||||
NPC[] npcs = FindObjectsByType<NPC>(FindObjectsSortMode.None);
|
||||
AddResource(Resource.ResourceType.Population, npcs.Length);
|
||||
}
|
||||
public Building[] CountBuildings()
|
||||
{
|
||||
Building[] buildings = FindObjectsByType<Building>(FindObjectsSortMode.None);
|
||||
return buildings;
|
||||
}
|
||||
}
|
||||
|
||||
33
Assets/Scripts/JobManager.cs
Normal file
33
Assets/Scripts/JobManager.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class JobManager : MonoBehaviour
|
||||
{
|
||||
private Building targetBuilding;
|
||||
private Resource targetResource;
|
||||
private NPC targetNPC;
|
||||
public void RequestJob(NPC.Job jobType)
|
||||
{
|
||||
switch (jobType)
|
||||
{
|
||||
case NPC.Job.Builder:
|
||||
targetBuilding = GetUnfinishedBuildings();
|
||||
if(targetBuilding != null)
|
||||
{
|
||||
targetBuilding.StartBuilding();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
private Building GetUnfinishedBuildings()
|
||||
{
|
||||
Building[] buildings = GameManager.Instance.CountBuildings();
|
||||
foreach (Building building in buildings)
|
||||
{
|
||||
if(building.GetBuildingState() == Building.BuildingState.Unbuilt)
|
||||
{
|
||||
return building;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/JobManager.cs.meta
Normal file
2
Assets/Scripts/JobManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4bd36540681fbaa4eb9be52d4b051ace
|
||||
@@ -20,7 +20,7 @@ public class NPC : MonoBehaviour
|
||||
[SerializeField] Animator animationController;
|
||||
[SerializeField] float movementSpeed, interactionRadius;
|
||||
[SerializeField] Image jobImg;
|
||||
[SerializeField] Sprite miner, forester, citizen, farmer, merchant, soldier;
|
||||
[SerializeField] Sprite miner, forester, citizen, farmer, merchant, soldier, builder;
|
||||
|
||||
private Resource currentTargetResource;
|
||||
private Building currentTargetBuilding; // Cache the TownHall so we don't search for it every frame
|
||||
@@ -209,6 +209,8 @@ public class NPC : MonoBehaviour
|
||||
switch (job)
|
||||
{
|
||||
case Job.Builder:
|
||||
//resourceToWorkWith = Resource.ResourceType.Building;
|
||||
jobImg.sprite = builder;
|
||||
break;
|
||||
case Job.Soldier:
|
||||
break;
|
||||
@@ -227,7 +229,7 @@ public class NPC : MonoBehaviour
|
||||
jobImg.sprite = miner;
|
||||
break;
|
||||
case Job.Citizen:
|
||||
resourceToWorkWith = Resource.ResourceType.Citizens;
|
||||
resourceToWorkWith = Resource.ResourceType.Population;
|
||||
jobImg.sprite = citizen;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -8,8 +8,9 @@ public class Resource : MonoBehaviour
|
||||
Stone,
|
||||
Metal,
|
||||
Money,
|
||||
Citizens,
|
||||
Food
|
||||
Population,
|
||||
Food,
|
||||
Building
|
||||
}
|
||||
public ResourceType resourceType;
|
||||
public enum ResourceState
|
||||
|
||||
@@ -21,7 +21,7 @@ public class UIController : MonoBehaviour
|
||||
{
|
||||
wood.text = GameManager.Instance.GetResource(Resource.ResourceType.Wood).ToString();
|
||||
stone.text = GameManager.Instance.GetResource(Resource.ResourceType.Stone).ToString();
|
||||
population.text = GameManager.Instance.GetResource(Resource.ResourceType.Citizens).ToString();
|
||||
population.text = GameManager.Instance.GetResource(Resource.ResourceType.Population).ToString();
|
||||
}
|
||||
|
||||
// Called by left-clicking a JobButton
|
||||
|
||||
Reference in New Issue
Block a user