diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..ddb6ff8 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "visualstudiotoolsforunity.vstuc" + ] +} diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..da60e25 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,10 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Attach to Unity", + "type": "vstuc", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9df82cf --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,60 @@ +{ + "files.exclude": { + "**/.DS_Store": true, + "**/.git": true, + "**/.vs": true, + "**/.gitmodules": true, + "**/.vsconfig": true, + "**/*.booproj": true, + "**/*.pidb": true, + "**/*.suo": true, + "**/*.user": true, + "**/*.userprefs": true, + "**/*.unityproj": true, + "**/*.dll": true, + "**/*.exe": true, + "**/*.pdf": true, + "**/*.mid": true, + "**/*.midi": true, + "**/*.wav": true, + "**/*.gif": true, + "**/*.ico": true, + "**/*.jpg": true, + "**/*.jpeg": true, + "**/*.png": true, + "**/*.psd": true, + "**/*.tga": true, + "**/*.tif": true, + "**/*.tiff": true, + "**/*.3ds": true, + "**/*.3DS": true, + "**/*.fbx": true, + "**/*.FBX": true, + "**/*.lxo": true, + "**/*.LXO": true, + "**/*.ma": true, + "**/*.MA": true, + "**/*.obj": true, + "**/*.OBJ": true, + "**/*.asset": true, + "**/*.cubemap": true, + "**/*.flare": true, + "**/*.mat": true, + "**/*.meta": true, + "**/*.prefab": true, + "**/*.unity": true, + "build/": true, + "Build/": true, + "Library/": true, + "library/": true, + "obj/": true, + "Obj/": true, + "Logs/": true, + "logs/": true, + "ProjectSettings/": true, + "UserSettings/": true, + "temp/": true, + "Temp/": true + }, + "dotnet.defaultSolution": "2D-Platformer-Unity.sln" +} \ No newline at end of file diff --git a/Assets/Prefabs/Pickup/dollar.prefab b/Assets/Prefabs/Pickup/dollar.prefab index 4d5f921..6cd4f9a 100644 --- a/Assets/Prefabs/Pickup/dollar.prefab +++ b/Assets/Prefabs/Pickup/dollar.prefab @@ -98,6 +98,10 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 92818094d16fd38428ed5eff85cd1dd5, type: 3} m_Name: m_EditorClassIdentifier: + destructTime: 0.1 + destructTag: 0 + objectPool: {fileID: 0} + splashEffect: {fileID: 2860770620947254498, guid: ce32754ecbaea3342842e4a46df1e61a, type: 3} pt: 0 PickupEffect: {fileID: 5746382810402386754, guid: ce32754ecbaea3342842e4a46df1e61a, type: 3} --- !u!61 &8577905970109917546 diff --git a/Assets/Prefabs/PickupEffect2.prefab b/Assets/Prefabs/PickupEffect2.prefab index ed0bc23..65e7e96 100644 --- a/Assets/Prefabs/PickupEffect2.prefab +++ b/Assets/Prefabs/PickupEffect2.prefab @@ -11,6 +11,7 @@ GameObject: - component: {fileID: 7737238146049744554} - component: {fileID: 1182951565672295042} - component: {fileID: 1756884539125823558} + - component: {fileID: 2860770620947254498} m_Layer: 0 m_Name: PickupEffect2 m_TagString: Untagged @@ -4888,3 +4889,19 @@ ParticleSystemRenderer: m_MeshWeighting2: 1 m_MeshWeighting3: 1 m_MaskInteraction: 0 +--- !u!114 &2860770620947254498 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5746382810402386754} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 7a67df81401afa3408d5e43f59e0a3e6, type: 3} + m_Name: + m_EditorClassIdentifier: + destructTime: 1.5 + destructTag: 0 + objectPool: {fileID: 0} + splashEffect: {fileID: 2860770620947254498} diff --git a/Assets/Scenes/Level.unity b/Assets/Scenes/Level.unity index 2a35b65..4fb72fc 100644 --- a/Assets/Scenes/Level.unity +++ b/Assets/Scenes/Level.unity @@ -38,7 +38,6 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -5052,6 +5051,57 @@ Transform: m_CorrespondingSourceObject: {fileID: 2673039095717234262, guid: 74d231073b03435419ae7d180354b023, type: 3} m_PrefabInstance: {fileID: 7383182982946073322} m_PrefabAsset: {fileID: 0} +--- !u!1 &169590098 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 169590100} + - component: {fileID: 169590099} + m_Layer: 0 + m_Name: ObjectPool + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &169590099 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 169590098} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fdbc6518d6c606b478e5da886126bc03, type: 3} + m_Name: + m_EditorClassIdentifier: + pools: + - Tag: 0 + Prefab: {fileID: 2860770620947254498, guid: ce32754ecbaea3342842e4a46df1e61a, type: 3} + Size: 2 + - Tag: 1 + Prefab: {fileID: -7981618645009687228, guid: 35f409698c2eb804292697d65adef0d0, type: 3} + Size: 0 +--- !u!4 &169590100 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 169590098} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &169708902 GameObject: m_ObjectHideFlags: 0 @@ -5195,6 +5245,10 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 1552639102} m_Modifications: + - target: {fileID: -7981618645009687228, guid: 35f409698c2eb804292697d65adef0d0, type: 3} + propertyPath: destructTag + value: 1 + objectReference: {fileID: 0} - target: {fileID: 1257432869399111996, guid: 35f409698c2eb804292697d65adef0d0, type: 3} propertyPath: m_LocalPosition.x value: 39.93 @@ -6597,6 +6651,10 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 1552639102} m_Modifications: + - target: {fileID: -7981618645009687228, guid: 35f409698c2eb804292697d65adef0d0, type: 3} + propertyPath: destructTag + value: 1 + objectReference: {fileID: 0} - target: {fileID: 1257432869399111996, guid: 35f409698c2eb804292697d65adef0d0, type: 3} propertyPath: m_LocalPosition.x value: -0.25 @@ -6851,12 +6909,12 @@ MonoBehaviour: m_RequiresColorTexture: 0 m_Version: 2 m_TaaSettings: - quality: 3 - frameInfluence: 0.1 - jitterScale: 1 - mipBias: 0 - varianceClampScale: 0.9 - contrastAdaptiveSharpening: 0 + m_Quality: 3 + m_FrameInfluence: 0.1 + m_JitterScale: 1 + m_MipBias: 0 + m_VarianceClampScale: 0.9 + m_ContrastAdaptiveSharpening: 0 --- !u!20 &519420031 Camera: m_ObjectHideFlags: 0 @@ -6917,7 +6975,7 @@ Transform: m_GameObject: {fileID: 519420028} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -6.7336082, y: -0.19944, z: -10} + m_LocalPosition: {x: -9.159615, y: -0.18990004, z: -10} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] @@ -15700,6 +15758,10 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 1552639102} m_Modifications: + - target: {fileID: -7981618645009687228, guid: 35f409698c2eb804292697d65adef0d0, type: 3} + propertyPath: destructTag + value: 1 + objectReference: {fileID: 0} - target: {fileID: 1257432869399111996, guid: 35f409698c2eb804292697d65adef0d0, type: 3} propertyPath: m_LocalPosition.x value: 43.77 @@ -16037,6 +16099,10 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 1552639102} m_Modifications: + - target: {fileID: -7981618645009687228, guid: 35f409698c2eb804292697d65adef0d0, type: 3} + propertyPath: destructTag + value: 1 + objectReference: {fileID: 0} - target: {fileID: 1257432869399111996, guid: 35f409698c2eb804292697d65adef0d0, type: 3} propertyPath: m_LocalPosition.x value: -2.75 @@ -16507,6 +16573,10 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 1552639102} m_Modifications: + - target: {fileID: -7981618645009687228, guid: 35f409698c2eb804292697d65adef0d0, type: 3} + propertyPath: destructTag + value: 1 + objectReference: {fileID: 0} - target: {fileID: 1257432869399111996, guid: 35f409698c2eb804292697d65adef0d0, type: 3} propertyPath: m_LocalPosition.x value: 38.68 @@ -16564,6 +16634,10 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 1552639102} m_Modifications: + - target: {fileID: -7981618645009687228, guid: 35f409698c2eb804292697d65adef0d0, type: 3} + propertyPath: destructTag + value: 1 + objectReference: {fileID: 0} - target: {fileID: 1257432869399111996, guid: 35f409698c2eb804292697d65adef0d0, type: 3} propertyPath: m_LocalPosition.x value: 50.05 @@ -16878,6 +16952,10 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 1552639102} m_Modifications: + - target: {fileID: -7981618645009687228, guid: 35f409698c2eb804292697d65adef0d0, type: 3} + propertyPath: destructTag + value: 1 + objectReference: {fileID: 0} - target: {fileID: 1257432869399111996, guid: 35f409698c2eb804292697d65adef0d0, type: 3} propertyPath: m_LocalPosition.x value: 45.02 @@ -17112,6 +17190,10 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 1552639102} m_Modifications: + - target: {fileID: -7981618645009687228, guid: 35f409698c2eb804292697d65adef0d0, type: 3} + propertyPath: destructTag + value: 1 + objectReference: {fileID: 0} - target: {fileID: 1257432869399111996, guid: 35f409698c2eb804292697d65adef0d0, type: 3} propertyPath: m_LocalPosition.x value: 10 @@ -17892,6 +17974,7 @@ GameObject: m_Component: - component: {fileID: 1554447434} - component: {fileID: 1554447433} + - component: {fileID: 1554447435} m_Layer: 0 m_Name: GameManager m_TagString: Untagged @@ -17913,9 +17996,12 @@ MonoBehaviour: m_EditorClassIdentifier: coinText: {fileID: 169708904} playerController: {fileID: 664841622} + levelUi: {fileID: 1554447435} + objectPool: {fileID: 169590099} levelCompletePanel: {fileID: 417105073} leveCompletePanelTitle: {fileID: 515162515} levelCompleteCoins: {fileID: 1400149914} + pickups: [] --- !u!4 &1554447434 Transform: m_ObjectHideFlags: 0 @@ -17931,6 +18017,22 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1554447435 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1554447432} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5c6644b396b8acd45a0e5fb3a10bc6b7, type: 3} + m_Name: + m_EditorClassIdentifier: + coinText: {fileID: 169708904} + levelCompletePanel: {fileID: 417105073} + panelTitle: {fileID: 515162515} + panelCoinsText: {fileID: 1400149914} --- !u!1001 &1571884950 PrefabInstance: m_ObjectHideFlags: 0 @@ -17939,6 +18041,10 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 1552639102} m_Modifications: + - target: {fileID: -7981618645009687228, guid: 35f409698c2eb804292697d65adef0d0, type: 3} + propertyPath: destructTag + value: 1 + objectReference: {fileID: 0} - target: {fileID: 1257432869399111996, guid: 35f409698c2eb804292697d65adef0d0, type: 3} propertyPath: m_LocalPosition.x value: -1.5 @@ -22989,6 +23095,10 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 1552639102} m_Modifications: + - target: {fileID: -7981618645009687228, guid: 35f409698c2eb804292697d65adef0d0, type: 3} + propertyPath: destructTag + value: 1 + objectReference: {fileID: 0} - target: {fileID: 1257432869399111996, guid: 35f409698c2eb804292697d65adef0d0, type: 3} propertyPath: m_LocalPosition.x value: 48.8 @@ -23056,6 +23166,10 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 1552639102} m_Modifications: + - target: {fileID: -7981618645009687228, guid: 35f409698c2eb804292697d65adef0d0, type: 3} + propertyPath: destructTag + value: 1 + objectReference: {fileID: 0} - target: {fileID: 1257432869399111996, guid: 35f409698c2eb804292697d65adef0d0, type: 3} propertyPath: m_LocalPosition.x value: 51.3 @@ -23193,6 +23307,14 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 1552639102} m_Modifications: + - target: {fileID: -7981618645009687228, guid: 35f409698c2eb804292697d65adef0d0, type: 3} + propertyPath: destructTag + value: 1 + objectReference: {fileID: 0} + - target: {fileID: -7981618645009687228, guid: 35f409698c2eb804292697d65adef0d0, type: 3} + propertyPath: splashEffect + value: + objectReference: {fileID: 2860770620947254498, guid: ce32754ecbaea3342842e4a46df1e61a, type: 3} - target: {fileID: 1257432869399111996, guid: 35f409698c2eb804292697d65adef0d0, type: 3} propertyPath: m_LocalPosition.x value: 8.75 @@ -23312,6 +23434,10 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 1552639102} m_Modifications: + - target: {fileID: -7981618645009687228, guid: 35f409698c2eb804292697d65adef0d0, type: 3} + propertyPath: destructTag + value: 1 + objectReference: {fileID: 0} - target: {fileID: 1257432869399111996, guid: 35f409698c2eb804292697d65adef0d0, type: 3} propertyPath: m_LocalPosition.x value: 7.5 @@ -23609,3 +23735,4 @@ SceneRoots: - {fileID: 1216249950} - {fileID: 894417850} - {fileID: 1254623653} + - {fileID: 169590100} diff --git a/Assets/Scripts/Destructable.meta b/Assets/Scripts/Destructable.meta new file mode 100644 index 0000000..658a371 --- /dev/null +++ b/Assets/Scripts/Destructable.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 021db673f9ec2704f822417a83f6f81b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Destructable/Destructable.cs b/Assets/Scripts/Destructable/Destructable.cs new file mode 100644 index 0000000..8b054f2 --- /dev/null +++ b/Assets/Scripts/Destructable/Destructable.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using TMPro; +using UnityEngine.UI; + +public class Destructable : MonoBehaviour, Idestruct +{ + + [Header("Parameter")] + [SerializeField] + float destructTime = 0.1f; + + [SerializeField] + PoolTag destructTag; + + //[HideInInspector] + public ObjectPool objectPool = null; + + public Destructable splashEffect; + + public event Action OnDestructExpired; + + public ObjectPool ObjectPool + { + get { return objectPool; } + set { objectPool = value; } + } + + + + public void ReturnToPool() + { + if (objectPool == null) + { + Debug.LogWarning("ObjectPool is not assigned."); + return; + } + RemoveListener(); + objectPool.ReturnToPool(destructTag, this); + } + + public void StartDestructCountdown() + { + StartCoroutine(DestructCountdown()); + } + + private IEnumerator DestructCountdown() + { + yield return new WaitForSeconds(destructTime); + OnDestructExpired?.Invoke(this); + } + + + + public PoolTag GetDestructTag() + { + return destructTag; + } + + + + private void OnEnable() + { + OnDestructExpired += HandleDestructExpired; + } + + private void OnDisable() + { + OnDestructExpired -= HandleDestructExpired; + } + + public void RemoveListener() + { + OnDestructExpired -= HandleDestructExpired; + } + + private void HandleDestructExpired(Destructable destructable) + { + ReturnToPool(); + } + + // public void + + + +} diff --git a/Assets/Scripts/Destructable/Destructable.cs.meta b/Assets/Scripts/Destructable/Destructable.cs.meta new file mode 100644 index 0000000..cc86ea3 --- /dev/null +++ b/Assets/Scripts/Destructable/Destructable.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7a67df81401afa3408d5e43f59e0a3e6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Destructable/Idestruct.cs b/Assets/Scripts/Destructable/Idestruct.cs new file mode 100644 index 0000000..9fb1932 --- /dev/null +++ b/Assets/Scripts/Destructable/Idestruct.cs @@ -0,0 +1,10 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public interface Idestruct +{ + void ReturnToPool(); +} + + diff --git a/Assets/Scripts/Destructable/Idestruct.cs.meta b/Assets/Scripts/Destructable/Idestruct.cs.meta new file mode 100644 index 0000000..255bd53 --- /dev/null +++ b/Assets/Scripts/Destructable/Idestruct.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d51e363fe03c9f34f9f3902239b810dc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 8abd654..808e5da 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -2,15 +2,18 @@ using TMPro; using System.Collections; using UnityEngine.SceneManagement; +using System.Collections.Generic; public class GameManager : MonoBehaviour { public static GameManager instance; - [SerializeField] private TMP_Text coinText; + //[SerializeField] private TMP_Text coinText; [SerializeField] private PlayerController playerController; + [SerializeField] private GameUi levelUi; + [SerializeField] private ObjectPool objectPool; private int coinCount = 0; private int gemCount = 0; @@ -19,18 +22,16 @@ public class GameManager : MonoBehaviour //Level Complete - [SerializeField] GameObject levelCompletePanel; - [SerializeField] TMP_Text leveCompletePanelTitle; - [SerializeField] TMP_Text levelCompleteCoins; + // [SerializeField] GameObject levelCompletePanel; + // [SerializeField] TMP_Text leveCompletePanelTitle; + // [SerializeField] TMP_Text levelCompleteCoins; - - private int totalCoins = 0; - - + private int totalCoins = 0; + [SerializeField] List pickups = new List(); private void Awake() { @@ -60,8 +61,9 @@ public void IncrementGemCount() private void UpdateGUI() { - coinText.text = coinCount.ToString(); - + //coinText.text = coinCount.ToString(); + levelUi.UpdateCoinCount(coinCount); + } public void Death() @@ -86,38 +88,40 @@ public void Death() Debug.Log("Died"); } } - + public void FindTotalPickups() { - pickup[] pickups = GameObject.FindObjectsOfType(); - + // pickup[] pickups = GameObject.FindObjectsOfType(); + // var totalPickUps = foreach (pickup pickupObject in pickups) { if (pickupObject.pt == pickup.pickupType.coin) { totalCoins += 1; } - + } + } + public void AddPickupToList(pickup pickupObject) + { + pickups.Add(pickupObject); + } - + public void RemovePickupFromList(pickup pickupObject) + { + pickups.Remove(pickupObject); } + public void LevelComplete() { - - - - levelCompletePanel.SetActive(true); - leveCompletePanelTitle.text = "LEVEL COMPLETE"; - - - - levelCompleteCoins.text = "COINS COLLECTED: "+ coinCount.ToString() +" / " + totalCoins.ToString(); - + levelUi.ShowLevelComplete(coinCount, totalCoins); + // levelCompletePanel.SetActive(true); + // leveCompletePanelTitle.text = "LEVEL COMPLETE"; + // levelCompleteCoins.text = "COINS COLLECTED: "+ coinCount.ToString() +" / " + totalCoins.ToString(); } - + public IEnumerator DeathCoroutine() { yield return new WaitForSeconds(1f); @@ -131,8 +135,13 @@ public IEnumerator DeathCoroutine() { SceneManager.LoadScene(1); - + } } + public ObjectPool GetObjectPool() + { + return objectPool; + } + } diff --git a/Assets/Scripts/GameUi.cs b/Assets/Scripts/GameUi.cs new file mode 100644 index 0000000..6ab083c --- /dev/null +++ b/Assets/Scripts/GameUi.cs @@ -0,0 +1,49 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +using TMPro; +public class GameUi : MonoBehaviour +{ + [Header("HUD")] + [SerializeField] private TMP_Text coinText; + + [Header("Level Complete Panel")] + [SerializeField] private GameObject levelCompletePanel; + [SerializeField] private TMP_Text panelTitle; + [SerializeField] private TMP_Text panelCoinsText; + + private void Awake() + { + if (levelCompletePanel != null) + levelCompletePanel.SetActive(false); + } + + public void UpdateCoinCount(int count) + { + if (coinText != null) + coinText.text = count.ToString(); + } + + // public void UpdateGemCount(int count) { ... } + + public void ShowLevelComplete(int collected, int total) + { + if (levelCompletePanel == null) return; + + levelCompletePanel.SetActive(true); + + if (panelTitle != null) + panelTitle.text = "LEVEL COMPLETE"; + + if (panelCoinsText != null) + panelCoinsText.text = $"COINS COLLECTED: {collected} / {total}"; + } + + + public void HideLevelComplete() + { + if (levelCompletePanel != null) + levelCompletePanel.SetActive(false); + } +} diff --git a/Assets/Scripts/GameUi.cs.meta b/Assets/Scripts/GameUi.cs.meta new file mode 100644 index 0000000..902657f --- /dev/null +++ b/Assets/Scripts/GameUi.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5c6644b396b8acd45a0e5fb3a10bc6b7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/ObjectPool.cs b/Assets/Scripts/ObjectPool.cs new file mode 100644 index 0000000..8ecdb1e --- /dev/null +++ b/Assets/Scripts/ObjectPool.cs @@ -0,0 +1,107 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class ObjectPool : MonoBehaviour +{ + [Header("Parameter")] + [SerializeField] + List pools; + + Dictionary> poolDictionary; + + void Start() + { + Initialize(); + } + + public void Initialize() + { + poolDictionary = new Dictionary>(); + + for (int poolIndex = 0; poolIndex < pools.Count; poolIndex++) + { + Pool pool = pools[poolIndex]; + Queue objectPool = new Queue(); + + for (int i = 0; i < pool.Size; i++) + { + Destructable obj = Instantiate(pool.Prefab).GetComponent(); + obj.gameObject.SetActive(false); + objectPool.Enqueue(obj); + + // if its a ui parents it under a canvas + // obj.transform.SetParent(obj.m_IsUIDestruct ? m_uiTransformParent : transform); + } + + poolDictionary.Add(pool.Tag, objectPool); + } + } + + public Destructable SpawnFromPool(PoolTag tag, Vector3 position, Quaternion rotation) + { + if (!poolDictionary.ContainsKey(tag)) + { + Debug.LogWarning($"Pool with tag {tag} doesn't exist."); + return null; + } + + Queue objectPool = poolDictionary[tag]; + Destructable objectToSpawn = null; + + // Check if there are inactive objects available + if (objectPool.Count > 0) + { + objectToSpawn = objectPool.Dequeue(); + } + else + { + // If no inactive objects are available, instantiate a new one + Pool pool = pools.Find(p => p.Tag == tag); + if (pool != null) + { + objectToSpawn = Instantiate(pool.Prefab); + objectToSpawn.transform.position = position; + objectToSpawn.transform.rotation = rotation; + objectToSpawn.transform.SetParent(transform); + } + } + + // Activate and position the spawned object + if (objectToSpawn != null) + { + objectToSpawn.gameObject.SetActive(true); + objectToSpawn.transform.position = position; + objectToSpawn.transform.rotation = rotation; + } + + return objectToSpawn; + } + + public void ReturnToPool(PoolTag tag, Destructable objectToReturn) + { + if (!poolDictionary.ContainsKey(tag)) + { + return; + } + + objectToReturn.gameObject.SetActive(false); + poolDictionary[tag].Enqueue(objectToReturn); + } +} + + +[System.Serializable] +public class Pool +{ + public PoolTag Tag; + public Destructable Prefab; + public int Size; +} + +public enum PoolTag +{ + DestructableEffect = 0, + coins = 1 + +} \ No newline at end of file diff --git a/Assets/Scripts/ObjectPool.cs.meta b/Assets/Scripts/ObjectPool.cs.meta new file mode 100644 index 0000000..c52dd40 --- /dev/null +++ b/Assets/Scripts/ObjectPool.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fdbc6518d6c606b478e5da886126bc03 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index 2cd22c6..e0232cd 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -138,7 +138,7 @@ public void SetAnimations() footEmissions.rateOverTime = 0f; } - playeranim.SetBool("isGrounded", isGroundedBool); + // playeranim.SetBool("isGrounded", isGroundedBool); } diff --git a/Assets/Scripts/pickup.cs b/Assets/Scripts/pickup.cs index 907fcde..94299f9 100644 --- a/Assets/Scripts/pickup.cs +++ b/Assets/Scripts/pickup.cs @@ -2,12 +2,18 @@ using System.Collections.Generic; using UnityEngine; -public class pickup : MonoBehaviour +public class pickup : Destructable { public enum pickupType { coin,gem,health} public pickupType pt; - [SerializeField] GameObject PickupEffect; + //[SerializeField] GameObject PickupEffect; + + void Start() + { + RegisterPickup(); + objectPool = GameManager.instance.GetObjectPool(); + } private void OnTriggerEnter2D(Collider2D collision) { @@ -16,10 +22,16 @@ private void OnTriggerEnter2D(Collider2D collision) if(collision.gameObject.tag == "Player") { GameManager.instance.IncrementCoinCount(); - - Instantiate(PickupEffect, transform.position, Quaternion.identity); - Destroy(this.gameObject,0.2f); + var destructEffect = objectPool.SpawnFromPool(PoolTag.DestructableEffect, transform.position, Quaternion.identity); + var destructComponenet = destructEffect.GetComponent(); + destructComponenet.ObjectPool = objectPool; + destructComponenet.StartDestructCountdown(); + + StartDestructCountdown(); // return it to the pull + // Instantiate(PickupEffect, transform.position, Quaternion.identity); + + // Destroy(this.gameObject,0.2f); } @@ -31,12 +43,17 @@ private void OnTriggerEnter2D(Collider2D collision) { GameManager.instance.IncrementGemCount(); - Instantiate(PickupEffect, transform.position, Quaternion.identity); + // Instantiate(PickupEffect, transform.position, Quaternion.identity); - Destroy(this.gameObject, 0.2f); + // StartDestructCountdown(); } } } + + public void RegisterPickup() + { + GameManager.instance.AddPickupToList(this); + } }