From 3256232b120e62db372ab3baeb000f6368ac2f3c Mon Sep 17 00:00:00 2001 From: BuyMyMojo Date: Thu, 2 Mar 2023 05:48:13 +1100 Subject: [PATCH] Plate holding object logic --- .erp | 2 +- Assets/Prefabs/KitchenObjects/Plate.prefab | 13 +++++++-- Assets/Scripts/Counters/ClearCounter.cs | 22 ++++++++++++++- Assets/Scripts/Counters/CuttingCounter.cs | 10 ++++++- Assets/Scripts/Counters/StoveCounter.cs | 24 +++++++++++++++- Assets/Scripts/KitchenObject.cs | 13 +++++++++ Assets/Scripts/PlateKitchenObject.cs | 33 ++++++++++++++++++++++ Assets/Scripts/PlateKitchenObject.cs.meta | 11 ++++++++ 8 files changed, 121 insertions(+), 7 deletions(-) create mode 100644 Assets/Scripts/PlateKitchenObject.cs create mode 100644 Assets/Scripts/PlateKitchenObject.cs.meta diff --git a/.erp b/.erp index 7feb4ea..06adfef 100644 --- a/.erp +++ b/.erp @@ -5,7 +5,7 @@ false false true - 1677702967 + 1677706525 23669525547325516 false \ No newline at end of file diff --git a/Assets/Prefabs/KitchenObjects/Plate.prefab b/Assets/Prefabs/KitchenObjects/Plate.prefab index 85be4bf..b850330 100644 --- a/Assets/Prefabs/KitchenObjects/Plate.prefab +++ b/Assets/Prefabs/KitchenObjects/Plate.prefab @@ -9,7 +9,7 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 2446150686974603219} - - component: {fileID: 5792615824413011753} + - component: {fileID: 8156927621140740658} m_Layer: 0 m_Name: Plate m_TagString: Untagged @@ -33,7 +33,7 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &5792615824413011753 +--- !u!114 &8156927621140740658 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -42,10 +42,17 @@ MonoBehaviour: m_GameObject: {fileID: 8716210818090012050} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 9f604455b7aeb5f4790263b920c04313, type: 3} + m_Script: {fileID: 11500000, guid: 0964246bbcef7994f80bbd41b1691bf7, type: 3} m_Name: m_EditorClassIdentifier: 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 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Counters/ClearCounter.cs b/Assets/Scripts/Counters/ClearCounter.cs index 5e79618..9d83f2e 100644 --- a/Assets/Scripts/Counters/ClearCounter.cs +++ b/Assets/Scripts/Counters/ClearCounter.cs @@ -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 { diff --git a/Assets/Scripts/Counters/CuttingCounter.cs b/Assets/Scripts/Counters/CuttingCounter.cs index b566130..5a867ec 100644 --- a/Assets/Scripts/Counters/CuttingCounter.cs +++ b/Assets/Scripts/Counters/CuttingCounter.cs @@ -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 { diff --git a/Assets/Scripts/Counters/StoveCounter.cs b/Assets/Scripts/Counters/StoveCounter.cs index ce92c67..9492b07 100644 --- a/Assets/Scripts/Counters/StoveCounter.cs +++ b/Assets/Scripts/Counters/StoveCounter.cs @@ -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, diff --git a/Assets/Scripts/KitchenObject.cs b/Assets/Scripts/KitchenObject.cs index f2cc94d..6d151f5 100644 --- a/Assets/Scripts/KitchenObject.cs +++ b/Assets/Scripts/KitchenObject.cs @@ -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); diff --git a/Assets/Scripts/PlateKitchenObject.cs b/Assets/Scripts/PlateKitchenObject.cs new file mode 100644 index 0000000..698b9d7 --- /dev/null +++ b/Assets/Scripts/PlateKitchenObject.cs @@ -0,0 +1,33 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PlateKitchenObject : KitchenObject +{ + + [SerializeField] private List validKitchenObjectSOList; + + private List kitchenObjectSOList; + + private void Awake() + { + kitchenObjectSOList = new List(); + } + + 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; + } + } +} diff --git a/Assets/Scripts/PlateKitchenObject.cs.meta b/Assets/Scripts/PlateKitchenObject.cs.meta new file mode 100644 index 0000000..d225657 --- /dev/null +++ b/Assets/Scripts/PlateKitchenObject.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0964246bbcef7994f80bbd41b1691bf7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: