diff --git a/.idea/.idea.ProjetAMJV_CR/.idea/.gitignore b/.idea/.idea.ProjetAMJV_CR/.idea/.gitignore new file mode 100644 index 0000000..8f2e99a --- /dev/null +++ b/.idea/.idea.ProjetAMJV_CR/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/.idea.ProjetAMJV_CR.iml +/contentModel.xml +/projectSettingsUpdater.xml +/modules.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.idea.ProjetAMJV_CR/.idea/encodings.xml b/.idea/.idea.ProjetAMJV_CR/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/.idea/.idea.ProjetAMJV_CR/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.ProjetAMJV_CR/.idea/indexLayout.xml b/.idea/.idea.ProjetAMJV_CR/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/.idea/.idea.ProjetAMJV_CR/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.ProjetAMJV_CR/.idea/vcs.xml b/.idea/.idea.ProjetAMJV_CR/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/.idea.ProjetAMJV_CR/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file 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..02daaa3 --- /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": "ProjetAMJV_CR.sln" +} \ No newline at end of file diff --git a/Assets/Scripts.meta b/Assets/Scripts.meta new file mode 100644 index 0000000..89addd9 --- /dev/null +++ b/Assets/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e5378d644a3d2139389083d95ed259ce +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/AttackHandler.cs b/Assets/Scripts/AttackHandler.cs new file mode 100644 index 0000000..28f9ccd --- /dev/null +++ b/Assets/Scripts/AttackHandler.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +public class AttackHandler : MonoBehaviour +{ + [SerializeField] private float damage; + [SerializeField] private float cooldown; + [SerializeField] private Collider attackShape; + + private float _timer; + + void Start() + { + _timer = cooldown; + } + + void Update() + { + _timer = Mathf.Max(_timer - Time.deltaTime, 0f); + } + + public bool Attack() + { + if (_timer >= 0) return false; + Collider[] targets = DetectTargets(); + foreach (Collider target in targets) + { + if (!target.CompareTag("Unit")) continue; + // GetComponent is expensive in performance, optimize here if it's slow + Unit unit = target.GetComponent(); + unit.healthHandler.TakeDamage(damage); + + } + return true; + } + + private Collider[] DetectTargets() + { + // Make sure to manager layers for better performance + + List targets = new List(); + Collider[] hitColliders; + + switch (attackShape) + { + case SphereCollider sphere: + hitColliders = Physics.OverlapSphere(sphere.transform.position, sphere.radius, sphere.includeLayers); + break; + case BoxCollider box: + hitColliders = Physics.OverlapBox(box.bounds.center, box.bounds.extents, box.transform.rotation, box.includeLayers); + break; + default: + throw new ArgumentException("Only sphere or box are supported"); + } + + return hitColliders; + + } + + +} diff --git a/Assets/Scripts/AttackHandler.cs.meta b/Assets/Scripts/AttackHandler.cs.meta new file mode 100644 index 0000000..0289a98 --- /dev/null +++ b/Assets/Scripts/AttackHandler.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: eb03fb8c097f016f09d345ce200c3f41 \ No newline at end of file diff --git a/Assets/Scripts/HealthHandler.cs b/Assets/Scripts/HealthHandler.cs new file mode 100644 index 0000000..7e69ab6 --- /dev/null +++ b/Assets/Scripts/HealthHandler.cs @@ -0,0 +1,38 @@ +using UnityEngine; + +public class HealthHandler : MonoBehaviour +{ + [SerializeField] private float maxHealth; + [SerializeField] private float currentHealth; + [SerializeField] private float armor; + + public void TakeDamage(float damage) + { + Debug.Assert(damage >= 0, "Damage cannot be negative, use Heal if you want to heal"); + currentHealth -= Mathf.Max(0, damage-armor); + } + + public void Heal(float value) + { + Debug.Assert(value >= 0, "value can't be less than zero"); + currentHealth = Mathf.Min(currentHealth + value, maxHealth); + } + + public float GetArmor() + { + return armor; + } + + public void EquipArmor(float armorBoost) + { + Debug.Assert(armorBoost >= 0, "armorBoost can't be less than zero, use UnEquipArmor instead"); + armor += armorBoost; + } + + public void UnEquipArmor(float armorBoost) + { + Debug.Assert(armorBoost >= 0, "armorBoost can't be less than zero, use EquipArmor instead"); + armor -= armorBoost; + } + +} diff --git a/Assets/Scripts/HealthHandler.cs.meta b/Assets/Scripts/HealthHandler.cs.meta new file mode 100644 index 0000000..e0fc4d3 --- /dev/null +++ b/Assets/Scripts/HealthHandler.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 8511709ac7cfc1d05bee202fa8b8b095 \ No newline at end of file diff --git a/Assets/Scripts/Unit.cs b/Assets/Scripts/Unit.cs new file mode 100644 index 0000000..575672c --- /dev/null +++ b/Assets/Scripts/Unit.cs @@ -0,0 +1,20 @@ +using Unity.VisualScripting; +using UnityEngine; + + +public class Unit : MonoBehaviour +{ + [SerializeField] public HealthHandler healthHandler; + [SerializeField] public AttackHandler attackHandler; + + + void Start() + { + // Null safety enjoyers things + Debug.Assert(healthHandler != null); + Debug.Assert(attackHandler != null); + + } + + +} diff --git a/Assets/Scripts/Unit.cs.meta b/Assets/Scripts/Unit.cs.meta new file mode 100644 index 0000000..0c81cd4 --- /dev/null +++ b/Assets/Scripts/Unit.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 9815bed5dc151c8c6a271899ed1b7c4f \ No newline at end of file diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index 1c92a78..08f9444 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -2,8 +2,9 @@ %TAG !u! tag:unity3d.com,2011: --- !u!78 &1 TagManager: - serializedVersion: 2 - tags: [] + serializedVersion: 3 + tags: + - Unit layers: - Default - TransparentFX @@ -41,3 +42,5 @@ TagManager: - name: Default uniqueID: 0 locked: 0 + m_RenderingLayers: + - Default