separated weapon class left to separate logic and implementation
This commit is contained in:
@@ -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<PlayerController>(Lifetime.Scoped);
|
||||
@@ -26,6 +27,7 @@ namespace Darkmatter.App
|
||||
|
||||
builder.RegisterComponent(playerConfig);
|
||||
builder.RegisterComponent(cameraConfig);
|
||||
builder.RegisterComponent<IWeapon>(gunWeapon);
|
||||
builder.Register<PlayerStateMachine>(Lifetime.Scoped);
|
||||
builder.RegisterComponentInHierarchy<CameraService>().As<ICameraService>();
|
||||
}
|
||||
|
||||
13
Assets/Darkmatter/Code/Core/Contracts/Others/IWeapon.cs
Normal file
13
Assets/Darkmatter/Code/Core/Contracts/Others/IWeapon.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Darkmatter.Core
|
||||
{
|
||||
public interface IWeapon
|
||||
{
|
||||
public void Attack();
|
||||
public void Reload();
|
||||
bool canAttack { get; }
|
||||
string WeaponName { get; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f82b92b1e5608845a9706ad20b155f8
|
||||
@@ -0,0 +1,9 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Darkmatter.Core
|
||||
{
|
||||
public interface IAimProvider
|
||||
{
|
||||
public Vector3 AimDir { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ebad764a0da2b7b4d8273baf63dd5500
|
||||
8
Assets/Darkmatter/Code/Domain/Weapon.meta
Normal file
8
Assets/Darkmatter/Code/Domain/Weapon.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 156c6779124556c48b177104c19c29f9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
Assets/Darkmatter/Code/Domain/Weapon/WeaponBase.cs
Normal file
19
Assets/Darkmatter/Code/Domain/Weapon/WeaponBase.cs
Normal file
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Darkmatter/Code/Domain/Weapon/WeaponBase.cs.meta
Normal file
2
Assets/Darkmatter/Code/Domain/Weapon/WeaponBase.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 87a4d2aa64c2bc1468b8e548d66764e1
|
||||
@@ -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<IDamageable>() != null)
|
||||
{
|
||||
hit.collider.GetComponent<IDamageable>().TakeDamage(10f);
|
||||
}
|
||||
// if(hit.collider.GetComponent<IDamageable>() != null)
|
||||
// {
|
||||
// hit.collider.GetComponent<IDamageable>().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);
|
||||
|
||||
8
Assets/Darkmatter/Code/Presentation/Weapons.meta
Normal file
8
Assets/Darkmatter/Code/Presentation/Weapons.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8bb38fc0897142643b14cbd6f6c2d9bb
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
54
Assets/Darkmatter/Code/Presentation/Weapons/GunWeapon.cs
Normal file
54
Assets/Darkmatter/Code/Presentation/Weapons/GunWeapon.cs
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf22e36737a853040b18d29e45fa59ee
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user