diff --git a/Assets/Darkmatter/Code/App/Installers/GameLifetimeScope.cs b/Assets/Darkmatter/Code/App/Installers/GameLifetimeScope.cs index 409ca58..f142651 100644 --- a/Assets/Darkmatter/Code/App/Installers/GameLifetimeScope.cs +++ b/Assets/Darkmatter/Code/App/Installers/GameLifetimeScope.cs @@ -15,6 +15,7 @@ namespace Darkmatter.App [SerializeField] private PlayerAnimController playerAnim; [SerializeField] private PlayerConfigSO playerConfig; [SerializeField] private CameraConfigSO cameraConfig; + [SerializeField] private GunWeapon gunWeapon; protected override void Configure(IContainerBuilder builder) { builder.RegisterEntryPoint(Lifetime.Scoped); @@ -26,6 +27,7 @@ namespace Darkmatter.App builder.RegisterComponent(playerConfig); builder.RegisterComponent(cameraConfig); + builder.RegisterComponent(gunWeapon); builder.Register(Lifetime.Scoped); builder.RegisterComponentInHierarchy().As(); } diff --git a/Assets/Darkmatter/Code/Core/Contracts/Others/IWeapon.cs b/Assets/Darkmatter/Code/Core/Contracts/Others/IWeapon.cs new file mode 100644 index 0000000..668ba06 --- /dev/null +++ b/Assets/Darkmatter/Code/Core/Contracts/Others/IWeapon.cs @@ -0,0 +1,13 @@ +using UnityEngine; + +namespace Darkmatter.Core +{ + public interface IWeapon + { + public void Attack(); + public void Reload(); + bool canAttack { get; } + string WeaponName { get; } + + } +} diff --git a/Assets/Darkmatter/Code/Core/Contracts/Others/IWeapon.cs.meta b/Assets/Darkmatter/Code/Core/Contracts/Others/IWeapon.cs.meta new file mode 100644 index 0000000..e936199 --- /dev/null +++ b/Assets/Darkmatter/Code/Core/Contracts/Others/IWeapon.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 9f82b92b1e5608845a9706ad20b155f8 \ No newline at end of file diff --git a/Assets/Darkmatter/Code/Core/Contracts/Player/IAimProvider.cs b/Assets/Darkmatter/Code/Core/Contracts/Player/IAimProvider.cs new file mode 100644 index 0000000..8fdf237 --- /dev/null +++ b/Assets/Darkmatter/Code/Core/Contracts/Player/IAimProvider.cs @@ -0,0 +1,9 @@ +using UnityEngine; + +namespace Darkmatter.Core +{ + public interface IAimProvider + { + public Vector3 AimDir { get; set; } + } +} diff --git a/Assets/Darkmatter/Code/Core/Contracts/Player/IAimProvider.cs.meta b/Assets/Darkmatter/Code/Core/Contracts/Player/IAimProvider.cs.meta new file mode 100644 index 0000000..7d679b5 --- /dev/null +++ b/Assets/Darkmatter/Code/Core/Contracts/Player/IAimProvider.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: ebad764a0da2b7b4d8273baf63dd5500 \ No newline at end of file diff --git a/Assets/Darkmatter/Code/Domain/Weapon.meta b/Assets/Darkmatter/Code/Domain/Weapon.meta new file mode 100644 index 0000000..d50a732 --- /dev/null +++ b/Assets/Darkmatter/Code/Domain/Weapon.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 156c6779124556c48b177104c19c29f9 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Darkmatter/Code/Domain/Weapon/WeaponBase.cs b/Assets/Darkmatter/Code/Domain/Weapon/WeaponBase.cs new file mode 100644 index 0000000..f4ed344 --- /dev/null +++ b/Assets/Darkmatter/Code/Domain/Weapon/WeaponBase.cs @@ -0,0 +1,19 @@ +using Darkmatter.Core; +using UnityEngine; + +namespace Darkmatter.Domain +{ + public abstract class WeaponBase : MonoBehaviour, IWeapon + { + public abstract bool canAttack { get; } + + public abstract string WeaponName {get; } + + public abstract void Attack(); + + public virtual void Reload() + { + Debug.Log("Reloading"); + } + } +} diff --git a/Assets/Darkmatter/Code/Domain/Weapon/WeaponBase.cs.meta b/Assets/Darkmatter/Code/Domain/Weapon/WeaponBase.cs.meta new file mode 100644 index 0000000..6e80523 --- /dev/null +++ b/Assets/Darkmatter/Code/Domain/Weapon/WeaponBase.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 87a4d2aa64c2bc1468b8e548d66764e1 \ No newline at end of file diff --git a/Assets/Darkmatter/Code/Presentation/Player/PlayerMotor.cs b/Assets/Darkmatter/Code/Presentation/Player/PlayerMotor.cs index 6bcfeee..4746de4 100644 --- a/Assets/Darkmatter/Code/Presentation/Player/PlayerMotor.cs +++ b/Assets/Darkmatter/Code/Presentation/Player/PlayerMotor.cs @@ -8,7 +8,7 @@ using VContainer; namespace Darkmatter.Presentation { - public class PlayerMotor : MonoBehaviour, IPlayerPawn + public class PlayerMotor : MonoBehaviour, IPlayerPawn, IAimProvider { public TwoBoneIKConstraint IKConstraint; [Header("LookSetting")] @@ -22,6 +22,8 @@ namespace Darkmatter.Presentation private float verticalVelocity; public bool isGrounded => IsOnGround(); + public Vector3 AimDir { get; set; } + [Header("GroundCheckSensorSetting")] public float groundOffset; public float groundCheckRadius; @@ -47,6 +49,7 @@ namespace Darkmatter.Presentation [Inject] private IInputReader inputReader; [Inject] private PlayerConfigSO playerConfig; + [Inject] private IWeapon gunWeapon; @@ -60,7 +63,7 @@ namespace Darkmatter.Presentation private void Update() { HandleAim(); - HandleShooting(); + HandleShooting(); } private void LateUpdate() @@ -77,34 +80,35 @@ namespace Darkmatter.Presentation //animator.SetBool("IsShooting", inputReader.isShooting); if (!inputReader.isShooting) return; - if(Time.time>=nextFiretime && bulletAmount > 0) - { - bulletAmount--; - nextFiretime = Time.time + fireRate; - Vector2 screenPoint = new Vector2(Screen.width / 2, Screen.height / 2); - Ray ray = mainCamera.ScreenPointToRay(screenPoint); - RaycastHit hit; - Physics.Raycast(ray, out hit, 100f); + //if(Time.time>=nextFiretime && bulletAmount > 0) + //{ + // bulletAmount--; + // nextFiretime = Time.time + fireRate; + // Vector2 screenPoint = new Vector2(Screen.width / 2, Screen.height / 2); + // Ray ray = mainCamera.ScreenPointToRay(screenPoint); + // RaycastHit hit; + // Physics.Raycast(ray, out hit, 100f); - if(hit.collider.GetComponent() != null) - { - hit.collider.GetComponent().TakeDamage(10f); - } + // if(hit.collider.GetComponent() != null) + // { + // hit.collider.GetComponent().TakeDamage(10f); + // } - Vector3 spawnPos = hit.point + hit.normal * 0.01f; - GameObject bulletHit = Instantiate(BulletHole, spawnPos, Quaternion.LookRotation(hit.normal)); + // Vector3 spawnPos = hit.point + hit.normal * 0.01f; + // GameObject bulletHit = Instantiate(BulletHole, spawnPos, Quaternion.LookRotation(hit.normal)); - bulletHitParticle.transform.position = spawnPos; - bulletHitParticle.transform.rotation = Quaternion.LookRotation(hit.normal); - bulletHitParticle.Play(true); - Destroy(bulletHit,5f); - muzzleFlashParticle.Play(true); + // bulletHitParticle.transform.position = spawnPos; + // bulletHitParticle.transform.rotation = Quaternion.LookRotation(hit.normal); + // bulletHitParticle.Play(true); + // Destroy(bulletHit,5f); + // muzzleFlashParticle.Play(true); - if(bulletAmount==0) - { - StartCoroutine(Reload()); - } - } + // if(bulletAmount==0) + // { + // StartCoroutine(Reload()); + // } + //} + gunWeapon.Attack(); } IEnumerator Reload() @@ -130,6 +134,7 @@ namespace Darkmatter.Presentation } Vector3 aimDir = (mouseWorldPos - transform.position).normalized; + AimDir = aimDir; aimDir.y = 0; // Quaternion targetRot = Quaternion.LookRotation(aimDir); transform.rotation = Quaternion.Slerp(transform.rotation, targetRot, Time.deltaTime * turnSpeed); diff --git a/Assets/Darkmatter/Code/Presentation/Weapons.meta b/Assets/Darkmatter/Code/Presentation/Weapons.meta new file mode 100644 index 0000000..25c6587 --- /dev/null +++ b/Assets/Darkmatter/Code/Presentation/Weapons.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8bb38fc0897142643b14cbd6f6c2d9bb +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Darkmatter/Code/Presentation/Weapons/GunWeapon.cs b/Assets/Darkmatter/Code/Presentation/Weapons/GunWeapon.cs new file mode 100644 index 0000000..130a206 --- /dev/null +++ b/Assets/Darkmatter/Code/Presentation/Weapons/GunWeapon.cs @@ -0,0 +1,54 @@ +using Darkmatter.Core; +using Darkmatter.Domain; +using UnityEngine; +using VContainer; + +namespace Darkmatter.Presentation +{ + public class GunWeapon : WeaponBase + { + [Header("VFX")] + public ParticleSystem MuzzleFlashParticle; + public ParticleSystem BulletHitEffectParticle; + + [Header("Weapon Data")] + public float fireRate = 1f; + public int ammoCount = 40; + private float lastUsedTime; + public override string WeaponName => "Rifel"; + + + public override bool canAttack => Time.time >= lastUsedTime + fireRate; + + [Inject] private IAimProvider aimProvider; + + + + public override void Attack() + { + lastUsedTime = Time.time; + ammoCount--; + PlayMuzzleFlash(); + + Vector3 startPos = transform.position; + Vector3 direction = aimProvider.AimDir; + + Debug.Log("Attack using Gun"); + + //use ray cast here + + + //after ray cast use damage logic too + } + public override void Reload() + { + base.Reload(); + ammoCount = 40; + } + + private void PlayMuzzleFlash() + { + MuzzleFlashParticle.Play(true); + } + } +} diff --git a/Assets/Darkmatter/Code/Presentation/Weapons/GunWeapon.cs.meta b/Assets/Darkmatter/Code/Presentation/Weapons/GunWeapon.cs.meta new file mode 100644 index 0000000..d697479 --- /dev/null +++ b/Assets/Darkmatter/Code/Presentation/Weapons/GunWeapon.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: bf22e36737a853040b18d29e45fa59ee \ No newline at end of file diff --git a/Assets/Scenes/GameScene.unity b/Assets/Scenes/GameScene.unity index 2c5c7d0..6e750c8 100644 --- a/Assets/Scenes/GameScene.unity +++ b/Assets/Scenes/GameScene.unity @@ -36154,6 +36154,7 @@ MonoBehaviour: playerAnim: {fileID: 5149987667482231426} playerConfig: {fileID: 11400000, guid: 893990031b7e34e48aec7db96883252f, type: 2} cameraConfig: {fileID: 11400000, guid: e862049a6864bb347903dec038b0ba28, type: 2} + gunWeapon: {fileID: 1291938116} --- !u!1 &968176019 GameObject: m_ObjectHideFlags: 0 @@ -41265,6 +41266,56 @@ Transform: - {fileID: 4091028196503775626} m_Father: {fileID: 1177356139994482873} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1291938114 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1291938115} + - component: {fileID: 1291938116} + m_Layer: 0 + m_Name: Gun + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1291938115 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1291938114} + 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: + - {fileID: 7947649588152924016} + - {fileID: 2862136830057316804} + m_Father: {fileID: 1177356139994482873} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1291938116 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1291938114} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: bf22e36737a853040b18d29e45fa59ee, type: 3} + m_Name: + m_EditorClassIdentifier: PresentationAssembly::Darkmatter.Presentation.GunWeapon + MuzzleFlashParticle: {fileID: 7825428930137112052} + BulletHitEffectParticle: {fileID: 370982010} + fireRate: 1 + ammoCount: 40 --- !u!1 &1316836208 GameObject: m_ObjectHideFlags: 0 @@ -57909,8 +57960,7 @@ Transform: m_Children: - {fileID: 3041648529585021056} - {fileID: 1269999721} - - {fileID: 7947649588152924016} - - {fileID: 2862136830057316804} + - {fileID: 1291938115} m_Father: {fileID: 7787047617832541211} m_LocalEulerAnglesHint: {x: 94.70502, y: -133.13, z: -90.554016} --- !u!1 &1480250442922314562 @@ -58126,12 +58176,12 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8611435887466887428} serializedVersion: 2 - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -1.014, y: 0.021, z: 0.131} + m_LocalRotation: {x: 0.000000089406946, y: 0.000000014901158, z: 0.00000005960463, w: 1} + m_LocalPosition: {x: -1.0140004, y: 0.021000026, z: 0.13100015} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] - m_Father: {fileID: 1177356139994482873} + m_Father: {fileID: 1291938115} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &2890387892273649483 GameObject: @@ -98085,9 +98135,9 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7953213095344998490} serializedVersion: 2 - m_LocalRotation: {x: 0, y: 0, z: 1, w: 0} - m_LocalPosition: {x: -1.014, y: 0.021, z: 0.131} - m_LocalScale: {x: 0.5, y: 0.5, z: 0.5} + m_LocalRotation: {x: 0.00000004470348, y: -0.0000000074505797, z: 1, w: -0.000000104308114} + m_LocalPosition: {x: -1.0140004, y: 0.021000026, z: 0.13100015} + m_LocalScale: {x: 0.5, y: 0.49999997, z: 0.49999997} m_ConstrainProportionsScale: 0 m_Children: - {fileID: 7947529462498084646} @@ -98097,7 +98147,7 @@ Transform: - {fileID: 7950223671339331804} - {fileID: 7950401701011229452} - {fileID: 7950085431087205450} - m_Father: {fileID: 1177356139994482873} + m_Father: {fileID: 1291938115} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 180} --- !u!4 &7950085431087205450 Transform: