Added the Cutting Counter
This commit is contained in:
parent
44837c6c13
commit
500f8f5f2a
41 changed files with 2383 additions and 70 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
50
Assets/Scripts/CuttingCounter.cs
Normal file
50
Assets/Scripts/CuttingCounter.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/CuttingCounter.cs.meta
Normal file
11
Assets/Scripts/CuttingCounter.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f73ad53d0ef2b26468661109b461383e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Reference in a new issue