Plate holding object logic
This commit is contained in:
parent
7a3073ea8a
commit
3256232b12
8 changed files with 121 additions and 7 deletions
|
@ -27,7 +27,27 @@ public class ClearCounter : BaseCounter
|
|||
// KitchenObject is here
|
||||
if (player.HasKitchenObject())
|
||||
{
|
||||
// player has object, do nothing
|
||||
// player has object
|
||||
if (player.GetKitchenObject().TryGetPlate(out PlateKitchenObject plateKitchenObject))
|
||||
{
|
||||
// Player is holding a plate
|
||||
if (plateKitchenObject.TryAddIngreedient(GetKitchenObject().GetKitchenObjectSO()))
|
||||
{
|
||||
GetKitchenObject().DestroySelf();
|
||||
}
|
||||
} else
|
||||
{
|
||||
// player not carrying plate but other object
|
||||
if (GetKitchenObject().TryGetPlate(out plateKitchenObject))
|
||||
{
|
||||
// Counter holds plate
|
||||
if (plateKitchenObject.TryAddIngreedient(player.GetKitchenObject().GetKitchenObjectSO()))
|
||||
{
|
||||
player.GetKitchenObject().DestroySelf();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -45,7 +45,15 @@ public class CuttingCounter : BaseCounter, IHasProgress
|
|||
// KitchenObject is here
|
||||
if (player.HasKitchenObject())
|
||||
{
|
||||
// player has object, do nothing
|
||||
// player has object
|
||||
if (player.GetKitchenObject().TryGetPlate(out PlateKitchenObject plateKitchenObject))
|
||||
{
|
||||
// Player is holding a plate
|
||||
if (plateKitchenObject.TryAddIngreedient(GetKitchenObject().GetKitchenObjectSO()))
|
||||
{
|
||||
GetKitchenObject().DestroySelf();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -140,13 +140,35 @@ public class StoveCounter : BaseCounter, IHasProgress
|
|||
// KitchenObject is here
|
||||
if (player.HasKitchenObject())
|
||||
{
|
||||
// player has object, do nothing
|
||||
// player has object
|
||||
if (player.GetKitchenObject().TryGetPlate(out PlateKitchenObject plateKitchenObject))
|
||||
{
|
||||
// Player is holding a plate
|
||||
if (plateKitchenObject.TryAddIngreedient(GetKitchenObject().GetKitchenObjectSO()))
|
||||
{
|
||||
GetKitchenObject().DestroySelf();
|
||||
}
|
||||
}
|
||||
|
||||
state = State.Idle;
|
||||
|
||||
OnStateChanged?.Invoke(this, new OnStateChangedEventArgs
|
||||
{
|
||||
state = state,
|
||||
});
|
||||
|
||||
OnProgressChange?.Invoke(this, new IHasProgress.OnProgressChangeEventsArgs
|
||||
{
|
||||
progressNormalized = 0f,
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
// player has nothing
|
||||
GetKitchenObject().SetKitchenObjectParent(player);
|
||||
|
||||
state = State.Idle;
|
||||
|
||||
OnStateChanged?.Invoke(this, new OnStateChangedEventArgs
|
||||
{
|
||||
state = state,
|
||||
|
|
|
@ -46,6 +46,19 @@ public class KitchenObject : MonoBehaviour
|
|||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
public bool TryGetPlate(out PlateKitchenObject plateKitchenObject)
|
||||
{
|
||||
if (this is PlateKitchenObject)
|
||||
{
|
||||
plateKitchenObject = this as PlateKitchenObject;
|
||||
return true;
|
||||
} else
|
||||
{
|
||||
plateKitchenObject = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static public KitchenObject SpawnKitchenObject(KitchenObjectSO kitchenObjectSO, IKitchenObjectParent kitchenObjectParent)
|
||||
{
|
||||
Transform kitchenObjectTransform = Instantiate(kitchenObjectSO.prefab);
|
||||
|
|
33
Assets/Scripts/PlateKitchenObject.cs
Normal file
33
Assets/Scripts/PlateKitchenObject.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlateKitchenObject : KitchenObject
|
||||
{
|
||||
|
||||
[SerializeField] private List<KitchenObjectSO> validKitchenObjectSOList;
|
||||
|
||||
private List<KitchenObjectSO> kitchenObjectSOList;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
kitchenObjectSOList = new List<KitchenObjectSO>();
|
||||
}
|
||||
|
||||
public bool TryAddIngreedient(KitchenObjectSO kitchenObjectSO)
|
||||
{
|
||||
if (!validKitchenObjectSOList.Contains(kitchenObjectSO))
|
||||
{
|
||||
// Not a valid ingreedient
|
||||
return false;
|
||||
}
|
||||
if (kitchenObjectSOList.Contains(kitchenObjectSO))
|
||||
{
|
||||
return false;
|
||||
} else
|
||||
{
|
||||
kitchenObjectSOList.Add(kitchenObjectSO);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/PlateKitchenObject.cs.meta
Normal file
11
Assets/Scripts/PlateKitchenObject.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0964246bbcef7994f80bbd41b1691bf7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in a new issue