Started working on Builder job and building buildings

This commit is contained in:
2026-06-12 12:00:15 +01:00
parent 529b25daf5
commit bd3bb4bc6f
12 changed files with 7599 additions and 6861 deletions

View File

@@ -51,7 +51,7 @@ Material:
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Texture: {fileID: 2800000, guid: 51148e3057e25994c80f5321340afc7b, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 951751753bd491349a68c9f347c3782c
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

3406
Assets/Prefabs/NPC.prefab Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: f97a75ea176e29648bedd5f9d0da92c4
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -6,11 +6,12 @@ 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()
{
@@ -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;
}
}

View 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;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 4bd36540681fbaa4eb9be52d4b051ace

View File

@@ -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;
}

View File

@@ -8,8 +8,9 @@ public class Resource : MonoBehaviour
Stone,
Metal,
Money,
Citizens,
Food
Population,
Food,
Building
}
public ResourceType resourceType;
public enum ResourceState

View File

@@ -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