Add plate spawning counter

This commit is contained in:
BuyMyMojo 2023-03-02 05:18:58 +11:00
parent 9da447f835
commit 7a3073ea8a
13 changed files with 891 additions and 92 deletions

View file

@ -0,0 +1,51 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlatesCounter : BaseCounter
{
public event EventHandler OnPlateSpawned;
public event EventHandler OnPlateRemoved;
[SerializeField] private float spawnPlateTimerMax = 4f;
[SerializeField] private KitchenObjectSO plateKitchenObjectSO;
private float spawnPlateTimer;
private int platesSpawnedAmount;
private int platesSpawnedMax = 4;
private void Update()
{
spawnPlateTimer += Time.deltaTime;
if (spawnPlateTimer > spawnPlateTimerMax)
{
spawnPlateTimer = 0f;
if (platesSpawnedAmount < platesSpawnedMax)
{
platesSpawnedAmount++;
OnPlateSpawned?.Invoke(this, EventArgs.Empty);
}
}
}
public override void Interact(Player player)
{
if (!player.HasKitchenObject())
{
// player is empty handed
if (platesSpawnedAmount > 0)
{
// at least 1 plate on counter
platesSpawnedAmount--;
KitchenObject.SpawnKitchenObject(plateKitchenObjectSO, player);
OnPlateRemoved?.Invoke(this, EventArgs.Empty);
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ec5fbe1ea872403428a4455a09ff09d0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,43 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlatesCounterVisual : MonoBehaviour
{
[SerializeField] private PlatesCounter platesCounter;
[SerializeField] private Transform counterTopPoint;
[SerializeField] private Transform plateVisualPrefab;
private List<GameObject> plateVisualGameObjectList;
private void Awake()
{
plateVisualGameObjectList = new List<GameObject>();
}
private void Start()
{
platesCounter.OnPlateSpawned += PlatesCounter_OnPlateSpawned;
platesCounter.OnPlateRemoved += PlatesCounter_OnPlateRemoved;
}
private void PlatesCounter_OnPlateRemoved(object sender, System.EventArgs e)
{
GameObject plateGameObject = plateVisualGameObjectList[plateVisualGameObjectList.Count - 1];
plateVisualGameObjectList.Remove(plateGameObject);
Destroy(plateGameObject);
}
private void PlatesCounter_OnPlateSpawned(object sender, System.EventArgs e)
{
Transform plateVisualTransform = Instantiate(plateVisualPrefab, counterTopPoint);
float plateOffsetY = .1f;
plateVisualTransform.localPosition = new Vector3(0, plateOffsetY * plateVisualGameObjectList.Count, 0);
plateVisualGameObjectList.Add(plateVisualTransform.gameObject);
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c2f5bbd3a2c5ae941856ceb005e76371
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: