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_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0} m_Offset: {x: 0, y: 0}
- _MainTex: - _MainTex:
m_Texture: {fileID: 0} m_Texture: {fileID: 2800000, guid: 51148e3057e25994c80f5321340afc7b, type: 3}
m_Scale: {x: 1, y: 1} m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0} m_Offset: {x: 0, y: 0}
- _MetallicGlossMap: - _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,15 +6,16 @@ public class GameManager : MonoBehaviour
{ {
public Dictionary<Resource.ResourceType, int> statistics = new Dictionary<Resource.ResourceType, int>(); public Dictionary<Resource.ResourceType, int> statistics = new Dictionary<Resource.ResourceType, int>();
public static GameManager Instance; 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 // Start is called once before the first execution of Update after the MonoBehaviour is created
void Awake() void Awake()
{ {
Instance = this; Instance = this;
CalculatePopulation();
} }
void Start() void Start()
{ {
} }
// Update is called once per frame // Update is called once per frame
void Update() void Update()
@@ -37,8 +38,8 @@ public class GameManager : MonoBehaviour
case Resource.ResourceType.Money: case Resource.ResourceType.Money:
money += amountToAdd; money += amountToAdd;
break; break;
case Resource.ResourceType.Citizens: case Resource.ResourceType.Population:
citizens += amountToAdd; population += amountToAdd;
break; break;
} }
} }
@@ -54,9 +55,19 @@ public class GameManager : MonoBehaviour
return metal; return metal;
case Resource.ResourceType.Money: case Resource.ResourceType.Money:
return money; return money;
case Resource.ResourceType.Citizens: case Resource.ResourceType.Population:
return citizens; return population;
} }
return 0; 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] Animator animationController;
[SerializeField] float movementSpeed, interactionRadius; [SerializeField] float movementSpeed, interactionRadius;
[SerializeField] Image jobImg; [SerializeField] Image jobImg;
[SerializeField] Sprite miner, forester, citizen, farmer, merchant, soldier; [SerializeField] Sprite miner, forester, citizen, farmer, merchant, soldier, builder;
private Resource currentTargetResource; private Resource currentTargetResource;
private Building currentTargetBuilding; // Cache the TownHall so we don't search for it every frame 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) switch (job)
{ {
case Job.Builder: case Job.Builder:
//resourceToWorkWith = Resource.ResourceType.Building;
jobImg.sprite = builder;
break; break;
case Job.Soldier: case Job.Soldier:
break; break;
@@ -227,7 +229,7 @@ public class NPC : MonoBehaviour
jobImg.sprite = miner; jobImg.sprite = miner;
break; break;
case Job.Citizen: case Job.Citizen:
resourceToWorkWith = Resource.ResourceType.Citizens; resourceToWorkWith = Resource.ResourceType.Population;
jobImg.sprite = citizen; jobImg.sprite = citizen;
break; break;
} }

View File

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

View File

@@ -21,7 +21,7 @@ public class UIController : MonoBehaviour
{ {
wood.text = GameManager.Instance.GetResource(Resource.ResourceType.Wood).ToString(); wood.text = GameManager.Instance.GetResource(Resource.ResourceType.Wood).ToString();
stone.text = GameManager.Instance.GetResource(Resource.ResourceType.Stone).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 // Called by left-clicking a JobButton