Finish monument unlocking mvp
This commit is contained in:
@@ -19,6 +19,13 @@ public class GameManager : MonoBehaviour
|
||||
{
|
||||
private int currentView = 0;
|
||||
|
||||
private Dictionary<Resource, int> committedResources = new Dictionary<Resource, int>()
|
||||
{
|
||||
{ Resource.BRICK, 0 },
|
||||
{ Resource.TILE, 0 },
|
||||
{ Resource.GLASS, 0 }
|
||||
};
|
||||
|
||||
private Dictionary<Resource, int> resources = new Dictionary<Resource, int>()
|
||||
{
|
||||
{ Resource.ROCK, 0 },
|
||||
@@ -29,21 +36,34 @@ public class GameManager : MonoBehaviour
|
||||
{ Resource.GLASS, 0 },
|
||||
{ Resource.HOUSE, 1 },
|
||||
{ Resource.WORKER, 0 },
|
||||
{ Resource.TOTAL_WORKER, 0 },
|
||||
{ Resource.TOTAL_WORKER, 0 }
|
||||
};
|
||||
|
||||
|
||||
public TMPro.TMP_Text debugText;
|
||||
|
||||
[SerializeField]
|
||||
GameObject mainViewBtn, mapViewBtn;
|
||||
|
||||
private TMPro.TMP_Text resourceLabel;
|
||||
[SerializeField]
|
||||
private Transform mainCameraPos, worldMapCameraPos;
|
||||
private TMPro.TMP_Text housingLabel;
|
||||
|
||||
[Header("Map View")]
|
||||
[SerializeField]
|
||||
private Transform worldMapCameraPos;
|
||||
[SerializeField]
|
||||
private GameObject mainViewBtn, commitBtn;
|
||||
|
||||
[Header("Main View")]
|
||||
[SerializeField]
|
||||
private Transform mainCameraPos;
|
||||
[SerializeField]
|
||||
private GameObject mapViewBtn;
|
||||
|
||||
private MonumentManager monumentManager;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
Camera.main.transform.position = mainCameraPos.position;
|
||||
monumentManager = GameObject.Find("MonumentManager").GetComponent<MonumentManager>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@@ -54,6 +74,24 @@ public class GameManager : MonoBehaviour
|
||||
{
|
||||
debugText.text += item.ToString();
|
||||
}
|
||||
|
||||
housingLabel.text = $"{resources[Resource.HOUSE]} Houses\n" +
|
||||
$"{resources[Resource.WORKER]} Workers";
|
||||
resourceLabel.text = $"Resources:\n" +
|
||||
$"Storage: Bricks {resources[Resource.BRICK]} | Tiles {resources[Resource.TILE]} | Glass {resources[Resource.GLASS]}\n" +
|
||||
$"Comitted: Bricks {committedResources[Resource.BRICK]} | Tiles {committedResources[Resource.TILE]} | Glass {committedResources[Resource.GLASS]}";
|
||||
}
|
||||
|
||||
public void CommitResources()
|
||||
{
|
||||
List<Resource> resourceList = new List<Resource>(committedResources.Keys);
|
||||
foreach (Resource resource in resourceList)
|
||||
{
|
||||
committedResources[resource] += GetResourceCount(resource);
|
||||
RemoveResource(resource, GetResourceCount(resource));
|
||||
}
|
||||
|
||||
monumentManager.UpdateUnlocks();
|
||||
}
|
||||
|
||||
public void AddResource(Resource res, int amt)
|
||||
@@ -71,19 +109,26 @@ public class GameManager : MonoBehaviour
|
||||
return resources[res];
|
||||
}
|
||||
|
||||
public Dictionary<Resource, int> GetCommitedResources()
|
||||
{
|
||||
return new Dictionary<Resource, int>(committedResources);
|
||||
}
|
||||
|
||||
public void SetView(int view)
|
||||
{
|
||||
switch (view)
|
||||
{
|
||||
case 0: //Main view
|
||||
Camera.main.transform.position = mainCameraPos.position;
|
||||
mainViewBtn.SetActive(true);
|
||||
mapViewBtn.SetActive(false);
|
||||
mainViewBtn.SetActive(false);
|
||||
mapViewBtn.SetActive(true);
|
||||
commitBtn.SetActive(false);
|
||||
break;
|
||||
case 1: //Map View
|
||||
Camera.main.transform.position = worldMapCameraPos.position;
|
||||
mainViewBtn.SetActive(false);
|
||||
mapViewBtn.SetActive(true);
|
||||
mainViewBtn.SetActive(true);
|
||||
mapViewBtn.SetActive(false);
|
||||
commitBtn.SetActive(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -8,6 +8,8 @@ public class Mine : MonoBehaviour
|
||||
public Resource resource;
|
||||
private GameManager gameManager;
|
||||
|
||||
[SerializeField]
|
||||
private TMPro.TextMeshPro storedLabel;
|
||||
private float nextTick = 0f;
|
||||
private AssignableWorker assignableWorker;
|
||||
// Start is called before the first frame update
|
||||
@@ -31,6 +33,7 @@ public class Mine : MonoBehaviour
|
||||
|
||||
private void Tick()
|
||||
{
|
||||
storedLabel.text = gameManager.GetResourceCount(resource).ToString();
|
||||
gameManager.AddResource(resource, 1 * assignableWorker.GetAssignedWorkers());
|
||||
}
|
||||
|
||||
|
||||
74
Assets/Scripts/MonumentManager.cs
Normal file
74
Assets/Scripts/MonumentManager.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
[System.Serializable]
|
||||
public class Monument
|
||||
{
|
||||
public string name;
|
||||
public string description;
|
||||
public int brickCost, tileCost, glassCost;
|
||||
public GameObject worldObject;
|
||||
}
|
||||
public class MonumentManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private List<Monument> monuments = new List<Monument>();
|
||||
[SerializeField]
|
||||
private TMP_Text nextUnlockLabel;
|
||||
|
||||
private GameManager gameManager;
|
||||
private Dictionary<Resource, int> resourcesForNextUnlock;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
|
||||
UpdateUnlocks();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void UpdateUnlocks()
|
||||
{
|
||||
Dictionary<Resource, int> availableResources = gameManager.GetCommitedResources();
|
||||
int lastMonumentIndex = -1;
|
||||
|
||||
for (int i = 0; i < monuments.Count; i++)
|
||||
{
|
||||
Monument monument = monuments[i];
|
||||
if(availableResources[Resource.BRICK] >= monument.brickCost &&
|
||||
availableResources[Resource.TILE] >= monument.tileCost &&
|
||||
availableResources[Resource.GLASS] >= monument.glassCost )
|
||||
{
|
||||
availableResources[Resource.BRICK] -= monument.brickCost;
|
||||
availableResources[Resource.TILE] -= monument.tileCost;
|
||||
availableResources[Resource.GLASS] -= monument.glassCost;
|
||||
monument.worldObject.GetComponent<Renderer>().material.color = Color.green;
|
||||
lastMonumentIndex = i;
|
||||
} else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
resourcesForNextUnlock = availableResources;
|
||||
|
||||
if (lastMonumentIndex == monuments.Count-1)
|
||||
{
|
||||
Debug.Log("All unlocked");
|
||||
return;
|
||||
}
|
||||
|
||||
nextUnlockLabel.text = $"Next Unlock: {monuments[lastMonumentIndex + 1].name} (" +
|
||||
$" B: {resourcesForNextUnlock[Resource.BRICK]}/{monuments[lastMonumentIndex + 1].brickCost}" +
|
||||
$" T: {resourcesForNextUnlock[Resource.TILE]}/{monuments[lastMonumentIndex + 1].tileCost}" +
|
||||
$" G: {resourcesForNextUnlock[Resource.GLASS]}/{monuments[lastMonumentIndex + 1].glassCost})";
|
||||
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/MonumentManager.cs.meta
Normal file
2
Assets/Scripts/MonumentManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec105ee063189bf4fba3ec1ba36e36ea
|
||||
Reference in New Issue
Block a user