Plate holding object logic
This commit is contained in:
parent
7a3073ea8a
commit
3256232b12
8 changed files with 121 additions and 7 deletions
2
.erp
2
.erp
|
@ -5,7 +5,7 @@
|
||||||
<resetOnSceneChange>false</resetOnSceneChange>
|
<resetOnSceneChange>false</resetOnSceneChange>
|
||||||
<debugMode>false</debugMode>
|
<debugMode>false</debugMode>
|
||||||
<EditorClosed>true</EditorClosed>
|
<EditorClosed>true</EditorClosed>
|
||||||
<LastTimestamp>1677702967</LastTimestamp>
|
<LastTimestamp>1677706525</LastTimestamp>
|
||||||
<LastSessionID>23669525547325516</LastSessionID>
|
<LastSessionID>23669525547325516</LastSessionID>
|
||||||
<Errored>false</Errored>
|
<Errored>false</Errored>
|
||||||
</ERPSettings>
|
</ERPSettings>
|
|
@ -9,7 +9,7 @@ GameObject:
|
||||||
serializedVersion: 6
|
serializedVersion: 6
|
||||||
m_Component:
|
m_Component:
|
||||||
- component: {fileID: 2446150686974603219}
|
- component: {fileID: 2446150686974603219}
|
||||||
- component: {fileID: 5792615824413011753}
|
- component: {fileID: 8156927621140740658}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: Plate
|
m_Name: Plate
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
|
@ -33,7 +33,7 @@ Transform:
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_RootOrder: 0
|
m_RootOrder: 0
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!114 &5792615824413011753
|
--- !u!114 &8156927621140740658
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
@ -42,10 +42,17 @@ MonoBehaviour:
|
||||||
m_GameObject: {fileID: 8716210818090012050}
|
m_GameObject: {fileID: 8716210818090012050}
|
||||||
m_Enabled: 1
|
m_Enabled: 1
|
||||||
m_EditorHideFlags: 0
|
m_EditorHideFlags: 0
|
||||||
m_Script: {fileID: 11500000, guid: 9f604455b7aeb5f4790263b920c04313, type: 3}
|
m_Script: {fileID: 11500000, guid: 0964246bbcef7994f80bbd41b1691bf7, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
kitchenObjectSO: {fileID: 11400000, guid: 33409fb567685fc42bb48805717e6c1a, type: 2}
|
kitchenObjectSO: {fileID: 11400000, guid: 33409fb567685fc42bb48805717e6c1a, type: 2}
|
||||||
|
validKitchenObjectSOList:
|
||||||
|
- {fileID: 11400000, guid: 6a1e97e49ac17314c872f2ef05c80dcf, type: 2}
|
||||||
|
- {fileID: 11400000, guid: 109b320dd13683c4abc574781815cbbd, type: 2}
|
||||||
|
- {fileID: 11400000, guid: adbde85b933684c4992834e8bb9d893b, type: 2}
|
||||||
|
- {fileID: 11400000, guid: cf77ec56d13b4c7478384a548ab18277, type: 2}
|
||||||
|
- {fileID: 11400000, guid: f00d7c6ba063ee6448dd26fac2bf4ce4, type: 2}
|
||||||
|
- {fileID: 11400000, guid: 42754f770e37e78488140348e6a9f9c3, type: 2}
|
||||||
--- !u!1001 &9216177299345934497
|
--- !u!1001 &9216177299345934497
|
||||||
PrefabInstance:
|
PrefabInstance:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
|
@ -27,7 +27,27 @@ public class ClearCounter : BaseCounter
|
||||||
// KitchenObject is here
|
// KitchenObject is here
|
||||||
if (player.HasKitchenObject())
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -45,7 +45,15 @@ public class CuttingCounter : BaseCounter, IHasProgress
|
||||||
// KitchenObject is here
|
// KitchenObject is here
|
||||||
if (player.HasKitchenObject())
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -140,13 +140,35 @@ public class StoveCounter : BaseCounter, IHasProgress
|
||||||
// KitchenObject is here
|
// KitchenObject is here
|
||||||
if (player.HasKitchenObject())
|
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
|
else
|
||||||
{
|
{
|
||||||
// player has nothing
|
// player has nothing
|
||||||
GetKitchenObject().SetKitchenObjectParent(player);
|
GetKitchenObject().SetKitchenObjectParent(player);
|
||||||
|
|
||||||
state = State.Idle;
|
state = State.Idle;
|
||||||
|
|
||||||
OnStateChanged?.Invoke(this, new OnStateChangedEventArgs
|
OnStateChanged?.Invoke(this, new OnStateChangedEventArgs
|
||||||
{
|
{
|
||||||
state = state,
|
state = state,
|
||||||
|
|
|
@ -46,6 +46,19 @@ public class KitchenObject : MonoBehaviour
|
||||||
Destroy(gameObject);
|
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)
|
static public KitchenObject SpawnKitchenObject(KitchenObjectSO kitchenObjectSO, IKitchenObjectParent kitchenObjectParent)
|
||||||
{
|
{
|
||||||
Transform kitchenObjectTransform = Instantiate(kitchenObjectSO.prefab);
|
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