Add basic tutorial

This commit is contained in:
2024-08-19 01:51:02 +02:00
parent 6171f3e1f4
commit c77eb3cdb5
5 changed files with 1489 additions and 33 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -9,6 +9,10 @@ public class HouseManager : MonoBehaviour
private float currentTtnw = 0; private float currentTtnw = 0;
private int workerPerHouse = 3; private int workerPerHouse = 3;
private GameManager gameManager; private GameManager gameManager;
//House cost: Brick Tile Glass
public int[] cost = new int[3] { 10, 5, 2 };
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
@@ -36,17 +40,17 @@ public class HouseManager : MonoBehaviour
public void BuildHouse() public void BuildHouse()
{ {
if (gameManager.GetResourceCount(Resource.BRICK) < 10 || if (gameManager.GetResourceCount(Resource.BRICK) < cost[0] ||
gameManager.GetResourceCount(Resource.TILE) < 5 || gameManager.GetResourceCount(Resource.TILE) < cost[1] ||
gameManager.GetResourceCount(Resource.GLASS) < 2) gameManager.GetResourceCount(Resource.GLASS) < cost[2])
{ {
Debug.Log("Not enough resources to build house!"); Debug.Log("Not enough resources to build house!");
return; return;
} }
gameManager.RemoveResource(Resource.BRICK, 10); gameManager.RemoveResource(Resource.BRICK, cost[0]);
gameManager.RemoveResource(Resource.TILE, 5); gameManager.RemoveResource(Resource.TILE, cost[1]);
gameManager.RemoveResource(Resource.GLASS, 2); gameManager.RemoveResource(Resource.GLASS, cost[2]);
gameManager.AddResource(Resource.HOUSE, 1); gameManager.AddResource(Resource.HOUSE, 1);
} }
} }

154
Assets/Scripts/Tutorial.cs Normal file
View File

@@ -0,0 +1,154 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class TutorialElement
{
public TutorialElement(string _title) { title = _title; }
public string title;
public GameObject worldObject;
public bool complete = false;
}
public enum Tutorials:int
{
Mining = 0,
Production = 1,
HouseBuilding = 2,
MovingIn = 3,
Assigning = 4,
WorldMap = 5,
Committing = 6,
Unlocking = 7
}
public class Tutorial : MonoBehaviour
{
[SerializeField]
private TutorialElement[] tutorialElements;
private GameManager gameManager;
private HouseManager houseManager;
[SerializeField]
private float genericTimeout = 15; //Timeout for generic tutorials with no conditions
private float genericCountdown = 0f;
[SerializeField]
private GameObject commitBtn;
// Start is called before the first frame update
void Start()
{
gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
houseManager = GameObject.Find("HouseManager").GetComponent<HouseManager>();
for (int i = 0; i < tutorialElements.Length; i++)
{
TutorialElement tutorial = tutorialElements[i];
tutorial.worldObject = GameObject.Find($"{tutorial.title}Tutorial");
if (i > 0) tutorial.worldObject.SetActive(false);
Debug.Log($"{tutorial.title}Tutorial");
}
}
// Update is called once per frame
void Update()
{
if (!tutorialElements[(int)Tutorials.Mining].complete)
{
if (gameManager.GetResourceCount(Resource.ROCK) >= 5)
{
tutorialElements[(int)Tutorials.Mining].complete = true;
tutorialElements[(int)Tutorials.Mining].worldObject.SetActive(false);
tutorialElements[(int)Tutorials.Production].worldObject.SetActive(true);
}
return;
}
if (!tutorialElements[(int)Tutorials.Production].complete)
{
if (gameManager.GetResourceCount(Resource.BRICK) > 0)
{
tutorialElements[(int)Tutorials.Production].complete = true;
tutorialElements[(int)Tutorials.Production].worldObject.SetActive(false);
}
return;
}
if (!tutorialElements[(int)Tutorials.HouseBuilding].complete)
{
if (gameManager.GetResourceCount(Resource.BRICK) >= houseManager.cost[0] &&
gameManager.GetResourceCount(Resource.TILE) >= houseManager.cost[1] &&
gameManager.GetResourceCount(Resource.GLASS) >= houseManager.cost[2])
{
tutorialElements[(int)Tutorials.HouseBuilding].worldObject.SetActive(true);
}
if (gameManager.GetResourceCount(Resource.HOUSE) > 0)
{
tutorialElements[(int)Tutorials.HouseBuilding].worldObject.SetActive(false);
tutorialElements[(int)Tutorials.HouseBuilding].complete = true;
tutorialElements[(int)Tutorials.MovingIn].worldObject.SetActive(true);
}
}
if (!tutorialElements[(int)Tutorials.MovingIn].complete)
{
if (gameManager.GetResourceCount(Resource.TOTAL_WORKER) >= 3)
{
tutorialElements[(int)Tutorials.MovingIn].complete = true;
tutorialElements[(int)Tutorials.MovingIn].worldObject.SetActive(false);
}
}
if (!tutorialElements[(int)Tutorials.Assigning].complete)
{
if (gameManager.GetResourceCount(Resource.TOTAL_WORKER) >= 1)
{
tutorialElements[(int)Tutorials.Assigning].worldObject.SetActive(true);
}
if (gameManager.GetResourceCount(Resource.WORKER) < gameManager.GetResourceCount(Resource.TOTAL_WORKER))
{
tutorialElements[(int)Tutorials.Assigning].complete = true;
tutorialElements[(int)Tutorials.Assigning].worldObject.SetActive(false);
}
return;
}
// Wait for 100 bricks to continue past this point
if (!tutorialElements[(int)Tutorials.WorldMap].complete && !(gameManager.GetResourceCount(Resource.BRICK) > 50)) { return; }
if (!tutorialElements[(int)Tutorials.WorldMap].complete)
{
tutorialElements[(int)Tutorials.WorldMap].worldObject.SetActive(true);
if (commitBtn.activeSelf == true)
{
tutorialElements[(int)Tutorials.WorldMap].complete = true;
tutorialElements[(int)Tutorials.WorldMap].worldObject.SetActive(false);
tutorialElements[(int)Tutorials.Committing].worldObject.SetActive(true);
}
return;
}
if (!tutorialElements[(int)Tutorials.Committing].complete)
{
if (gameManager.GetCommitedResources()[Resource.BRICK] > 0)
{
tutorialElements[(int)Tutorials.Committing].complete = true;
tutorialElements[(int)Tutorials.Committing].worldObject.SetActive(false);
tutorialElements[(int)Tutorials.Unlocking].worldObject.SetActive(true);
genericCountdown = genericTimeout;
}
return;
}
if (!tutorialElements[(int)Tutorials.Unlocking].complete)
{
genericCountdown -= Time.deltaTime;
if(genericCountdown <= 0)
{
tutorialElements[(int)Tutorials.Unlocking].complete = true;
tutorialElements[(int)Tutorials.Unlocking].worldObject.SetActive(false);
}
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e06026c15045dcd4f927388a799502e4

View File

@@ -41,7 +41,7 @@ Material:
- _PerspectiveFilter: 0.875 - _PerspectiveFilter: 0.875
- _ScaleRatioA: 0.9 - _ScaleRatioA: 0.9
- _ScaleRatioB: 1 - _ScaleRatioB: 1
- _ScaleRatioC: 0.42195612 - _ScaleRatioC: 0.6347656
- _ScaleX: 1 - _ScaleX: 1
- _ScaleY: 1 - _ScaleY: 1
- _ShaderFlags: 0 - _ShaderFlags: 0
@@ -53,10 +53,10 @@ Material:
- _StencilWriteMask: 255 - _StencilWriteMask: 255
- _TextureHeight: 1024 - _TextureHeight: 1024
- _TextureWidth: 1024 - _TextureWidth: 1024
- _UnderlayDilate: 0.733 - _UnderlayDilate: 1
- _UnderlayOffsetX: 0 - _UnderlayOffsetX: 0
- _UnderlayOffsetY: 0 - _UnderlayOffsetY: 0
- _UnderlaySoftness: 1 - _UnderlaySoftness: 0.152
- _VertexOffsetX: 0 - _VertexOffsetX: 0
- _VertexOffsetY: 0 - _VertexOffsetY: 0
- _WeightBold: 0.75 - _WeightBold: 0.75