Add cutting progress bar

This commit is contained in:
BuyMyMojo 2023-03-01 04:08:49 +11:00
parent 8194937cd8
commit 4ad7bf281c
8 changed files with 761 additions and 42 deletions

View file

@ -1,3 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
@ -5,6 +6,13 @@ using UnityEngine;
public class CuttingCounter : BaseCounter
{
public event EventHandler<OnProgressChangeEventsArgs> OnProgressChange;
public class OnProgressChangeEventsArgs : EventArgs
{
public float progressNormalized;
}
public event EventHandler OnCut;
[SerializeField] private CuttingRecipeSO[] cuttingRecipeSOArray;
private int cuttingProgress;
@ -22,6 +30,13 @@ public class CuttingCounter : BaseCounter
// player is carrying an object that can be chopped
player.GetKitchenObject().SetKitchenObjectParent(this);
cuttingProgress = 0;
CuttingRecipeSO cuttingRecipeSO = GetCuttingRecipeSOWithInput(GetKitchenObject().GetKitchenObjectSO());
OnProgressChange?.Invoke(this, new OnProgressChangeEventsArgs
{
progressNormalized = (float)cuttingProgress / cuttingRecipeSO.cuttingProgressMax,
});
}
}
else
@ -51,9 +66,16 @@ public class CuttingCounter : BaseCounter
// there is a KitchenObject AND it is able to be cut
cuttingProgress++;
OnCut?.Invoke(this, EventArgs.Empty);
CuttingRecipeSO cuttingRecipeSO = GetCuttingRecipeSOWithInput(GetKitchenObject().GetKitchenObjectSO());
OnProgressChange?.Invoke(this, new OnProgressChangeEventsArgs
{
progressNormalized = (float)cuttingProgress / cuttingRecipeSO.cuttingProgressMax,
});
if (cuttingProgress >= cuttingRecipeSO.cuttingProgressMax)
{
KitchenObjectSO outputKitchenSO = GetOutputForInput(GetKitchenObject().GetKitchenObjectSO());

View file

@ -0,0 +1,28 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CuttingCounterVisual : MonoBehaviour
{
private const string CUT = "Cut";
[SerializeField] private CuttingCounter cuttingCounter;
private Animator animator;
private void Awake()
{
animator = GetComponent<Animator>();
}
private void Start()
{
cuttingCounter.OnCut += ContainerCounter_OnCut;
}
private void ContainerCounter_OnCut(object sender, System.EventArgs e)
{
animator.SetTrigger(CUT);
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d6d78e6b76d8cc545bcc3eee6bd24c0d
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;
using UnityEngine.UI;
public class ProgressBarUI : MonoBehaviour
{
[SerializeField] private CuttingCounter cuttingCounter;
[SerializeField] private Image barImage;
private void Start()
{
cuttingCounter.OnProgressChange += CuttingCounter_OnProgressChange;
barImage.fillAmount = 0f;
Hide();
}
private void CuttingCounter_OnProgressChange(object sender, CuttingCounter.OnProgressChangeEventsArgs e)
{
barImage.fillAmount = e.progressNormalized;
if (e.progressNormalized == 0f || e.progressNormalized == 1f) {
Hide();
} else
{
Show();
}
}
private void Show()
{
gameObject.SetActive(true);
}
private void Hide()
{
gameObject.SetActive(false);
}
}

View file

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