Complete basic frying logic
This commit is contained in:
parent
ef0155632a
commit
9da447f835
19 changed files with 902 additions and 346 deletions
|
@ -3,14 +3,10 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CuttingCounter : BaseCounter
|
||||
public class CuttingCounter : BaseCounter, IHasProgress
|
||||
{
|
||||
|
||||
public event EventHandler<OnProgressChangeEventsArgs> OnProgressChange;
|
||||
public class OnProgressChangeEventsArgs : EventArgs
|
||||
{
|
||||
public float progressNormalized;
|
||||
}
|
||||
public event EventHandler<IHasProgress.OnProgressChangeEventsArgs> OnProgressChange;
|
||||
public event EventHandler OnCut;
|
||||
|
||||
[SerializeField] private CuttingRecipeSO[] cuttingRecipeSOArray;
|
||||
|
@ -33,7 +29,7 @@ public class CuttingCounter : BaseCounter
|
|||
|
||||
CuttingRecipeSO cuttingRecipeSO = GetCuttingRecipeSOWithInput(GetKitchenObject().GetKitchenObjectSO());
|
||||
|
||||
OnProgressChange?.Invoke(this, new OnProgressChangeEventsArgs
|
||||
OnProgressChange?.Invoke(this, new IHasProgress.OnProgressChangeEventsArgs
|
||||
{
|
||||
progressNormalized = (float)cuttingProgress / cuttingRecipeSO.cuttingProgressMax,
|
||||
});
|
||||
|
@ -71,7 +67,7 @@ public class CuttingCounter : BaseCounter
|
|||
|
||||
CuttingRecipeSO cuttingRecipeSO = GetCuttingRecipeSOWithInput(GetKitchenObject().GetKitchenObjectSO());
|
||||
|
||||
OnProgressChange?.Invoke(this, new OnProgressChangeEventsArgs
|
||||
OnProgressChange?.Invoke(this, new IHasProgress.OnProgressChangeEventsArgs
|
||||
{
|
||||
progressNormalized = (float)cuttingProgress / cuttingRecipeSO.cuttingProgressMax,
|
||||
});
|
||||
|
|
|
@ -1,33 +1,104 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using static CuttingCounter;
|
||||
|
||||
public class StoveCounter : BaseCounter
|
||||
public class StoveCounter : BaseCounter, IHasProgress
|
||||
{
|
||||
|
||||
[SerializeField] private FryingRecipeSO[] fryingRecipeSOArray;
|
||||
public event EventHandler<IHasProgress.OnProgressChangeEventsArgs> OnProgressChange;
|
||||
public event EventHandler<OnStateChangedEventArgs> OnStateChanged;
|
||||
public class OnStateChangedEventArgs : EventArgs
|
||||
{
|
||||
public State state;
|
||||
}
|
||||
|
||||
public enum State
|
||||
{
|
||||
Idle,
|
||||
Frying,
|
||||
Fried,
|
||||
Burnt
|
||||
}
|
||||
|
||||
[SerializeField] private FryingRecipeSO[] fryingRecipeSOArray;
|
||||
[SerializeField] private BurningRecipeSO[] burningRecipeSOArray;
|
||||
|
||||
private State state;
|
||||
private float fryingTimer;
|
||||
private float burningTimer;
|
||||
private FryingRecipeSO fryingRecipeSO;
|
||||
private BurningRecipeSO burningRecipeSO;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
state = State.Idle;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (HasKitchenObject())
|
||||
{
|
||||
fryingTimer += Time.deltaTime;
|
||||
FryingRecipeSO fryingRecipeSO = GetFryingRecipeSOWithInput(GetKitchenObject().GetKitchenObjectSO());
|
||||
if (fryingTimer > fryingRecipeSO.fryingTimerMax)
|
||||
switch (state)
|
||||
{
|
||||
// Fried
|
||||
fryingTimer = 0f;
|
||||
Debug.Log("Fried!");
|
||||
GetKitchenObject().DestroySelf();
|
||||
case State.Idle:
|
||||
break;
|
||||
case State.Frying:
|
||||
fryingTimer += Time.deltaTime;
|
||||
|
||||
KitchenObject.SpawnKitchenObject(fryingRecipeSO.output, this);
|
||||
OnProgressChange?.Invoke(this, new IHasProgress.OnProgressChangeEventsArgs
|
||||
{
|
||||
progressNormalized = (float)fryingTimer / fryingRecipeSO.fryingTimerMax,
|
||||
});
|
||||
|
||||
if (fryingTimer > fryingRecipeSO.fryingTimerMax)
|
||||
{
|
||||
// Fried
|
||||
GetKitchenObject().DestroySelf();
|
||||
|
||||
KitchenObject.SpawnKitchenObject(fryingRecipeSO.output, this);
|
||||
|
||||
burningTimer = 0f;
|
||||
burningRecipeSO = GetBurningRecipeSOWithInput(GetKitchenObject().GetKitchenObjectSO());
|
||||
|
||||
state = State.Fried;
|
||||
OnStateChanged?.Invoke(this, new OnStateChangedEventArgs {
|
||||
state = state,
|
||||
});
|
||||
}
|
||||
break;
|
||||
case State.Fried:
|
||||
burningTimer += Time.deltaTime;
|
||||
|
||||
OnProgressChange?.Invoke(this, new IHasProgress.OnProgressChangeEventsArgs
|
||||
{
|
||||
progressNormalized = (float)burningTimer / burningRecipeSO.burningTimerMax,
|
||||
});
|
||||
|
||||
if (burningTimer > burningRecipeSO.burningTimerMax)
|
||||
{
|
||||
// Fried
|
||||
GetKitchenObject().DestroySelf();
|
||||
|
||||
KitchenObject.SpawnKitchenObject(burningRecipeSO.output, this);
|
||||
|
||||
state = State.Burnt;
|
||||
OnStateChanged?.Invoke(this, new OnStateChangedEventArgs
|
||||
{
|
||||
state = state,
|
||||
});
|
||||
|
||||
OnProgressChange?.Invoke(this, new IHasProgress.OnProgressChangeEventsArgs
|
||||
{
|
||||
progressNormalized = 0f,
|
||||
});
|
||||
}
|
||||
break;
|
||||
case State.Burnt:
|
||||
break;
|
||||
}
|
||||
Debug.Log(fryingTimer);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,6 +114,20 @@ public class StoveCounter : BaseCounter
|
|||
{
|
||||
// player is carrying an object that can be Fried
|
||||
player.GetKitchenObject().SetKitchenObjectParent(this);
|
||||
|
||||
fryingRecipeSO = GetFryingRecipeSOWithInput(GetKitchenObject().GetKitchenObjectSO());
|
||||
|
||||
fryingTimer = 0f;
|
||||
state = State.Frying;
|
||||
OnStateChanged?.Invoke(this, new OnStateChangedEventArgs
|
||||
{
|
||||
state = state,
|
||||
});
|
||||
|
||||
OnProgressChange?.Invoke(this, new IHasProgress.OnProgressChangeEventsArgs
|
||||
{
|
||||
progressNormalized = (float)fryingTimer / fryingRecipeSO.fryingTimerMax,
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -61,6 +146,16 @@ public class StoveCounter : BaseCounter
|
|||
{
|
||||
// player has nothing
|
||||
GetKitchenObject().SetKitchenObjectParent(player);
|
||||
state = State.Idle;
|
||||
OnStateChanged?.Invoke(this, new OnStateChangedEventArgs
|
||||
{
|
||||
state = state,
|
||||
});
|
||||
|
||||
OnProgressChange?.Invoke(this, new IHasProgress.OnProgressChangeEventsArgs
|
||||
{
|
||||
progressNormalized = 0f,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,4 +193,17 @@ public class StoveCounter : BaseCounter
|
|||
|
||||
}
|
||||
|
||||
private BurningRecipeSO GetBurningRecipeSOWithInput(KitchenObjectSO inputKitchenObjectSO)
|
||||
{
|
||||
foreach (BurningRecipeSO burningRecipeSO in burningRecipeSOArray)
|
||||
{
|
||||
if (burningRecipeSO.input == inputKitchenObjectSO)
|
||||
{
|
||||
return burningRecipeSO;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
23
Assets/Scripts/Counters/StoveCounterVisual.cs
Normal file
23
Assets/Scripts/Counters/StoveCounterVisual.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class StoveCounterVisual : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private StoveCounter stoveCounter;
|
||||
|
||||
[SerializeField] private GameObject stoveOnGameObject;
|
||||
[SerializeField] private GameObject particlesGameObject;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
stoveCounter.OnStateChanged += StoveCounter_OnStateChanged;
|
||||
}
|
||||
|
||||
private void StoveCounter_OnStateChanged(object sender, StoveCounter.OnStateChangedEventArgs e)
|
||||
{
|
||||
bool showVisual = e.state == StoveCounter.State.Frying || e.state == StoveCounter.State.Fried;
|
||||
stoveOnGameObject.SetActive(showVisual);
|
||||
particlesGameObject.SetActive(showVisual);
|
||||
}
|
||||
}
|
11
Assets/Scripts/Counters/StoveCounterVisual.cs.meta
Normal file
11
Assets/Scripts/Counters/StoveCounterVisual.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e49edd74ac4ee404585246500a99a307
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
15
Assets/Scripts/IHasProgress.cs
Normal file
15
Assets/Scripts/IHasProgress.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public interface IHasProgress
|
||||
{
|
||||
|
||||
public event EventHandler<OnProgressChangeEventsArgs> OnProgressChange;
|
||||
public class OnProgressChangeEventsArgs : EventArgs
|
||||
{
|
||||
public float progressNormalized;
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/IHasProgress.cs.meta
Normal file
11
Assets/Scripts/IHasProgress.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b17a4d6abcdd24141bc2cd588d5fb26a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -6,19 +6,26 @@ using UnityEngine.UI;
|
|||
public class ProgressBarUI : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] private CuttingCounter cuttingCounter;
|
||||
[SerializeField] private GameObject hasProgressGameObject;
|
||||
[SerializeField] private Image barImage;
|
||||
|
||||
private IHasProgress hasProgress;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
cuttingCounter.OnProgressChange += CuttingCounter_OnProgressChange;
|
||||
hasProgress = hasProgressGameObject.GetComponent<IHasProgress>();
|
||||
if (hasProgress == null) {
|
||||
Debug.LogError("Game Object " + hasProgressGameObject + " does not have a componenet that implements IHasProgress!");
|
||||
}
|
||||
|
||||
hasProgress.OnProgressChange += HasProgress_OnProgressChange;
|
||||
|
||||
barImage.fillAmount = 0f;
|
||||
|
||||
Hide();
|
||||
}
|
||||
|
||||
private void CuttingCounter_OnProgressChange(object sender, CuttingCounter.OnProgressChangeEventsArgs e)
|
||||
private void HasProgress_OnProgressChange(object sender, IHasProgress.OnProgressChangeEventsArgs e)
|
||||
{
|
||||
barImage.fillAmount = e.progressNormalized;
|
||||
|
||||
|
|
13
Assets/Scripts/ScriptableObjects/BurningRecipeSO.cs
Normal file
13
Assets/Scripts/ScriptableObjects/BurningRecipeSO.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu()]
|
||||
public class BurningRecipeSO : ScriptableObject
|
||||
{
|
||||
|
||||
public KitchenObjectSO input;
|
||||
public KitchenObjectSO output;
|
||||
public float burningTimerMax;
|
||||
|
||||
}
|
11
Assets/Scripts/ScriptableObjects/BurningRecipeSO.cs.meta
Normal file
11
Assets/Scripts/ScriptableObjects/BurningRecipeSO.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f7c19db799100754091bcd4a956edc1a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in a new issue