Add trash counter

This commit is contained in:
BuyMyMojo 2023-03-01 04:32:48 +11:00
parent cc314c40e5
commit 217df07f89
24 changed files with 793 additions and 10 deletions

View file

@ -0,0 +1,47 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BaseCounter : MonoBehaviour, IKitchenObjectParent
{
[SerializeField] private Transform counterTopPoint;
private KitchenObject kitchenObject;
public virtual void Interact(Player player)
{
Debug.LogError("BaseCounter.Interact();");
}
public virtual void InteractAlternate(Player player)
{
Debug.LogError("BaseCounter.InteractAlterante();");
}
public Transform GetKitchenObjectFollowTransform()
{
return counterTopPoint;
}
public void SetKitchenObject(KitchenObject kitchenObject)
{
this.kitchenObject = kitchenObject;
}
public KitchenObject GetKitchenObject()
{
return kitchenObject;
}
public void ClearKitchenObject()
{
kitchenObject = null;
}
public bool HasKitchenObject()
{
return kitchenObject != null;
}
}

View file

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

View file

@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ClearCounter : BaseCounter
{
[SerializeField] private KitchenObjectSO kitchenObjectSO;
public override void Interact(Player player)
{
if (!HasKitchenObject())
{
// no KitchenObject here
if (player.HasKitchenObject())
{
// player has object
player.GetKitchenObject().SetKitchenObjectParent(this);
} else
{
// player has nothing, do nothing
}
}
else
{
// KitchenObject is here
if (player.HasKitchenObject())
{
// player has object, do nothing
}
else
{
// player has nothing
GetKitchenObject().SetKitchenObjectParent(player);
}
}
}
}

View file

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

View file

@ -0,0 +1,24 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ContainerCounter : BaseCounter
{
public event EventHandler OnPlayerGrabbedObject;
[SerializeField] private KitchenObjectSO kitchenObjectSO;
public override void Interact(Player player)
{
if (!player.HasKitchenObject())
{
// player is not carrying anything
KitchenObject.SpawnKitchenObject(kitchenObjectSO, player);
OnPlayerGrabbedObject?.Invoke(this, EventArgs.Empty);
}
}
}

View file

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

View file

@ -0,0 +1,28 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ContainerCounterVisual : MonoBehaviour
{
private const string OPEN_CLOSE = "OpenClose";
[SerializeField] private ContainerCounter containerCounter;
private Animator animator;
private void Awake()
{
animator = GetComponent<Animator>();
}
private void Start()
{
containerCounter.OnPlayerGrabbedObject += ContainerCounter_OnPlayerGrabbedObject;
}
private void ContainerCounter_OnPlayerGrabbedObject(object sender, System.EventArgs e)
{
animator.SetTrigger(OPEN_CLOSE);
}
}

View file

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

View file

@ -0,0 +1,120 @@
using System;
using System.Collections;
using System.Collections.Generic;
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;
public override void Interact(Player player)
{
if (!HasKitchenObject())
{
// no KitchenObject here
if (player.HasKitchenObject())
{
// player has object
if (HasRecipeWithInput(player.GetKitchenObject().GetKitchenObjectSO()))
{
// 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
{
// player has nothing, do nothing
}
}
else
{
// KitchenObject is here
if (player.HasKitchenObject())
{
// player has object, do nothing
}
else
{
// player has nothing
GetKitchenObject().SetKitchenObjectParent(player);
}
}
}
public override void InteractAlternate(Player player)
{
if (HasKitchenObject() && HasRecipeWithInput(GetKitchenObject().GetKitchenObjectSO()))
{
// 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());
GetKitchenObject().DestroySelf();
KitchenObject.SpawnKitchenObject(outputKitchenSO, this);
}
}
}
private bool HasRecipeWithInput(KitchenObjectSO inputKitchenObjectSO)
{
CuttingRecipeSO cuttingRecipeSO = GetCuttingRecipeSOWithInput(inputKitchenObjectSO);
return cuttingRecipeSO != null;
}
private KitchenObjectSO GetOutputForInput(KitchenObjectSO inputKitchenObjectSO)
{
CuttingRecipeSO cuttingRecipeSO = GetCuttingRecipeSOWithInput(inputKitchenObjectSO);
if (cuttingRecipeSO != null)
{
return cuttingRecipeSO.output;
} else
{
return null;
}
}
private CuttingRecipeSO GetCuttingRecipeSOWithInput(KitchenObjectSO inputKitchenObjectSO)
{
foreach (CuttingRecipeSO cuttingRecipeSO in cuttingRecipeSOArray)
{
if (cuttingRecipeSO.input == inputKitchenObjectSO)
{
return cuttingRecipeSO;
}
}
return null;
}
}

View file

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

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,14 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TrashCounter : BaseCounter
{
public override void Interact(Player player)
{
if (player.HasKitchenObject())
{
player.GetKitchenObject().DestroySelf();
}
}
}

View file

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