Added the Cutting Counter

This commit is contained in:
BuyMyMojo 2023-03-01 02:05:53 +11:00
parent 44837c6c13
commit 500f8f5f2a
41 changed files with 2383 additions and 70 deletions

View file

@ -14,6 +14,11 @@ public class BaseCounter : MonoBehaviour, IKitchenObjectParent
Debug.LogError("BaseCounter.Interact();");
}
public virtual void InteractAlternate(Player player)
{
Debug.LogError("BaseCounter.InteractAlterante();");
}
public Transform GetKitchenObjectFollowTransform()
{
return counterTopPoint;

View file

@ -10,7 +10,31 @@ public class ClearCounter : BaseCounter
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

@ -12,10 +12,10 @@ public class ContainerCounter : BaseCounter
public override void Interact(Player player)
{
if (!HasKitchenObject())
if (!player.HasKitchenObject())
{
Transform kitchenObjectTransform = Instantiate(kitchenObjectSO.prefab);
kitchenObjectTransform.GetComponent<KitchenObject>().SetKitchenObjectParent(player);
// player is not carrying anything
KitchenObject.SpawnKitchenObject(kitchenObjectSO, player);
OnPlayerGrabbedObject?.Invoke(this, EventArgs.Empty);
}

View file

@ -0,0 +1,50 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CuttingCounter : BaseCounter
{
[SerializeField] private KitchenObjectSO cutKitchenObjectSO;
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);
}
}
}
public override void InteractAlternate(Player player)
{
if (HasKitchenObject())
{
// there is a KitchenObject here
GetKitchenObject().DestroySelf();
KitchenObject.SpawnKitchenObject(cutKitchenObjectSO, this);
}
}
}

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

@ -7,6 +7,7 @@ public class GameInput : MonoBehaviour
{
public event EventHandler OnInteractAction;
public event EventHandler OnInteractAlteranteAction;
private PlayerInputActions playerInputActions;
@ -18,6 +19,12 @@ public class GameInput : MonoBehaviour
playerInputActions.Player.Enable();
playerInputActions.Player.Interact.performed += Interact_performed;
playerInputActions.Player.InteractAlternate.performed += InteractAlternate_performed;
}
private void InteractAlternate_performed(UnityEngine.InputSystem.InputAction.CallbackContext obj)
{
OnInteractAlteranteAction?.Invoke(this, EventArgs.Empty);
}
private void Interact_performed(UnityEngine.InputSystem.InputAction.CallbackContext obj)

View file

@ -39,5 +39,21 @@ public class KitchenObject : MonoBehaviour
return kitchenObjectParent;
}
public void DestroySelf()
{
kitchenObjectParent.ClearKitchenObject();
Destroy(gameObject);
}
static public KitchenObject SpawnKitchenObject(KitchenObjectSO kitchenObjectSO, IKitchenObjectParent kitchenObjectParent)
{
Transform kitchenObjectTransform = Instantiate(kitchenObjectSO.prefab);
KitchenObject kitchenObject = kitchenObjectTransform.GetComponent<KitchenObject>();
kitchenObject.SetKitchenObjectParent(kitchenObjectParent);
return kitchenObject;
}
}

View file

@ -28,6 +28,15 @@ public class Player : MonoBehaviour, IKitchenObjectParent
private void Start()
{
gameInput.OnInteractAction += GameInput_OnInteractAction;
gameInput.OnInteractAlteranteAction += GameInput_OnInteractAlteranteAction; ;
}
private void GameInput_OnInteractAlteranteAction(object sender, EventArgs e)
{
if (selectedCounter != null)
{
selectedCounter.InteractAlternate(this);
}
}
private void GameInput_OnInteractAction(object sender, System.EventArgs e)
@ -123,7 +132,7 @@ public class Player : MonoBehaviour, IKitchenObjectParent
// attempt only X move
Vector3 moveDirX = new Vector3(moveDir.x, 0, 0).normalized;
canMove = !Physics.CapsuleCast(transform.position, transform.position + Vector3.up * playerHeight, playerRadius, moveDirX, moveDistance);
canMove = moveDir.x != 0 && !Physics.CapsuleCast(transform.position, transform.position + Vector3.up * playerHeight, playerRadius, moveDirX, moveDistance);
// if able to move on X then change moveDir to X
if (canMove)
@ -134,7 +143,7 @@ public class Player : MonoBehaviour, IKitchenObjectParent
{
// cannot move on X so attempt to move on Z
Vector3 moveDirZ = new Vector3(0, 0, moveDir.z).normalized;
canMove = !Physics.CapsuleCast(transform.position, transform.position + Vector3.up * playerHeight, playerRadius, moveDirZ, moveDistance);
canMove = moveDir.z != 0 && !Physics.CapsuleCast(transform.position, transform.position + Vector3.up * playerHeight, playerRadius, moveDirZ, moveDistance);
// if able to move on Z then change moveDir to Z
if (canMove)