separated logic for weapon code refactored
This commit is contained in:
@@ -1,8 +1,4 @@
|
|||||||
<!-- UNITY CODE ASSIST INSTRUCTIONS START -->
|
<!-- UNITY CODE ASSIST INSTRUCTIONS START -->
|
||||||
- Project name: MobileShooter
|
- Project name: MobileShooter
|
||||||
- Unity version: Unity 6000.3.0f1
|
- Unity version: Unity 6000.3.0f1
|
||||||
- Active game object:
|
|
||||||
- Name: Third Person ADS Camera
|
|
||||||
- Tag: Untagged
|
|
||||||
- Layer: Default
|
|
||||||
<!-- UNITY CODE ASSIST INSTRUCTIONS END -->
|
<!-- UNITY CODE ASSIST INSTRUCTIONS END -->
|
||||||
@@ -16,6 +16,7 @@ namespace Darkmatter.App
|
|||||||
[SerializeField] private PlayerConfigSO playerConfig;
|
[SerializeField] private PlayerConfigSO playerConfig;
|
||||||
[SerializeField] private CameraConfigSO cameraConfig;
|
[SerializeField] private CameraConfigSO cameraConfig;
|
||||||
[SerializeField] private GunWeapon gunWeapon;
|
[SerializeField] private GunWeapon gunWeapon;
|
||||||
|
[SerializeField] private TargetProvider TargetProvider;
|
||||||
protected override void Configure(IContainerBuilder builder)
|
protected override void Configure(IContainerBuilder builder)
|
||||||
{
|
{
|
||||||
builder.RegisterEntryPoint<PlayerController>(Lifetime.Scoped);
|
builder.RegisterEntryPoint<PlayerController>(Lifetime.Scoped);
|
||||||
@@ -24,7 +25,7 @@ namespace Darkmatter.App
|
|||||||
builder.RegisterComponent<IPlayerAnim>(playerAnim);
|
builder.RegisterComponent<IPlayerAnim>(playerAnim);
|
||||||
builder.RegisterComponent<IInputReader>(inputReader);
|
builder.RegisterComponent<IInputReader>(inputReader);
|
||||||
builder.RegisterComponent<IPlayerPawn>(playerMotor);
|
builder.RegisterComponent<IPlayerPawn>(playerMotor);
|
||||||
|
builder.RegisterComponent<ITargetProvider>(TargetProvider);
|
||||||
builder.RegisterComponent(playerConfig);
|
builder.RegisterComponent(playerConfig);
|
||||||
builder.RegisterComponent(cameraConfig);
|
builder.RegisterComponent(cameraConfig);
|
||||||
builder.RegisterComponent<IWeapon>(gunWeapon);
|
builder.RegisterComponent<IWeapon>(gunWeapon);
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace Darkmatter.Core
|
|
||||||
{
|
|
||||||
public interface IAimProvider
|
|
||||||
{
|
|
||||||
public Vector3 AimDir { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,6 @@ namespace Darkmatter.Core
|
|||||||
{
|
{
|
||||||
public interface IPlayerPawn
|
public interface IPlayerPawn
|
||||||
{
|
{
|
||||||
Camera mainCamera { get; }
|
|
||||||
bool isGrounded { get; }
|
bool isGrounded { get; }
|
||||||
|
|
||||||
void Jump(float jumpForce);
|
void Jump(float jumpForce);
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Darkmatter.Core
|
||||||
|
{
|
||||||
|
public interface ITargetProvider
|
||||||
|
{
|
||||||
|
public RaycastHit hitPoint { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,6 @@ namespace Darkmatter.Core
|
|||||||
{
|
{
|
||||||
public interface ICameraService
|
public interface ICameraService
|
||||||
{
|
{
|
||||||
|
Camera mainCamera { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Darkmatter.Core;
|
using Darkmatter.Core;
|
||||||
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Darkmatter.Domain
|
namespace Darkmatter.Domain
|
||||||
@@ -17,9 +18,15 @@ namespace Darkmatter.Domain
|
|||||||
public override void Update()
|
public override void Update()
|
||||||
{
|
{
|
||||||
HandlePlayerMovement();
|
HandlePlayerMovement();
|
||||||
|
HandleShoooting();
|
||||||
CheckForStateBreak();
|
CheckForStateBreak();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void HandleShoooting()
|
||||||
|
{
|
||||||
|
runner.Shoot(inputReader.isShooting);
|
||||||
|
}
|
||||||
|
|
||||||
public override void LateUpdate()
|
public override void LateUpdate()
|
||||||
{
|
{
|
||||||
HandlePlayerRotation();
|
HandlePlayerRotation();
|
||||||
@@ -44,7 +51,7 @@ namespace Darkmatter.Domain
|
|||||||
|
|
||||||
private void CheckForStateBreak()
|
private void CheckForStateBreak()
|
||||||
{
|
{
|
||||||
if (runner.playerController.isGrounded)
|
if (runner.playerPawn.isGrounded)
|
||||||
{
|
{
|
||||||
runner.ChangeState(new LocomotionState(runner));
|
runner.ChangeState(new LocomotionState(runner));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,10 +19,16 @@ namespace Darkmatter.Domain
|
|||||||
public override void Update()
|
public override void Update()
|
||||||
{
|
{
|
||||||
HandlePlayerMovement();
|
HandlePlayerMovement();
|
||||||
|
HandleShooting();
|
||||||
CheckForStateBreak();
|
CheckForStateBreak();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void HandleShooting()
|
||||||
|
{
|
||||||
|
runner.Shoot(inputReader.isShooting);
|
||||||
|
}
|
||||||
|
|
||||||
public override void LateUpdate()
|
public override void LateUpdate()
|
||||||
{
|
{
|
||||||
HandlePlayerRotation();
|
HandlePlayerRotation();
|
||||||
@@ -39,7 +45,7 @@ namespace Darkmatter.Domain
|
|||||||
|
|
||||||
private void CheckForStateBreak()
|
private void CheckForStateBreak()
|
||||||
{
|
{
|
||||||
if (!runner.playerController.isGrounded)
|
if (!runner.playerPawn.isGrounded)
|
||||||
{
|
{
|
||||||
runner.ChangeState(new AirboneState(runner));
|
runner.ChangeState(new AirboneState(runner));
|
||||||
}
|
}
|
||||||
@@ -57,7 +63,7 @@ namespace Darkmatter.Domain
|
|||||||
|
|
||||||
private void HandlePlayerJump()
|
private void HandlePlayerJump()
|
||||||
{
|
{
|
||||||
runner.playerController.Jump(playerConfig.jumpForce);
|
runner.playerPawn.Jump(playerConfig.jumpForce);
|
||||||
playerAnim.PlayJumpAnim();
|
playerAnim.PlayJumpAnim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,12 @@ namespace Darkmatter.Domain
|
|||||||
{
|
{
|
||||||
public class PlayerStateMachine : StateMachine
|
public class PlayerStateMachine : StateMachine
|
||||||
{
|
{
|
||||||
[Inject] public readonly IPlayerPawn playerController;
|
[Inject] public readonly IPlayerPawn playerPawn;
|
||||||
[Inject] public readonly IInputReader inputReader;
|
[Inject] public readonly IInputReader inputReader;
|
||||||
[Inject] public readonly IPlayerAnim playerAnim;
|
[Inject] public readonly IPlayerAnim playerAnim;
|
||||||
|
[Inject] public readonly ITargetProvider targetProvider;
|
||||||
|
[Inject] public readonly ICameraService cameraService;
|
||||||
|
[Inject] public readonly IWeapon GunWeapon;
|
||||||
[Inject] public readonly PlayerConfigSO playerConfig;
|
[Inject] public readonly PlayerConfigSO playerConfig;
|
||||||
[Inject] public readonly CameraConfigSO cameraConfig;
|
[Inject] public readonly CameraConfigSO cameraConfig;
|
||||||
|
|
||||||
@@ -19,8 +22,8 @@ namespace Darkmatter.Domain
|
|||||||
public void Move(Vector2 moveInputDir, float moveSpeed)
|
public void Move(Vector2 moveInputDir, float moveSpeed)
|
||||||
{
|
{
|
||||||
//player movement with reference to camera
|
//player movement with reference to camera
|
||||||
Vector3 cameraForward = playerController.mainCamera.transform.forward;
|
Vector3 cameraForward =cameraService.mainCamera.transform.forward;
|
||||||
Vector3 cameraRight = playerController.mainCamera.transform.right;
|
Vector3 cameraRight = cameraService.mainCamera.transform.right;
|
||||||
|
|
||||||
cameraForward.y = 0f;
|
cameraForward.y = 0f;
|
||||||
cameraRight.y = 0f;
|
cameraRight.y = 0f;
|
||||||
@@ -30,7 +33,7 @@ namespace Darkmatter.Domain
|
|||||||
|
|
||||||
moveDir = cameraRight * moveInputDir.x + cameraForward * moveInputDir.y;
|
moveDir = cameraRight * moveInputDir.x + cameraForward * moveInputDir.y;
|
||||||
|
|
||||||
playerController.Move(moveDir * moveSpeed);
|
playerPawn.Move(moveDir * moveSpeed);
|
||||||
playerAnim.PlayMovementAnim(moveInputDir);
|
playerAnim.PlayMovementAnim(moveInputDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +46,17 @@ namespace Darkmatter.Domain
|
|||||||
pitch -= lookInput.y * cameraConfig.lookSensitivity * Time.deltaTime;
|
pitch -= lookInput.y * cameraConfig.lookSensitivity * Time.deltaTime;
|
||||||
}
|
}
|
||||||
pitch = Mathf.Clamp(pitch, cameraConfig.bottomClampAngle, cameraConfig.topClampAngle);
|
pitch = Mathf.Clamp(pitch, cameraConfig.bottomClampAngle, cameraConfig.topClampAngle);
|
||||||
playerController.SetCameraRotation(pitch, Yaw);
|
playerPawn.SetCameraRotation(pitch, Yaw);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Shoot(bool isShooting)
|
||||||
|
{
|
||||||
|
if (!isShooting) return;
|
||||||
|
if(GunWeapon.canAttack)
|
||||||
|
{
|
||||||
|
GunWeapon.Attack();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,11 +8,13 @@ namespace Darkmatter.Presentation
|
|||||||
{
|
{
|
||||||
public class CameraService : MonoBehaviour, ICameraService
|
public class CameraService : MonoBehaviour, ICameraService
|
||||||
{
|
{
|
||||||
|
public Camera mainCamera { get; private set; }
|
||||||
public CinemachineThirdPersonFollow AdsCamera;
|
public CinemachineThirdPersonFollow AdsCamera;
|
||||||
[Inject] private IInputReader inputReader;
|
[Inject] private IInputReader inputReader;
|
||||||
public bool isAiming = false;
|
public bool isAiming = false;
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
|
mainCamera = Camera.main;
|
||||||
inputReader.OnAdsCameraSwitch += SwitchADSCamera;
|
inputReader.OnAdsCameraSwitch += SwitchADSCamera;
|
||||||
AdsCamera.gameObject.SetActive(false);
|
AdsCamera.gameObject.SetActive(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
using System;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace Darkmatter.Presentation
|
|
||||||
{
|
|
||||||
public class Gun : MonoBehaviour
|
|
||||||
{
|
|
||||||
public LineRenderer lineRenderer;
|
|
||||||
public float LifeTime = 0.05f;
|
|
||||||
|
|
||||||
public void Init(Vector3 start, Vector3 end)
|
|
||||||
{
|
|
||||||
lineRenderer.enabled = true;
|
|
||||||
lineRenderer.SetPosition(0, start);
|
|
||||||
lineRenderer.SetPosition(1, end);
|
|
||||||
Invoke("DisableBullet", LifeTime);
|
|
||||||
}
|
|
||||||
void DisableBullet()
|
|
||||||
{
|
|
||||||
lineRenderer.enabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void Shoot()
|
|
||||||
{
|
|
||||||
Debug.Log("Shooting");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: c3f99ff473a5f474099e6dd5f8dcde78
|
|
||||||
@@ -8,11 +8,11 @@ using VContainer;
|
|||||||
|
|
||||||
namespace Darkmatter.Presentation
|
namespace Darkmatter.Presentation
|
||||||
{
|
{
|
||||||
public class PlayerMotor : MonoBehaviour, IPlayerPawn, IAimProvider
|
public class PlayerMotor : MonoBehaviour, IPlayerPawn
|
||||||
{
|
{
|
||||||
public TwoBoneIKConstraint IKConstraint;
|
public TwoBoneIKConstraint IKConstraint;
|
||||||
|
|
||||||
[Header("LookSetting")]
|
[Header("LookSetting")]
|
||||||
public Camera mainCamera { get; private set; }
|
|
||||||
public Transform cinemachineFollowTarget;
|
public Transform cinemachineFollowTarget;
|
||||||
|
|
||||||
[Header("MoveSetting")]
|
[Header("MoveSetting")]
|
||||||
@@ -22,8 +22,6 @@ namespace Darkmatter.Presentation
|
|||||||
private float verticalVelocity;
|
private float verticalVelocity;
|
||||||
public bool isGrounded => IsOnGround();
|
public bool isGrounded => IsOnGround();
|
||||||
|
|
||||||
public Vector3 AimDir { get; set; }
|
|
||||||
|
|
||||||
[Header("GroundCheckSensorSetting")]
|
[Header("GroundCheckSensorSetting")]
|
||||||
public float groundOffset;
|
public float groundOffset;
|
||||||
public float groundCheckRadius;
|
public float groundCheckRadius;
|
||||||
@@ -31,115 +29,13 @@ namespace Darkmatter.Presentation
|
|||||||
|
|
||||||
[Header("TurnSetting")]
|
[Header("TurnSetting")]
|
||||||
public float turnSpeed = 5f;
|
public float turnSpeed = 5f;
|
||||||
public float smoothing = 10f;
|
|
||||||
[Header("AnimationSetting")]
|
|
||||||
public Animator animator;
|
|
||||||
|
|
||||||
[Header("AimSetting")]
|
|
||||||
public Transform aim;
|
|
||||||
Vector3 mouseWorldPos = Vector3.zero;
|
|
||||||
public Transform muzzlePos;
|
|
||||||
public float fireRate = 0.1f;
|
|
||||||
float nextFiretime=0;
|
|
||||||
|
|
||||||
public ParticleSystem muzzleFlashParticle;
|
|
||||||
public ParticleSystem bulletHitParticle;
|
|
||||||
public GameObject BulletHole;
|
|
||||||
|
|
||||||
|
|
||||||
[Inject] private IInputReader inputReader;
|
|
||||||
[Inject] private PlayerConfigSO playerConfig;
|
[Inject] private PlayerConfigSO playerConfig;
|
||||||
[Inject] private IWeapon gunWeapon;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
Cursor.lockState = CursorLockMode.Locked;
|
Cursor.lockState = CursorLockMode.Locked;
|
||||||
if(animator==null) animator = GetComponent<Animator>();
|
}
|
||||||
mainCamera = Camera.main;
|
|
||||||
|
|
||||||
}
|
|
||||||
private void Update()
|
|
||||||
{
|
|
||||||
HandleAim();
|
|
||||||
HandleShooting();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void LateUpdate()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
public int bulletAmount = 40;
|
|
||||||
private void HandleShooting()
|
|
||||||
{
|
|
||||||
//float shootingWeight = animator.GetLayerWeight(1);
|
|
||||||
//float targetWeight = inputReader.isShooting ? 1 : 0;
|
|
||||||
//float setshootingWeight = Mathf.Lerp(shootingWeight, targetWeight, Time.deltaTime * 5);
|
|
||||||
//animator.SetLayerWeight(1, setshootingWeight);
|
|
||||||
//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(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));
|
|
||||||
|
|
||||||
// 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());
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
gunWeapon.Attack();
|
|
||||||
}
|
|
||||||
|
|
||||||
IEnumerator Reload()
|
|
||||||
{
|
|
||||||
IKConstraint.weight = 0f;
|
|
||||||
animator.SetLayerWeight(1, 1);
|
|
||||||
animator.SetTrigger("Reload");
|
|
||||||
yield return new WaitForSeconds(3f);
|
|
||||||
bulletAmount =40;
|
|
||||||
animator.SetLayerWeight(1, 0);
|
|
||||||
IKConstraint.weight = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void HandleAim()
|
|
||||||
{
|
|
||||||
Vector2 screenPoint = new Vector2(Screen.width/2, Screen.height/2);
|
|
||||||
Ray ray = mainCamera.ScreenPointToRay(screenPoint);
|
|
||||||
if(Physics.Raycast(ray,out RaycastHit hitPoint, 100f,groundLayer))
|
|
||||||
{
|
|
||||||
mouseWorldPos= hitPoint.point;
|
|
||||||
//aim.position = mouseWorldPos;
|
|
||||||
aim.position = Vector3.Lerp(aim.position, hitPoint.point, Time.deltaTime * smoothing);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//state based functions
|
//state based functions
|
||||||
public void Move(Vector3 motion)
|
public void Move(Vector3 motion)
|
||||||
@@ -153,8 +49,7 @@ namespace Darkmatter.Presentation
|
|||||||
public void SetCameraRotation(float pitch, float yaw)
|
public void SetCameraRotation(float pitch, float yaw)
|
||||||
{
|
{
|
||||||
cinemachineFollowTarget.rotation = Quaternion.Euler(pitch, yaw, 0);
|
cinemachineFollowTarget.rotation = Quaternion.Euler(pitch, yaw, 0);
|
||||||
|
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0,yaw,0), Time.deltaTime*turnSpeed); //rotate player towards the camera forward axis
|
||||||
//transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0,yaw,0), Time.deltaTime*turnSpeed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Jump(float jumpForce)
|
public void Jump(float jumpForce)
|
||||||
|
|||||||
41
Assets/Darkmatter/Code/Presentation/Player/TargetProvider.cs
Normal file
41
Assets/Darkmatter/Code/Presentation/Player/TargetProvider.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
using Darkmatter.Core;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Darkmatter.Presentation
|
||||||
|
{
|
||||||
|
public class TargetProvider : MonoBehaviour, ITargetProvider
|
||||||
|
{
|
||||||
|
private Camera mainCamera;
|
||||||
|
[SerializeField] private LayerMask aimLayer;
|
||||||
|
|
||||||
|
private RaycastHit _hitPoint;
|
||||||
|
public RaycastHit hitPoint => _hitPoint;
|
||||||
|
|
||||||
|
public Vector3 currentAimPos;
|
||||||
|
public Transform AimObject; //for IK aim handling
|
||||||
|
public float smoothing = 10f;
|
||||||
|
public float maxDistance = 100f;
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
mainCamera = Camera.main;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
Vector2 screenPoint = new Vector2(Screen.width / 2, Screen.height / 2);
|
||||||
|
Ray ray = mainCamera.ScreenPointToRay(screenPoint);
|
||||||
|
if (Physics.Raycast(ray, out _hitPoint, maxDistance, aimLayer,queryTriggerInteraction:QueryTriggerInteraction.Ignore))
|
||||||
|
{
|
||||||
|
currentAimPos = Vector3.Lerp(currentAimPos, _hitPoint.point, Time.deltaTime * smoothing);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
currentAimPos = ray.GetPoint(maxDistance);
|
||||||
|
}
|
||||||
|
|
||||||
|
AimObject.position = currentAimPos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 315b8f05ac753ce4cb4b05beec2a6f9f
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using Darkmatter.Core;
|
using Darkmatter.Core;
|
||||||
using Darkmatter.Domain;
|
using Darkmatter.Domain;
|
||||||
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using VContainer;
|
using VContainer;
|
||||||
|
|
||||||
@@ -12,15 +13,17 @@ namespace Darkmatter.Presentation
|
|||||||
public ParticleSystem BulletHitEffectParticle;
|
public ParticleSystem BulletHitEffectParticle;
|
||||||
|
|
||||||
[Header("Weapon Data")]
|
[Header("Weapon Data")]
|
||||||
public float fireRate = 1f;
|
public float fireRate = 0.1f;
|
||||||
public int ammoCount = 40;
|
public int ammoCount = 40;
|
||||||
private float lastUsedTime;
|
private float lastUsedTime;
|
||||||
|
public GameObject BulletHole;
|
||||||
public override string WeaponName => "Rifel";
|
public override string WeaponName => "Rifel";
|
||||||
|
|
||||||
|
|
||||||
public override bool canAttack => Time.time >= lastUsedTime + fireRate;
|
public override bool canAttack => Time.time >= lastUsedTime + fireRate && ammoCount > 0;
|
||||||
|
|
||||||
[Inject] private IAimProvider aimProvider;
|
[Inject] private ITargetProvider targetProvider;
|
||||||
|
private RaycastHit hitPoint => targetProvider.hitPoint;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -28,18 +31,38 @@ namespace Darkmatter.Presentation
|
|||||||
{
|
{
|
||||||
lastUsedTime = Time.time;
|
lastUsedTime = Time.time;
|
||||||
ammoCount--;
|
ammoCount--;
|
||||||
|
|
||||||
PlayMuzzleFlash();
|
PlayMuzzleFlash();
|
||||||
|
if (hitPoint.transform != null) PlayBulletHitEffectParticle();
|
||||||
|
|
||||||
Vector3 startPos = transform.position;
|
if(ammoCount <= 0) //test reload
|
||||||
Vector3 direction = aimProvider.AimDir;
|
{
|
||||||
|
Reload();
|
||||||
Debug.Log("Attack using Gun");
|
}
|
||||||
|
|
||||||
//use ray cast here
|
|
||||||
|
|
||||||
|
|
||||||
//after ray cast use damage logic too
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ShowBulletHole(Vector3 spawnPos)
|
||||||
|
{
|
||||||
|
GameObject bulletHit = Instantiate(BulletHole, spawnPos, Quaternion.LookRotation(hitPoint.normal));
|
||||||
|
Destroy(bulletHit, 5f);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PlayBulletHitEffectParticle()
|
||||||
|
{
|
||||||
|
var damageable = hitPoint.transform.GetComponent<IDamageable>();
|
||||||
|
if (damageable != null)
|
||||||
|
{
|
||||||
|
damageable.TakeDamage(10f);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3 spawnPos = hitPoint.point + hitPoint.normal * 0.01f;
|
||||||
|
|
||||||
|
BulletHitEffectParticle.transform.position = spawnPos;
|
||||||
|
BulletHitEffectParticle.transform.rotation = Quaternion.LookRotation(hitPoint.normal);
|
||||||
|
|
||||||
|
BulletHitEffectParticle.Play(true);
|
||||||
|
}
|
||||||
|
|
||||||
public override void Reload()
|
public override void Reload()
|
||||||
{
|
{
|
||||||
base.Reload();
|
base.Reload();
|
||||||
|
|||||||
@@ -29865,7 +29865,7 @@ MonoBehaviour:
|
|||||||
m_EditorClassIdentifier: Unity.Cinemachine::Unity.Cinemachine.CinemachineThirdPersonAim
|
m_EditorClassIdentifier: Unity.Cinemachine::Unity.Cinemachine.CinemachineThirdPersonAim
|
||||||
AimCollisionFilter:
|
AimCollisionFilter:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Bits: 1
|
m_Bits: 4294967295
|
||||||
IgnoreTag:
|
IgnoreTag:
|
||||||
AimDistance: 200
|
AimDistance: 200
|
||||||
NoiseCancellation: 1
|
NoiseCancellation: 1
|
||||||
@@ -36155,6 +36155,7 @@ MonoBehaviour:
|
|||||||
playerConfig: {fileID: 11400000, guid: 893990031b7e34e48aec7db96883252f, type: 2}
|
playerConfig: {fileID: 11400000, guid: 893990031b7e34e48aec7db96883252f, type: 2}
|
||||||
cameraConfig: {fileID: 11400000, guid: e862049a6864bb347903dec038b0ba28, type: 2}
|
cameraConfig: {fileID: 11400000, guid: e862049a6864bb347903dec038b0ba28, type: 2}
|
||||||
gunWeapon: {fileID: 1291938116}
|
gunWeapon: {fileID: 1291938116}
|
||||||
|
TargetProvider: {fileID: 9174570246757384965}
|
||||||
--- !u!1 &968176019
|
--- !u!1 &968176019
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -41314,8 +41315,9 @@ MonoBehaviour:
|
|||||||
m_EditorClassIdentifier: PresentationAssembly::Darkmatter.Presentation.GunWeapon
|
m_EditorClassIdentifier: PresentationAssembly::Darkmatter.Presentation.GunWeapon
|
||||||
MuzzleFlashParticle: {fileID: 7825428930137112052}
|
MuzzleFlashParticle: {fileID: 7825428930137112052}
|
||||||
BulletHitEffectParticle: {fileID: 370982010}
|
BulletHitEffectParticle: {fileID: 370982010}
|
||||||
fireRate: 1
|
fireRate: 0.1
|
||||||
ammoCount: 40
|
ammoCount: 40
|
||||||
|
BulletHole: {fileID: 4555957734307141869, guid: 4de3748ba04e4fa41b656da3f8d23a5a, type: 3}
|
||||||
--- !u!1 &1316836208
|
--- !u!1 &1316836208
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -46374,7 +46376,7 @@ MonoBehaviour:
|
|||||||
m_EditorClassIdentifier: Unity.Cinemachine::Unity.Cinemachine.CinemachineThirdPersonAim
|
m_EditorClassIdentifier: Unity.Cinemachine::Unity.Cinemachine.CinemachineThirdPersonAim
|
||||||
AimCollisionFilter:
|
AimCollisionFilter:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Bits: 1
|
m_Bits: 4294967295
|
||||||
IgnoreTag:
|
IgnoreTag:
|
||||||
AimDistance: 200
|
AimDistance: 200
|
||||||
NoiseCancellation: 1
|
NoiseCancellation: 1
|
||||||
@@ -57690,9 +57692,10 @@ GameObject:
|
|||||||
- component: {fileID: 3649487752288184257}
|
- component: {fileID: 3649487752288184257}
|
||||||
- component: {fileID: 3317298528410109698}
|
- component: {fileID: 3317298528410109698}
|
||||||
- component: {fileID: 9174570246757384964}
|
- component: {fileID: 9174570246757384964}
|
||||||
|
- component: {fileID: 3102384702973419205}
|
||||||
- component: {fileID: 5149987667482231426}
|
- component: {fileID: 5149987667482231426}
|
||||||
- component: {fileID: 7539699777945653300}
|
- component: {fileID: 7539699777945653300}
|
||||||
- component: {fileID: 3102384702973419205}
|
- component: {fileID: 9174570246757384965}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: Player
|
m_Name: Player
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
@@ -59020,15 +59023,6 @@ MonoBehaviour:
|
|||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Bits: 8
|
m_Bits: 8
|
||||||
turnSpeed: 4
|
turnSpeed: 4
|
||||||
smoothing: 10
|
|
||||||
animator: {fileID: 3649487752288184257}
|
|
||||||
aim: {fileID: 1758691227}
|
|
||||||
muzzlePos: {fileID: 2862136830057316804}
|
|
||||||
fireRate: 0.1
|
|
||||||
muzzleFlashParticle: {fileID: 7825428930137112052}
|
|
||||||
bulletHitParticle: {fileID: 370982010}
|
|
||||||
BulletHole: {fileID: 4555957734307141869, guid: 4de3748ba04e4fa41b656da3f8d23a5a, type: 3}
|
|
||||||
bulletAmount: 40
|
|
||||||
--- !u!1 &7547960368595836929
|
--- !u!1 &7547960368595836929
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -98583,6 +98577,25 @@ CharacterController:
|
|||||||
m_SkinWidth: 0.08
|
m_SkinWidth: 0.08
|
||||||
m_MinMoveDistance: 0.001
|
m_MinMoveDistance: 0.001
|
||||||
m_Center: {x: 0, y: 1.4, z: 0}
|
m_Center: {x: 0, y: 1.4, z: 0}
|
||||||
|
--- !u!114 &9174570246757384965
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 682798877665067124}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 315b8f05ac753ce4cb4b05beec2a6f9f, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier: PresentationAssembly::Darkmatter.Presentation.PlayerTargetProvider
|
||||||
|
aimLayer:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 0
|
||||||
|
currentAimPos: {x: 0, y: 0, z: 0}
|
||||||
|
AimObject: {fileID: 1758691227}
|
||||||
|
smoothing: 10
|
||||||
|
maxDistance: 100
|
||||||
--- !u!1660057539 &9223372036854775807
|
--- !u!1660057539 &9223372036854775807
|
||||||
SceneRoots:
|
SceneRoots:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ TagManager:
|
|||||||
- Ground
|
- Ground
|
||||||
- Water
|
- Water
|
||||||
- UI
|
- UI
|
||||||
-
|
- Enemy
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
|
|||||||
Reference in New Issue
Block a user