Add world map view

This commit is contained in:
2024-08-18 18:11:05 +02:00
committed by Minz
parent a7fd4a2fb1
commit 762d982929
8 changed files with 847 additions and 45 deletions

View File

@@ -20,7 +20,7 @@ public class AssignableWorker : MonoBehaviour
public void AddWorker()
{
if(gameManager.GetResource(Resource.WORKER) > 0)
if(gameManager.GetResourceCount(Resource.WORKER) > 0)
{
workersAssigned++;
gameManager.RemoveResource(Resource.WORKER, 1);

View File

@@ -36,11 +36,11 @@ public class Facility : MonoBehaviour
if (!processing) //Not processing but workers assigned, start new job if material is available
{
if (gameManager.GetResource(inputResource) < materialConsumption) return; //Not enough material
if (gameManager.GetResourceCount(inputResource) < materialConsumption) return; //Not enough material
//Consumtion 5, 2
int workerCount = (assignableWorker.GetAssignedWorkers() == 0 ? 1 : assignableWorker.GetAssignedWorkers());
int maxPossibleBatch = gameManager.GetResource(inputResource) / materialConsumption;
int maxPossibleBatch = gameManager.GetResourceCount(inputResource) / materialConsumption;
currentProductionBatch = Mathf.Min(maxPossibleBatch, workerCount);
int requiredRessources = currentProductionBatch * materialConsumption;
@@ -67,7 +67,7 @@ public class Facility : MonoBehaviour
{
if (processing) return; //Already processing
if (gameManager.GetResource(inputResource) < materialConsumption) return; //Not enough material
if (gameManager.GetResourceCount(inputResource) < materialConsumption) return; //Not enough material
gameManager.RemoveResource(inputResource, materialConsumption);
currentProcess = processingTime;

View File

@@ -17,6 +17,8 @@ public enum Resource
}
public class GameManager : MonoBehaviour
{
private int currentView = 0;
private Dictionary<Resource, int> resources = new Dictionary<Resource, int>()
{
{ Resource.ROCK, 0 },
@@ -32,10 +34,16 @@ public class GameManager : MonoBehaviour
public TMPro.TMP_Text debugText;
[SerializeField]
GameObject mainViewBtn, mapViewBtn;
[SerializeField]
private Transform mainCameraPos, worldMapCameraPos;
// Start is called before the first frame update
void Start()
{
Camera.main.transform.position = mainCameraPos.position;
}
// Update is called once per frame
@@ -58,9 +66,27 @@ public class GameManager : MonoBehaviour
resources[res] -= amt;
}
public int GetResource(Resource res)
public int GetResourceCount(Resource res)
{
return resources[res];
}
public void SetView(int view)
{
switch (view)
{
case 0: //Main view
Camera.main.transform.position = mainCameraPos.position;
mainViewBtn.SetActive(true);
mapViewBtn.SetActive(false);
break;
case 1: //Map View
Camera.main.transform.position = worldMapCameraPos.position;
mainViewBtn.SetActive(false);
mapViewBtn.SetActive(true);
break;
default:
break;
}
}
}

View File

@@ -24,9 +24,9 @@ public class HouseManager : MonoBehaviour
} else
{
currentTtnw = ttnw;
if (gameManager.GetResource(Resource.TOTAL_WORKER) < gameManager.GetResource(Resource.HOUSE) * workerPerHouse)
if (gameManager.GetResourceCount(Resource.TOTAL_WORKER) < gameManager.GetResourceCount(Resource.HOUSE) * workerPerHouse)
{
int freeWorkerSlots = (gameManager.GetResource(Resource.HOUSE) * workerPerHouse) - gameManager.GetResource(Resource.TOTAL_WORKER);
int freeWorkerSlots = (gameManager.GetResourceCount(Resource.HOUSE) * workerPerHouse) - gameManager.GetResourceCount(Resource.TOTAL_WORKER);
int newWorkers = Mathf.CeilToInt((float)freeWorkerSlots / workerPerHouse);
gameManager.AddResource(Resource.WORKER, newWorkers);
gameManager.AddResource(Resource.TOTAL_WORKER, newWorkers);
@@ -36,9 +36,9 @@ public class HouseManager : MonoBehaviour
public void BuildHouse()
{
if (gameManager.GetResource(Resource.BRICK) < 10 ||
gameManager.GetResource(Resource.TILE) < 5 ||
gameManager.GetResource(Resource.GLASS) < 2)
if (gameManager.GetResourceCount(Resource.BRICK) < 10 ||
gameManager.GetResourceCount(Resource.TILE) < 5 ||
gameManager.GetResourceCount(Resource.GLASS) < 2)
{
Debug.Log("Not enough resources to build house!");
return;

View File

@@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class WorldMapUI : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3f5605aef187419469548c23842f08da