From b5966a38bea7a85e9787617e4158fd84cc8aa6de Mon Sep 17 00:00:00 2001 From: abhi6403 <163630847+abhi6403@users.noreply.github.com> Date: Thu, 13 Feb 2025 13:00:49 +0530 Subject: [PATCH 1/3] Implemented MVC for shell --- Assets/Prefabs/LobbyUI.prefab | 64 +++++++++---------- Assets/Prefabs/Shell.prefab | 10 ++- Assets/Prefabs/Tank.prefab | 26 ++++---- Assets/Scenes/Game.unity | 5 ++ Assets/Scripts/Destroyables/Destroyables.cs | 2 +- Assets/Scripts/Shell/ShellController.cs | 27 ++++---- Assets/Scripts/Shell/ShellModel.cs | 13 ++++ Assets/Scripts/Shell/ShellModel.cs.meta | 11 ++++ Assets/Scripts/Shell/ShellView.cs | 19 ++++++ Assets/Scripts/Shell/ShellView.cs.meta | 11 ++++ .../Shaders/Ice_URP.shadergraph.meta | 2 +- .../Shaders/Dissolve_URP.shadergraph.meta | 2 +- .../Shaders/Respawn_URP.shadergraph.meta | 2 +- 13 files changed, 125 insertions(+), 69 deletions(-) create mode 100644 Assets/Scripts/Shell/ShellModel.cs create mode 100644 Assets/Scripts/Shell/ShellModel.cs.meta create mode 100644 Assets/Scripts/Shell/ShellView.cs create mode 100644 Assets/Scripts/Shell/ShellView.cs.meta diff --git a/Assets/Prefabs/LobbyUI.prefab b/Assets/Prefabs/LobbyUI.prefab index 9bd2f72..acb5126 100644 --- a/Assets/Prefabs/LobbyUI.prefab +++ b/Assets/Prefabs/LobbyUI.prefab @@ -34,7 +34,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 252, y: -139} + m_AnchoredPosition: {x: 630, y: -275} m_SizeDelta: {x: 200, y: 50} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &1221577733002267392 @@ -93,14 +93,14 @@ MonoBehaviour: m_faceColor: serializedVersion: 2 rgba: 4294967295 - m_fontSize: 36 - m_fontSizeBase: 36 + m_fontSize: 52 + m_fontSizeBase: 52 m_fontWeight: 400 m_enableAutoSizing: 0 m_fontSizeMin: 18 m_fontSizeMax: 72 m_fontStyle: 1 - m_HorizontalAlignment: 2 + m_HorizontalAlignment: 1 m_VerticalAlignment: 256 m_textAlignment: 65535 m_characterSpacing: 0 @@ -129,7 +129,7 @@ MonoBehaviour: m_VertexBufferAutoSizeReduction: 0 m_useMaxVisibleDescender: 1 m_pageToDisplay: 1 - m_margin: {x: 0, y: 0, z: 0, w: 0} + m_margin: {x: -40.421753, y: 0, z: -61.979736, w: 0} m_isUsingLegacyAnimationComponent: 0 m_isVolumetricText: 0 m_hasFontAssetChanged: 0 @@ -154,7 +154,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!224 &3870283614252560928 RectTransform: m_ObjectHideFlags: 0 @@ -210,7 +210,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3} m_Name: m_EditorClassIdentifier: - m_UiScaleMode: 1 + m_UiScaleMode: 0 m_ReferencePixelsPerUnit: 100 m_ScaleFactor: 1 m_ReferenceResolution: {x: 800, y: 600} @@ -369,8 +369,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 250, y: 0} - m_SizeDelta: {x: 150, y: 200} + m_AnchoredPosition: {x: 600, y: 8} + m_SizeDelta: {x: 380, y: 430} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &3870283614683537165 CanvasRenderer: @@ -432,8 +432,8 @@ MonoBehaviour: m_Transition: 1 m_Colors: m_NormalColor: {r: 1, g: 1, b: 1, a: 1} - m_HighlightedColor: {r: 0.5471698, g: 0.5471698, b: 0.5471698, a: 1} - m_PressedColor: {r: 0.5471698, g: 0.5471698, b: 0.5471698, a: 1} + m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} m_ColorMultiplier: 1 @@ -530,15 +530,15 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Material: {fileID: 0} - m_Color: {r: 0, g: 0, b: 0, a: 0.54901963} + m_Color: {r: 0.20754719, g: 0.19873622, b: 0.19873622, a: 0.6039216} m_RaycastTarget: 1 m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} m_Maskable: 1 m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_Sprite: {fileID: 10907, guid: 0000000000000000f000000000000000, type: 0} - m_Type: 1 + m_Sprite: {fileID: 0} + m_Type: 0 m_PreserveAspect: 0 m_FillCenter: 1 m_FillMethod: 4 @@ -582,8 +582,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 150, y: 200} + m_AnchoredPosition: {x: 0, y: 5} + m_SizeDelta: {x: 380, y: 430} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &3870283615308096693 CanvasRenderer: @@ -645,8 +645,8 @@ MonoBehaviour: m_Transition: 1 m_Colors: m_NormalColor: {r: 1, g: 1, b: 1, a: 1} - m_HighlightedColor: {r: 0.5471698, g: 0.5471698, b: 0.5471698, a: 1} - m_PressedColor: {r: 0.5471698, g: 0.5471698, b: 0.5471698, a: 1} + m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} m_ColorMultiplier: 1 @@ -714,8 +714,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: -250, y: 0} - m_SizeDelta: {x: 150, y: 200} + m_AnchoredPosition: {x: -600, y: 5} + m_SizeDelta: {x: 380, y: 430} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &3870283615956841255 CanvasRenderer: @@ -777,8 +777,8 @@ MonoBehaviour: m_Transition: 1 m_Colors: m_NormalColor: {r: 1, g: 1, b: 1, a: 1} - m_HighlightedColor: {r: 0.5471698, g: 0.5471698, b: 0.5471698, a: 1} - m_PressedColor: {r: 0.5471698, g: 0.5471698, b: 0.5471698, a: 1} + m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} m_ColorMultiplier: 1 @@ -845,7 +845,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: -1, y: -139} + m_AnchoredPosition: {x: -30, y: -275} m_SizeDelta: {x: 200, y: 50} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &1130081879593505292 @@ -904,14 +904,14 @@ MonoBehaviour: m_faceColor: serializedVersion: 2 rgba: 4294967295 - m_fontSize: 36 - m_fontSizeBase: 36 + m_fontSize: 52 + m_fontSizeBase: 52 m_fontWeight: 400 m_enableAutoSizing: 0 m_fontSizeMin: 18 m_fontSizeMax: 72 m_fontStyle: 1 - m_HorizontalAlignment: 2 + m_HorizontalAlignment: 1 m_VerticalAlignment: 256 m_textAlignment: 65535 m_characterSpacing: 0 @@ -940,7 +940,7 @@ MonoBehaviour: m_VertexBufferAutoSizeReduction: 0 m_useMaxVisibleDescender: 1 m_pageToDisplay: 1 - m_margin: {x: 0, y: 0, z: 0, w: 0} + m_margin: {x: 0, y: 0, z: -64.67468, w: 0} m_isUsingLegacyAnimationComponent: 0 m_isVolumetricText: 0 m_hasFontAssetChanged: 0 @@ -980,7 +980,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: -250, y: -139} + m_AnchoredPosition: {x: -618, y: -275} m_SizeDelta: {x: 200, y: 50} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &2841010330150748415 @@ -1039,14 +1039,14 @@ MonoBehaviour: m_faceColor: serializedVersion: 2 rgba: 4294967295 - m_fontSize: 36 - m_fontSizeBase: 36 + m_fontSize: 52 + m_fontSizeBase: 52 m_fontWeight: 400 m_enableAutoSizing: 0 m_fontSizeMin: 18 m_fontSizeMax: 72 m_fontStyle: 1 - m_HorizontalAlignment: 2 + m_HorizontalAlignment: 1 m_VerticalAlignment: 256 m_textAlignment: 65535 m_characterSpacing: 0 @@ -1075,7 +1075,7 @@ MonoBehaviour: m_VertexBufferAutoSizeReduction: 0 m_useMaxVisibleDescender: 1 m_pageToDisplay: 1 - m_margin: {x: 0, y: 0, z: 0, w: 0} + m_margin: {x: 0, y: 0, z: -56.59021, w: 0} m_isUsingLegacyAnimationComponent: 0 m_isVolumetricText: 0 m_hasFontAssetChanged: 0 diff --git a/Assets/Prefabs/Shell.prefab b/Assets/Prefabs/Shell.prefab index 58e429b..4de39f4 100644 --- a/Assets/Prefabs/Shell.prefab +++ b/Assets/Prefabs/Shell.prefab @@ -67,7 +67,7 @@ PrefabInstance: - targetCorrespondingSourceObject: {fileID: 100000, guid: 9ed1e8a25f964bd4298944675e425a0d, type: 3} insertIndex: -1 - addedObject: {fileID: 2080484652483106648} + addedObject: {fileID: 9094102746410450669} m_SourcePrefab: {fileID: 100100000, guid: 9ed1e8a25f964bd4298944675e425a0d, type: 3} --- !u!1 &6691933039618786073 stripped GameObject: @@ -123,7 +123,7 @@ BoxCollider: serializedVersion: 3 m_Size: {x: 0.2987081, y: 0.26465786, z: 0.5166997} m_Center: {x: 0, y: 0.008731306, z: 0.19371921} ---- !u!114 &2080484652483106648 +--- !u!114 &9094102746410450669 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -132,10 +132,8 @@ MonoBehaviour: m_GameObject: {fileID: 6691933039618786073} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: efe29f4b8836cd74684e96d6b8a21cdf, type: 3} + m_Script: {fileID: 11500000, guid: 19a26dfc617b47c43b975bac52edba00, type: 3} m_Name: m_EditorClassIdentifier: - explosion: {fileID: 876944751265867935, guid: a325166043ffcc448a7670e9fecd8815, - type: 3} - fireParticle: {fileID: 7731502986580185585, guid: ee6933974236ce54286eae798bb3287e, + shellExploision: {fileID: 876944751265867935, guid: a325166043ffcc448a7670e9fecd8815, type: 3} diff --git a/Assets/Prefabs/Tank.prefab b/Assets/Prefabs/Tank.prefab index 090f040..fbb8587 100644 --- a/Assets/Prefabs/Tank.prefab +++ b/Assets/Prefabs/Tank.prefab @@ -64,7 +64,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 0, y: -2.25} + m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0.5, y: 0.5} --- !u!1 &4357085371443335405 @@ -91,18 +91,18 @@ RectTransform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4357085371443335405} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: -1} + m_LocalRotation: {x: -0.042976465, y: -0, z: -0, w: 0.9990761} + m_LocalPosition: {x: 0, y: 0, z: -0.96} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: - {fileID: 3217123901393735791} m_Father: {fileID: 1439225616756593854} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_LocalEulerAnglesHint: {x: -4.926, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 0.087249964, y: 2.65} - m_SizeDelta: {x: -1.8255, y: 1.6907} + m_AnchoredPosition: {x: -0.000000059604645, y: 1.31} + m_SizeDelta: {x: 0, y: -1.4512} m_Pivot: {x: 0.5, y: 0.45166743} --- !u!114 &1289341129724263172 MonoBehaviour: @@ -189,7 +189,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0} - m_AnchoredPosition: {x: 0, y: 5} + m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &5902429766816407952 @@ -257,8 +257,8 @@ RectTransform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7892152523456331593} m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} + m_LocalPosition: {x: 0, y: 0, z: 2.7489} + m_LocalScale: {x: 1.3333334, y: 1.3333334, z: 1.3333334} m_ConstrainProportionsScale: 0 m_Children: - {fileID: 2630859995377569576} @@ -266,8 +266,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0} - m_AnchoredPosition: {x: 0, y: 0.1} - m_SizeDelta: {x: 3.5, y: 3.5} + m_AnchoredPosition: {x: -0.0031, y: 0.1} + m_SizeDelta: {x: 1.3918, y: 6.1901} m_Pivot: {x: 0.5, y: 0.5} --- !u!223 &8053286205472130276 Canvas: @@ -304,7 +304,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3} m_Name: m_EditorClassIdentifier: - m_UiScaleMode: 0 + m_UiScaleMode: 2 m_ReferencePixelsPerUnit: 1 m_ScaleFactor: 1 m_ReferenceResolution: {x: 800, y: 600} @@ -431,8 +431,6 @@ MonoBehaviour: childs: - {fileID: 4959132435605449605} - {fileID: 4959132435605449607} - ShellController: {fileID: 2080484652483106648, guid: 28fefa089149ea847ae843638066c83a, - type: 3} fireTransform: {fileID: 6544317465860475146} aimSlider: {fileID: 1289341129724263172} shell: {fileID: 8142298251708592852, guid: 28fefa089149ea847ae843638066c83a, type: 3} diff --git a/Assets/Scenes/Game.unity b/Assets/Scenes/Game.unity index 1ddc1fe..76ca0d3 100644 --- a/Assets/Scenes/Game.unity +++ b/Assets/Scenes/Game.unity @@ -1417,6 +1417,11 @@ PrefabInstance: propertyPath: m_Name value: LobbyUI objectReference: {fileID: 0} + - target: {fileID: 3870283614252561372, guid: b02382b9e205b7f4d89a5c94e08a2724, + type: 3} + propertyPath: m_IsActive + value: 0 + objectReference: {fileID: 0} - target: {fileID: 3870283614683537163, guid: b02382b9e205b7f4d89a5c94e08a2724, type: 3} propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Target diff --git a/Assets/Scripts/Destroyables/Destroyables.cs b/Assets/Scripts/Destroyables/Destroyables.cs index c9c68c0..6553fba 100644 --- a/Assets/Scripts/Destroyables/Destroyables.cs +++ b/Assets/Scripts/Destroyables/Destroyables.cs @@ -15,7 +15,7 @@ public class Destroyables : MonoBehaviour public void OnCollisionEnter(Collision other) { - ShellController shell = other.gameObject.GetComponent(); + ShellView shell = other.gameObject.GetComponent(); if (shell) { diff --git a/Assets/Scripts/Shell/ShellController.cs b/Assets/Scripts/Shell/ShellController.cs index 8d9c229..564d120 100644 --- a/Assets/Scripts/Shell/ShellController.cs +++ b/Assets/Scripts/Shell/ShellController.cs @@ -1,28 +1,29 @@ using System; using System.Collections; using System.Collections.Generic; +using Unity.IO.LowLevel.Unsafe; using UnityEngine; +using Object = UnityEngine.Object; -public class ShellController : MonoBehaviour +public class ShellController { - public ParticleSystem explosion; + private ShellView shellView; + private ShellModel shellModel; - private void OnCollisionEnter(Collision collision) + public ShellController(ShellView shellView, ShellModel shellModel,Transform shellTransform) { - SpawnDamageParticles(); - Explode(); + this.shellModel = shellModel; + this.shellView = Fire(shellView,shellTransform); } - - private void Explode() - { - Destroy(gameObject); - } - - private void SpawnDamageParticles() + private ShellView Fire(ShellView shellView, Transform shellTransform) { - Instantiate(explosion, transform.position, Quaternion.identity); + GameObject shellGameObject = Object.Instantiate(shellView.gameObject, shellTransform.position, shellTransform.rotation); + + return shellGameObject.GetComponent(); } + + } diff --git a/Assets/Scripts/Shell/ShellModel.cs b/Assets/Scripts/Shell/ShellModel.cs new file mode 100644 index 0000000..f98b5b2 --- /dev/null +++ b/Assets/Scripts/Shell/ShellModel.cs @@ -0,0 +1,13 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class ShellModel +{ + public float launchForce; + + public ShellModel(float launchForce) + { + this.launchForce = launchForce; + } +} diff --git a/Assets/Scripts/Shell/ShellModel.cs.meta b/Assets/Scripts/Shell/ShellModel.cs.meta new file mode 100644 index 0000000..2047328 --- /dev/null +++ b/Assets/Scripts/Shell/ShellModel.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d33da15aecf6b2c4c87b23d7f683fd29 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Shell/ShellView.cs b/Assets/Scripts/Shell/ShellView.cs new file mode 100644 index 0000000..df4b54e --- /dev/null +++ b/Assets/Scripts/Shell/ShellView.cs @@ -0,0 +1,19 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class ShellView : MonoBehaviour +{ + [SerializeField]private ParticleSystem shellExploision; + private ShellController shellController; + + private void OnCollisionEnter(Collision collision) + { + SpawnDamageParticles(); + Destroy(gameObject); + } + private void SpawnDamageParticles() + { + Instantiate(shellExploision, transform.position, Quaternion.identity); + } +} diff --git a/Assets/Scripts/Shell/ShellView.cs.meta b/Assets/Scripts/Shell/ShellView.cs.meta new file mode 100644 index 0000000..d0ca64c --- /dev/null +++ b/Assets/Scripts/Shell/ShellView.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 19a26dfc617b47c43b975bac52edba00 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UnityTechnologies/ParticlePack/EffectExamples/Magic Effects/Shaders/Ice_URP.shadergraph.meta b/Assets/UnityTechnologies/ParticlePack/EffectExamples/Magic Effects/Shaders/Ice_URP.shadergraph.meta index c579727..32c7ba8 100644 --- a/Assets/UnityTechnologies/ParticlePack/EffectExamples/Magic Effects/Shaders/Ice_URP.shadergraph.meta +++ b/Assets/UnityTechnologies/ParticlePack/EffectExamples/Magic Effects/Shaders/Ice_URP.shadergraph.meta @@ -7,4 +7,4 @@ ScriptedImporter: userData: assetBundleName: assetBundleVariant: - script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3} + script: {instanceID: 0} diff --git a/Assets/UnityTechnologies/ParticlePack/EffectExamples/Misc Effects/Shaders/Dissolve_URP.shadergraph.meta b/Assets/UnityTechnologies/ParticlePack/EffectExamples/Misc Effects/Shaders/Dissolve_URP.shadergraph.meta index 63f5ff1..850535d 100644 --- a/Assets/UnityTechnologies/ParticlePack/EffectExamples/Misc Effects/Shaders/Dissolve_URP.shadergraph.meta +++ b/Assets/UnityTechnologies/ParticlePack/EffectExamples/Misc Effects/Shaders/Dissolve_URP.shadergraph.meta @@ -7,4 +7,4 @@ ScriptedImporter: userData: assetBundleName: assetBundleVariant: - script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3} + script: {instanceID: 0} diff --git a/Assets/UnityTechnologies/ParticlePack/EffectExamples/Misc Effects/Shaders/Respawn_URP.shadergraph.meta b/Assets/UnityTechnologies/ParticlePack/EffectExamples/Misc Effects/Shaders/Respawn_URP.shadergraph.meta index 1a2b303..c6a3340 100644 --- a/Assets/UnityTechnologies/ParticlePack/EffectExamples/Misc Effects/Shaders/Respawn_URP.shadergraph.meta +++ b/Assets/UnityTechnologies/ParticlePack/EffectExamples/Misc Effects/Shaders/Respawn_URP.shadergraph.meta @@ -7,4 +7,4 @@ ScriptedImporter: userData: assetBundleName: assetBundleVariant: - script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3} + script: {instanceID: 0} From 605b350709040ff5ee305869872530a699af15c6 Mon Sep 17 00:00:00 2001 From: abhi6403 <163630847+abhi6403@users.noreply.github.com> Date: Thu, 13 Feb 2025 13:51:10 +0530 Subject: [PATCH 2/3] Updated Tank MVC --- Assets/Prefabs/Tank.prefab | 14 ++++++ Assets/Scripts/Tank/TankController.cs | 19 ++++---- Assets/Scripts/Tank/TankModel.cs | 67 +++++++++++++++++++++++---- Assets/Scripts/Tank/TankView.cs | 42 ++++++++++------- 4 files changed, 107 insertions(+), 35 deletions(-) diff --git a/Assets/Prefabs/Tank.prefab b/Assets/Prefabs/Tank.prefab index fbb8587..09f78c6 100644 --- a/Assets/Prefabs/Tank.prefab +++ b/Assets/Prefabs/Tank.prefab @@ -430,6 +430,8 @@ MonoBehaviour: rb: {fileID: -6539351600588824667} childs: - {fileID: 4959132435605449605} + - {fileID: 4959132435605449603} + - {fileID: 4959132435605449613} - {fileID: 4959132435605449607} fireTransform: {fileID: 6544317465860475146} aimSlider: {fileID: 1289341129724263172} @@ -488,6 +490,12 @@ Transform: type: 3} m_PrefabInstance: {fileID: 4959132435603420133} m_PrefabAsset: {fileID: 0} +--- !u!23 &4959132435605449603 stripped +MeshRenderer: + m_CorrespondingSourceObject: {fileID: 2300006, guid: 002e2a607f5b64c48be0b3b0d8b8bfdd, + type: 3} + m_PrefabInstance: {fileID: 4959132435603420133} + m_PrefabAsset: {fileID: 0} --- !u!23 &4959132435605449605 stripped MeshRenderer: m_CorrespondingSourceObject: {fileID: 2300000, guid: 002e2a607f5b64c48be0b3b0d8b8bfdd, @@ -500,3 +508,9 @@ MeshRenderer: type: 3} m_PrefabInstance: {fileID: 4959132435603420133} m_PrefabAsset: {fileID: 0} +--- !u!23 &4959132435605449613 stripped +MeshRenderer: + m_CorrespondingSourceObject: {fileID: 2300008, guid: 002e2a607f5b64c48be0b3b0d8b8bfdd, + type: 3} + m_PrefabInstance: {fileID: 4959132435603420133} + m_PrefabAsset: {fileID: 0} diff --git a/Assets/Scripts/Tank/TankController.cs b/Assets/Scripts/Tank/TankController.cs index 313cdb6..70ff2f6 100644 --- a/Assets/Scripts/Tank/TankController.cs +++ b/Assets/Scripts/Tank/TankController.cs @@ -16,7 +16,7 @@ public TankController(TankModel _tankModel, TankView _tankView) tankModel.setTankController(this); tankView.setTankController(this); - tankView.ChangeColor(tankModel.tankMaterial); + tankView.ChangeColor(tankModel.GetTankMaterial()); } public void Move(float movement,float movementSpeed) @@ -33,22 +33,23 @@ public void Rotate(float rotate, float rotationSpeed) public void FireProcess() { - tankView.aimSlider.value = tankModel.minLaunchForce; + tankView.getSlider().value = tankModel.getMinLaunchForce(); - if (tankModel.currentLaunchForce >= tankModel.maxLaunchForce && !tankModel.fired) + if (tankModel.getCurrentLaunchForce() >= tankModel.getMaxLaunchForce() && !tankModel.getFiredState()) { - tankModel.currentLaunchForce = tankModel.maxLaunchForce; + tankModel.setCurrentLaunchForce(tankModel.getMaxLaunchForce()); tankView.Fire(); } else if (Input.GetButtonDown("Jump")) { - tankModel.fired = false; - tankModel.currentLaunchForce = tankModel.minLaunchForce; + tankModel.setFiredState(false); + tankModel.setCurrentLaunchForce( tankModel.getMinLaunchForce()); } - else if (Input.GetButton("Jump") && !tankModel.fired) + else if (Input.GetButton("Jump") && !tankModel.getFiredState()) { - tankModel.currentLaunchForce += tankModel.chargeSpeed * Time.deltaTime; - tankView.aimSlider.value = tankModel.currentLaunchForce; + float tempLaunchForce = tankModel.getCurrentLaunchForce() + tankModel.getChargeSpeed() * Time.deltaTime; + tankModel.setCurrentLaunchForce(tempLaunchForce); + tankView.getSlider().value = tankModel.getCurrentLaunchForce(); } else if (Input.GetButtonUp("Jump")) { diff --git a/Assets/Scripts/Tank/TankModel.cs b/Assets/Scripts/Tank/TankModel.cs index 0639bcb..0b5b4a4 100644 --- a/Assets/Scripts/Tank/TankModel.cs +++ b/Assets/Scripts/Tank/TankModel.cs @@ -4,19 +4,19 @@ public class TankModel { private TankController tankController; - public float movementSpeed; - public float rotationSpeed; + private float movementSpeed; + private float rotationSpeed; - public TankTypes tankType; - public Material tankMaterial; + private TankTypes tankType; + private Material tankMaterial; - public float minLaunchForce = 15f; - public float maxLaunchForce = 30f; - public float maxChargeTime = 0.75f; + private float minLaunchForce = 15f; + private float maxLaunchForce = 30f; + private float maxChargeTime = 0.75f; - public float currentLaunchForce; - public float chargeSpeed; - public bool fired; + private float currentLaunchForce; + private float chargeSpeed; + private bool fired; public TankModel(float _movement, float _rotation,TankTypes _tankType, Material _tankMaterial) { @@ -29,6 +29,53 @@ public TankModel(float _movement, float _rotation,TankTypes _tankType, Material chargeSpeed = (maxLaunchForce - minLaunchForce) / maxChargeTime; } + + public Material GetTankMaterial() + { + return tankMaterial; + } + public float getMovementSpeed() + { + return movementSpeed; + } + + public float getRotationSpeed() + { + return rotationSpeed; + } + + public float getChargeSpeed() + { + return chargeSpeed; + } + + public void setFiredState(bool _fired) + { + this.fired = _fired; + } + + public bool getFiredState() + { + return fired; + } + public float getCurrentLaunchForce() + { + return currentLaunchForce; + } + + public void setCurrentLaunchForce(float _currentLaunchForce) + { + currentLaunchForce = _currentLaunchForce; + } + public float getMinLaunchForce() + { + return minLaunchForce; + } + + public float getMaxLaunchForce() + { + return maxLaunchForce; + } public void setTankController(TankController _tankController) { tankController = _tankController; diff --git a/Assets/Scripts/Tank/TankView.cs b/Assets/Scripts/Tank/TankView.cs index 986e255..2b6d2ba 100644 --- a/Assets/Scripts/Tank/TankView.cs +++ b/Assets/Scripts/Tank/TankView.cs @@ -9,17 +9,14 @@ public class TankView : MonoBehaviour private float movement; private float rotation; - public Rigidbody rb; - public MeshRenderer[] childs; + [SerializeField] private Rigidbody rb; + [SerializeField] private MeshRenderer[] childs; - public Transform fireTransform; - public Slider aimSlider; + [SerializeField] private Transform fireTransform; + [SerializeField] private Slider aimSlider; - public Rigidbody shell; - public void setTankController(TankController _tankController) - { - tankController = _tankController; - } + [SerializeField] public Rigidbody shell; + private void Start() { @@ -27,24 +24,27 @@ private void Start() cameraShake = cam.GetComponent(); cam.transform.SetParent(transform); cam.transform.position = new Vector3(0f, 3f, -4f); - tankController.GetTankView().aimSlider.value = tankController.GetTankModel().minLaunchForce; + tankController.GetTankView().aimSlider.value = tankController.GetTankModel().getMinLaunchForce(); } private void Update() { Movement(); + ControlMovement(); + tankController.FireProcess(); + } + private void ControlMovement() + { if (movement != 0) { - tankController.Move(movement,tankController.GetTankModel().movementSpeed); + tankController.Move(movement,tankController.GetTankModel().getMovementSpeed()); } if (rotation != 0) { - tankController.Rotate(rotation,tankController.GetTankModel().rotationSpeed); + tankController.Rotate(rotation,tankController.GetTankModel().getRotationSpeed()); } - - tankController.FireProcess(); } private void Movement() @@ -63,15 +63,25 @@ public void ChangeColor(Material color) public void Fire() { - tankController.GetTankModel().fired = true; + tankController.GetTankModel().setFiredState(true); Rigidbody shellInstance = Instantiate(shell, fireTransform.position, fireTransform.rotation) as Rigidbody; StartCoroutine(cameraShake.Shake(0.1f, 0.1f)); - shellInstance.velocity = tankController.GetTankModel().currentLaunchForce * fireTransform.forward; + shellInstance.velocity = tankController.GetTankModel().getCurrentLaunchForce() * fireTransform.forward; } public Rigidbody getRigidbody() { return rb; } + + public Slider getSlider() + { + return aimSlider; + } + + public void setTankController(TankController _tankController) + { + tankController = _tankController; + } } From 8bc7c7f0ced4db251b356dad3bcf2aa15f257042 Mon Sep 17 00:00:00 2001 From: abhi6403 <163630847+abhi6403@users.noreply.github.com> Date: Fri, 14 Feb 2025 18:30:04 +0530 Subject: [PATCH 3/3] Spawning the bullet --- Assets/Prefabs/Shell.prefab | 2 +- Assets/Scenes/Game.unity | 67 +++++++++++++++++++++ Assets/Scripts/Destroyables/Destroyables.cs | 10 ++- Assets/Scripts/Shell/ShellController.cs | 38 ++++++++++-- Assets/Scripts/Shell/ShellModel.cs | 57 ++++++++++++++++-- Assets/Scripts/Shell/ShellSpawner.cs | 55 +++++++++++++++++ Assets/Scripts/Shell/ShellSpawner.cs.meta | 11 ++++ Assets/Scripts/Shell/ShellTypes.cs | 10 +++ Assets/Scripts/Shell/ShellTypes.cs.meta | 11 ++++ Assets/Scripts/Shell/ShellView.cs | 63 ++++++++++++++++++- Assets/Scripts/Tank/TankModel.cs | 21 +++++-- Assets/Scripts/Tank/TankSpwaner.cs | 46 ++++++++++---- Assets/Scripts/Tank/TankView.cs | 18 ++++-- 13 files changed, 372 insertions(+), 37 deletions(-) create mode 100644 Assets/Scripts/Shell/ShellSpawner.cs create mode 100644 Assets/Scripts/Shell/ShellSpawner.cs.meta create mode 100644 Assets/Scripts/Shell/ShellTypes.cs create mode 100644 Assets/Scripts/Shell/ShellTypes.cs.meta diff --git a/Assets/Prefabs/Shell.prefab b/Assets/Prefabs/Shell.prefab index 4de39f4..94e9ce3 100644 --- a/Assets/Prefabs/Shell.prefab +++ b/Assets/Prefabs/Shell.prefab @@ -135,5 +135,5 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 19a26dfc617b47c43b975bac52edba00, type: 3} m_Name: m_EditorClassIdentifier: - shellExploision: {fileID: 876944751265867935, guid: a325166043ffcc448a7670e9fecd8815, + shellExplosion: {fileID: 876944751265867935, guid: a325166043ffcc448a7670e9fecd8815, type: 3} diff --git a/Assets/Scenes/Game.unity b/Assets/Scenes/Game.unity index 76ca0d3..8d9bead 100644 --- a/Assets/Scenes/Game.unity +++ b/Assets/Scenes/Game.unity @@ -1304,6 +1304,65 @@ Canvas: m_SortingLayerID: 0 m_SortingOrder: 0 m_TargetDisplay: 0 +--- !u!1 &1032831209 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1032831211} + - component: {fileID: 1032831210} + m_Layer: 0 + m_Name: ShellSpawner + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1032831210 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1032831209} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: becf24fea7dd9a04e985dd3150c6f094, type: 3} + m_Name: + m_EditorClassIdentifier: + shellView: {fileID: 9094102746410450669, guid: 28fefa089149ea847ae843638066c83a, + type: 3} + shells: + - shellType: 0 + damagePower: 100 + explosionRadius: 10 + explosionForce: 0 + - shellType: 1 + damagePower: 20 + explosionRadius: 1 + explosionForce: 0 + - shellType: 2 + damagePower: 50 + explosionRadius: 5 + explosionForce: 0 +--- !u!4 &1032831211 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1032831209} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -0.0031000674, y: 1.4333335, z: 2.8769128} + 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!1001 &1132741370 PrefabInstance: m_ObjectHideFlags: 0 @@ -2807,19 +2866,26 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: ad225eade72e848488c7fcc11f33c498, type: 3} m_Name: m_EditorClassIdentifier: + shellSpawner: {fileID: 1032831210} tankView: {fileID: 2262637418626244599, guid: 5f6f31c77b9ac524b9c770a09e7603e6, type: 3} tanksList: - movementSpeed: 30 rotationSpeed: 75 + minLaunchForce: 0 + maxLaunchForce: 0 tankType: 0 color: {fileID: 2100000, guid: c39933e60e73205419d1f79a2af1fdac, type: 2} - movementSpeed: 10 rotationSpeed: 50 + minLaunchForce: 0 + maxLaunchForce: 0 tankType: 1 color: {fileID: 2100000, guid: 463052f3f7389124f9e7b34b0b931d0d, type: 2} - movementSpeed: 60 rotationSpeed: 120 + minLaunchForce: 0 + maxLaunchForce: 0 tankType: 2 color: {fileID: 2100000, guid: ff21ff0ea9b18924bb1fdfbb0e58f5cb, type: 2} --- !u!4 &2009169650 @@ -2921,3 +2987,4 @@ SceneRoots: - {fileID: 2009169650} - {fileID: 1009262948} - {fileID: 1653019543} + - {fileID: 1032831211} diff --git a/Assets/Scripts/Destroyables/Destroyables.cs b/Assets/Scripts/Destroyables/Destroyables.cs index 6553fba..732ec57 100644 --- a/Assets/Scripts/Destroyables/Destroyables.cs +++ b/Assets/Scripts/Destroyables/Destroyables.cs @@ -10,7 +10,7 @@ public class Destroyables : MonoBehaviour public float health; public ParticleSystem explosionparticle; public UIController uIController; - private float damagePower = 50f; + private float damage; public void OnCollisionEnter(Collision other) @@ -24,11 +24,15 @@ public void OnCollisionEnter(Collision other) SpawnDamageParticles(); Destroy(gameObject); } - health -= damagePower; - uIController.UpdateScoreText(damagePower); + health -= damage; + uIController.UpdateScoreText(damage); } } + public void setDamage(float _damage) + { + damage = _damage; + } private void SpawnDamageParticles() { Instantiate(explosionparticle, transform.position, Quaternion.identity); diff --git a/Assets/Scripts/Shell/ShellController.cs b/Assets/Scripts/Shell/ShellController.cs index 564d120..8da08d9 100644 --- a/Assets/Scripts/Shell/ShellController.cs +++ b/Assets/Scripts/Shell/ShellController.cs @@ -9,11 +9,17 @@ public class ShellController { private ShellView shellView; private ShellModel shellModel; + private Rigidbody shellRigidBody; - public ShellController(ShellView shellView, ShellModel shellModel,Transform shellTransform) + public ShellController(ShellView _shellView, ShellModel _shellModel) { - this.shellModel = shellModel; - this.shellView = Fire(shellView,shellTransform); + shellModel = _shellModel; + shellModel.SetShellController(this); + Transform originTransform = getOriginTransform(); + shellView = GameObject.Instantiate(_shellView); + shellView.SetShellController(this); + shellRigidBody = shellView.getShellRigidbody(); + shellRigidBody.velocity = getVelocity(); } private ShellView Fire(ShellView shellView, Transform shellTransform) @@ -22,8 +28,30 @@ private ShellView Fire(ShellView shellView, Transform shellTransform) return shellGameObject.GetComponent(); } - - + + public float getExplosionRadius() + { + return shellModel.getExplosionRadius(); + } + + public Transform getOriginTransform() + { + return shellModel.getOriginPoint(); + } + + public Vector3 getVelocity() + { + return shellModel.getVelocity(); + } + public float getExplosionForce() + { + return shellModel.getExplosionForce(); + } + + public float getDamagePower() + { + return shellModel.getDamagePower(); + } } diff --git a/Assets/Scripts/Shell/ShellModel.cs b/Assets/Scripts/Shell/ShellModel.cs index f98b5b2..4492208 100644 --- a/Assets/Scripts/Shell/ShellModel.cs +++ b/Assets/Scripts/Shell/ShellModel.cs @@ -2,12 +2,61 @@ using System.Collections.Generic; using UnityEngine; -public class ShellModel +public class ShellModel { - public float launchForce; + private ShellController shellController; + + private ShellTypes shellType; + private float damagePower; + private float explosionRadius; + private float explosionForce; + private Vector3 velocity; + private Transform originPoint; - public ShellModel(float launchForce) + public ShellModel( + ShellTypes _shellType, + float _damage, + float _explosionRadius, + float _explosionForce, + Vector3 _velocity, + Transform _originPoint) { - this.launchForce = launchForce; + shellType = _shellType; + damagePower = _damage; + explosionRadius = _explosionRadius; + explosionForce = _explosionForce; + velocity = _velocity; + originPoint = _originPoint; } + + public void SetShellController(ShellController _shellController) + { + shellController = _shellController; + } + + public float getExplosionRadius() + { + return explosionRadius; + } + + public float getExplosionForce() + { + return explosionForce; + } + + public float getDamagePower() + { + return damagePower; + } + + public Vector3 getVelocity() + { + return velocity; + } + + public Transform getOriginPoint() + { + return originPoint; + } + } diff --git a/Assets/Scripts/Shell/ShellSpawner.cs b/Assets/Scripts/Shell/ShellSpawner.cs new file mode 100644 index 0000000..6ef04bc --- /dev/null +++ b/Assets/Scripts/Shell/ShellSpawner.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class ShellSpawner : MonoBehaviour +{ + [SerializeField] private ShellView shellView; + + [System.Serializable] + public class Shell + { + public ShellTypes shellType; + public float damagePower; + public float explosionRadius; + public float explosionForce; + } + + [SerializeField] private List shells; + + + public void SpawnShell(ShellTypes shellType,Vector3 velocity,Transform originPoint) + { + Shell shell = null; + + switch (shellType) + { + case ShellTypes.REDTANKSHELL: + shell = shells[2]; + break; + case ShellTypes.BLUETANKSHELL: + shell = shells[1]; + break; + case ShellTypes.GREENTANKSHELL: + shell = shells[0]; + break; + } + + if (shell != null) + { + ShellModel shellModel = new ShellModel( + shell.shellType, + shell.damagePower, + shell.explosionRadius, + shell.explosionForce, + velocity, + originPoint + ); + + ShellController shellController = new ShellController(shellView,shellModel); + + } + + } +} diff --git a/Assets/Scripts/Shell/ShellSpawner.cs.meta b/Assets/Scripts/Shell/ShellSpawner.cs.meta new file mode 100644 index 0000000..d94c302 --- /dev/null +++ b/Assets/Scripts/Shell/ShellSpawner.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: becf24fea7dd9a04e985dd3150c6f094 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Shell/ShellTypes.cs b/Assets/Scripts/Shell/ShellTypes.cs new file mode 100644 index 0000000..7657857 --- /dev/null +++ b/Assets/Scripts/Shell/ShellTypes.cs @@ -0,0 +1,10 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public enum ShellTypes +{ + GREENTANKSHELL, + BLUETANKSHELL, + REDTANKSHELL, +} diff --git a/Assets/Scripts/Shell/ShellTypes.cs.meta b/Assets/Scripts/Shell/ShellTypes.cs.meta new file mode 100644 index 0000000..a391514 --- /dev/null +++ b/Assets/Scripts/Shell/ShellTypes.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a9e6afa87c2515847b1f323a108b8aa0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Shell/ShellView.cs b/Assets/Scripts/Shell/ShellView.cs index df4b54e..286c294 100644 --- a/Assets/Scripts/Shell/ShellView.cs +++ b/Assets/Scripts/Shell/ShellView.cs @@ -1,19 +1,78 @@ +using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class ShellView : MonoBehaviour { - [SerializeField]private ParticleSystem shellExploision; + [SerializeField]private ParticleSystem shellExplosion; private ShellController shellController; + private Rigidbody shellRigidbody; + private Destroyables destroyables; + private void Start() + { + destroyables = FindObjectOfType(); + } + + public void SetShellController(ShellController _shellController) + { + shellController = _shellController; + } private void OnCollisionEnter(Collision collision) { + CollisionWithDestroyables(); SpawnDamageParticles(); Destroy(gameObject); } + + private void CollisionWithDestroyables() + { + float explosionRadius = shellController.getExplosionRadius(); + float explosionForce = shellController.getExplosionForce(); + + Collider[] colliders = Physics.OverlapSphere(transform.position, explosionRadius); + for (int i = 0; i < colliders.Length; i++) + { + //Rigidbody rigidbody = colliders[i].GetComponent(); + + Destroyables destroyables = colliders[i].GetComponent(); + + if (destroyables != null) + { + float damage = ProcessCollisionToDestroyables(explosionForce, explosionRadius); + this.destroyables.setDamage(damage); + } + } + } + private float ProcessCollisionToDestroyables(float explosionForce, float explosionRadius) + { + shellRigidbody.AddExplosionForce(explosionForce,transform.position,explosionRadius); + float damage = CalculateDamage(shellRigidbody.position); + return damage; + } + private float CalculateDamage(Vector3 targetPosition) + { + float explosionRadius = shellController.getExplosionRadius(); + float damagePower = shellController.getDamagePower(); + + Vector3 explosionToTarget = targetPosition - transform.position; + float explosionDistance = explosionToTarget.magnitude; + float relativeDistance = (explosionRadius - explosionDistance) / explosionRadius; + float damage = relativeDistance * damagePower; + + damage = Mathf.Max(0f, damage); + + return damage; + } + private void SpawnDamageParticles() { - Instantiate(shellExploision, transform.position, Quaternion.identity); + Instantiate(shellExplosion, transform.position, Quaternion.identity); + } + + public Rigidbody getShellRigidbody() + { + return shellRigidbody; } } diff --git a/Assets/Scripts/Tank/TankModel.cs b/Assets/Scripts/Tank/TankModel.cs index 0b5b4a4..b56e8ed 100644 --- a/Assets/Scripts/Tank/TankModel.cs +++ b/Assets/Scripts/Tank/TankModel.cs @@ -10,26 +10,39 @@ public class TankModel private TankTypes tankType; private Material tankMaterial; - private float minLaunchForce = 15f; - private float maxLaunchForce = 30f; - private float maxChargeTime = 0.75f; + private float minLaunchForce; + private float maxLaunchForce; + private float maxChargeTime; private float currentLaunchForce; private float chargeSpeed; private bool fired; - public TankModel(float _movement, float _rotation,TankTypes _tankType, Material _tankMaterial) + public TankModel( + TankTypes _tankType, + Material _tankMaterial, + float _movement, + float _rotation, + float _minLaunchForce, + float _maxLaunchForce + ) { movementSpeed = _movement; rotationSpeed = _rotation; tankType = _tankType; tankMaterial = _tankMaterial; + minLaunchForce = _minLaunchForce; + maxLaunchForce = _maxLaunchForce; currentLaunchForce = minLaunchForce; chargeSpeed = (maxLaunchForce - minLaunchForce) / maxChargeTime; } + public TankTypes getTankType() + { + return tankType; + } public Material GetTankMaterial() { return tankMaterial; diff --git a/Assets/Scripts/Tank/TankSpwaner.cs b/Assets/Scripts/Tank/TankSpwaner.cs index 04a7f72..31638dd 100644 --- a/Assets/Scripts/Tank/TankSpwaner.cs +++ b/Assets/Scripts/Tank/TankSpwaner.cs @@ -8,10 +8,14 @@ public class Tank { public float movementSpeed; public float rotationSpeed; + public float minLaunchForce; + public float maxLaunchForce; public TankTypes tankType; public Material color; } + + [SerializeField] private ShellSpawner shellSpawner; public TankView tankView; @@ -19,22 +23,38 @@ public class Tank public void CreateTank(TankTypes tankType) { - if (tankType == TankTypes.BLUETANK) - { - TankModel tankModel = new TankModel(tanksList[2].movementSpeed,tanksList[2].rotationSpeed,tanksList[2].tankType,tanksList[2].color); - TankController controller = new TankController(tankModel, tankView); - } - - if (tankType == TankTypes.GREENTANK) + Tank tank = null; + + switch (tankType) { - TankModel tankModel = new TankModel(tanksList[0].movementSpeed,tanksList[0].rotationSpeed,tanksList[0].tankType,tanksList[0].color); - TankController controller = new TankController(tankModel, tankView); + case TankTypes.GREENTANK: + tank = tanksList[0]; + break; + case TankTypes.BLUETANK: + tank = tanksList[1]; + break; + case TankTypes.REDTANK: + tank = tanksList[2]; + break; } - - if (tankType == TankTypes.REDTANK) + + if (tank != null) { - TankModel tankModel = new TankModel(tanksList[1].movementSpeed,tanksList[1].rotationSpeed,tanksList[1].tankType,tanksList[1].color); - TankController controller = new TankController(tankModel, tankView); + TankModel tankModel = new TankModel( + tank.tankType, + tank.color, + tank.movementSpeed, + tank.rotationSpeed, + tank.minLaunchForce, + tank.maxLaunchForce + ); + + TankController tankController = new TankController(tankModel,tankView); } } + + public ShellSpawner getShellSpawner() + { + return shellSpawner; + } } diff --git a/Assets/Scripts/Tank/TankView.cs b/Assets/Scripts/Tank/TankView.cs index 2b6d2ba..fc48d4d 100644 --- a/Assets/Scripts/Tank/TankView.cs +++ b/Assets/Scripts/Tank/TankView.cs @@ -1,6 +1,7 @@ using System; using UnityEngine; using UnityEngine.UI; +using static ShellSpawner; public class TankView : MonoBehaviour { @@ -15,8 +16,8 @@ public class TankView : MonoBehaviour [SerializeField] private Transform fireTransform; [SerializeField] private Slider aimSlider; - [SerializeField] public Rigidbody shell; - + [SerializeField] private Rigidbody shell; + [SerializeField] private ShellSpawner shellSpawner; private void Start() { @@ -63,13 +64,20 @@ public void ChangeColor(Material color) public void Fire() { + Debug.Log("Shell Spawned"); tankController.GetTankModel().setFiredState(true); - - Rigidbody shellInstance = Instantiate(shell, fireTransform.position, fireTransform.rotation) as Rigidbody; StartCoroutine(cameraShake.Shake(0.1f, 0.1f)); - shellInstance.velocity = tankController.GetTankModel().getCurrentLaunchForce() * fireTransform.forward; + //Rigidbody shellInstance = Instantiate(shell, fireTransform.position, fireTransform.rotation) as Rigidbody; + Vector3 velocity = tankController.GetTankModel().getCurrentLaunchForce() * fireTransform.transform.forward; + shellSpawner.SpawnShell(ShellTypes.REDTANKSHELL,velocity,shellSpawner.transform); } + public void setShellSpawner(ShellSpawner spawner) + { + + shellSpawner = spawner; + } + public Rigidbody getRigidbody() { return rb;