added reload animation and bullet limit

This commit is contained in:
Mausham
2025-12-29 16:41:50 -08:00
parent 3e98a42d4e
commit 357a226e21
531 changed files with 299250 additions and 849 deletions

View File

@@ -5,7 +5,8 @@
"GUID:cf1df9e1968a94c4686f2fbe5ef907fc",
"GUID:23f9a018fbd2e1242a0525718cc761d6",
"GUID:00bcf444fe1ffd8468345b96caa37633",
"GUID:b0214a6008ed146ff8f122a6a9c2f6cc"
"GUID:b0214a6008ed146ff8f122a6a9c2f6cc",
"GUID:4307f53044263cf4b835bd812fc161a4"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@@ -9,6 +9,7 @@ namespace Darkmatter.App
{
public class GameLifetimeScope : LifetimeScope
{
[SerializeField] private InputReaderSO inputReader;
[SerializeField] private PlayerMotor playerMotor;
[SerializeField] private PlayerAnimController playerAnim;
@@ -26,6 +27,7 @@ namespace Darkmatter.App
builder.RegisterComponent(playerConfig);
builder.RegisterComponent(cameraConfig);
builder.Register<PlayerStateMachine>(Lifetime.Scoped);
builder.RegisterComponentInHierarchy<CameraService>().As<ICameraService>();
}
}
}

View File

@@ -127,6 +127,15 @@ public partial class @GameInputAction: IInputActionCollection2, IDisposable
""processors"": """",
""interactions"": """",
""initialStateCheck"": false
},
{
""name"": ""ADS Camera"",
""type"": ""Button"",
""id"": ""bc014086-71fa-432a-8e3c-3e2003c5244b"",
""expectedControlType"": """",
""processors"": """",
""interactions"": """",
""initialStateCheck"": false
}
],
""bindings"": [
@@ -217,6 +226,17 @@ public partial class @GameInputAction: IInputActionCollection2, IDisposable
""action"": ""Shoot"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""f5bad540-cf37-4957-ad4a-1e5a5e723890"",
""path"": ""<Mouse>/rightButton"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""ADS Camera"",
""isComposite"": false,
""isPartOfComposite"": false
}
]
}
@@ -229,6 +249,7 @@ public partial class @GameInputAction: IInputActionCollection2, IDisposable
m_Player_Look = m_Player.FindAction("Look", throwIfNotFound: true);
m_Player_Jump = m_Player.FindAction("Jump", throwIfNotFound: true);
m_Player_Shoot = m_Player.FindAction("Shoot", throwIfNotFound: true);
m_Player_ADSCamera = m_Player.FindAction("ADS Camera", throwIfNotFound: true);
}
~@GameInputAction()
@@ -313,6 +334,7 @@ public partial class @GameInputAction: IInputActionCollection2, IDisposable
private readonly InputAction m_Player_Look;
private readonly InputAction m_Player_Jump;
private readonly InputAction m_Player_Shoot;
private readonly InputAction m_Player_ADSCamera;
/// <summary>
/// Provides access to input actions defined in input action map "Player".
/// </summary>
@@ -341,6 +363,10 @@ public partial class @GameInputAction: IInputActionCollection2, IDisposable
/// </summary>
public InputAction @Shoot => m_Wrapper.m_Player_Shoot;
/// <summary>
/// Provides access to the underlying input action "Player/ADSCamera".
/// </summary>
public InputAction @ADSCamera => m_Wrapper.m_Player_ADSCamera;
/// <summary>
/// Provides access to the underlying input action map instance.
/// </summary>
public InputActionMap Get() { return m_Wrapper.m_Player; }
@@ -378,6 +404,9 @@ public partial class @GameInputAction: IInputActionCollection2, IDisposable
@Shoot.started += instance.OnShoot;
@Shoot.performed += instance.OnShoot;
@Shoot.canceled += instance.OnShoot;
@ADSCamera.started += instance.OnADSCamera;
@ADSCamera.performed += instance.OnADSCamera;
@ADSCamera.canceled += instance.OnADSCamera;
}
/// <summary>
@@ -401,6 +430,9 @@ public partial class @GameInputAction: IInputActionCollection2, IDisposable
@Shoot.started -= instance.OnShoot;
@Shoot.performed -= instance.OnShoot;
@Shoot.canceled -= instance.OnShoot;
@ADSCamera.started -= instance.OnADSCamera;
@ADSCamera.performed -= instance.OnADSCamera;
@ADSCamera.canceled -= instance.OnADSCamera;
}
/// <summary>
@@ -469,5 +501,12 @@ public partial class @GameInputAction: IInputActionCollection2, IDisposable
/// <seealso cref="UnityEngine.InputSystem.InputAction.performed" />
/// <seealso cref="UnityEngine.InputSystem.InputAction.canceled" />
void OnShoot(InputAction.CallbackContext context);
/// <summary>
/// Method invoked when associated input action "ADS Camera" is either <see cref="UnityEngine.InputSystem.InputAction.started" />, <see cref="UnityEngine.InputSystem.InputAction.performed" /> or <see cref="UnityEngine.InputSystem.InputAction.canceled" />.
/// </summary>
/// <seealso cref="UnityEngine.InputSystem.InputAction.started" />
/// <seealso cref="UnityEngine.InputSystem.InputAction.performed" />
/// <seealso cref="UnityEngine.InputSystem.InputAction.canceled" />
void OnADSCamera(InputAction.CallbackContext context);
}
}

View File

@@ -41,6 +41,15 @@
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "ADS Camera",
"type": "Button",
"id": "bc014086-71fa-432a-8e3c-3e2003c5244b",
"expectedControlType": "",
"processors": "",
"interactions": "",
"initialStateCheck": false
}
],
"bindings": [
@@ -131,6 +140,17 @@
"action": "Shoot",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "f5bad540-cf37-4957-ad4a-1e5a5e723890",
"path": "<Mouse>/rightButton",
"interactions": "",
"processors": "",
"groups": "",
"action": "ADS Camera",
"isComposite": false,
"isPartOfComposite": false
}
]
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 29db8f30e6e4e7e46836335e6946c6bd
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,10 @@
using UnityEngine;
namespace Darkmatter.Core
{
public interface IDamageable
{
void TakeDamage(float damage);
void Die();
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3cd1959707bc9f64c9fedf29ea9fb1b7

View File

@@ -4,6 +4,7 @@ namespace Darkmatter.Core
{
public interface IPlayerAnim : IHumonoidAnim
{
void PlayReloadAnim();
void PlayShootAnim();
}
}

View File

@@ -0,0 +1,9 @@
using UnityEngine;
namespace Darkmatter.Core
{
public interface ICameraService
{
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 9ec6d1036e8f7a34b88dc6c49fae0666

View File

@@ -6,6 +6,7 @@ namespace Darkmatter.Core
public interface IInputReader
{
public event Action OnJumpPerformed;
public event Action OnAdsCameraSwitch;
public Vector2 moveInput { get; }
public Vector2 lookInput { get; }
public bool isShooting { get; }

View File

@@ -10,6 +10,7 @@ namespace Darkmatter.Core
public GameInputAction action;
public event Action OnJumpPerformed;
public event Action OnAdsCameraSwitch;
public bool isShooting { get; private set; }
public Vector2 moveInput { get; private set; }
public Vector2 lookInput { get; private set; }
@@ -53,5 +54,13 @@ namespace Darkmatter.Core
{
isShooting = context.ReadValueAsButton();
}
public void OnADSCamera(InputAction.CallbackContext context)
{
if(context.performed)
{
OnAdsCameraSwitch?.Invoke();
}
}
}
}

View File

@@ -6,6 +6,12 @@ namespace Darkmatter.Presentation
public class PlayerAnimController : HumonoidAnim, IPlayerAnim
{
private readonly int shootHash = Animator.StringToHash("IsShooting");
public void PlayReloadAnim()
{
Debug.Log("Reloading");
}
public void PlayShootAnim()
{
Debug.Log("player Shoot");

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 44cee54525ff71e468d5c70145e8c0e6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,30 @@
using Darkmatter.Core;
using System;
using Unity.Cinemachine;
using UnityEngine;
using VContainer;
namespace Darkmatter.Presentation
{
public class CameraService : MonoBehaviour, ICameraService
{
public CinemachineThirdPersonFollow AdsCamera;
[Inject] private IInputReader inputReader;
public bool isAiming = false;
private void Start()
{
inputReader.OnAdsCameraSwitch += SwitchADSCamera;
AdsCamera.gameObject.SetActive(false);
}
private void OnDisable()
{
inputReader.OnAdsCameraSwitch -= SwitchADSCamera;
}
private void SwitchADSCamera()
{
isAiming = !isAiming;
AdsCamera.gameObject.SetActive(isAiming);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: a0a5885776e435440ab9d5cf33f86d63

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 99f130bb5ff02fa4e8fbb2b3269771f7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,22 @@
using Darkmatter.Core;
using UnityEngine;
namespace Darkmatter.Presentation
{
public class Enemy : MonoBehaviour, IDamageable
{
public float health = 100f;
public void Die()
{
Debug.Log("Dead");
this.gameObject.SetActive(false);
}
public void TakeDamage(float damage)
{
health -= damage;
if (health <= 0) Die();
Debug.Log("Damage Taken");
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 7cc0904e9eef2eb42860484c3c0d2675

View File

@@ -1,14 +1,16 @@
using Darkmatter.Core;
using Darkmatter.Domain;
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.Animations.Rigging;
using VContainer;
namespace Darkmatter.Presentation
{
public class PlayerMotor : MonoBehaviour, IPlayerPawn
{
public TwoBoneIKConstraint IKConstraint;
[Header("LookSetting")]
public Camera mainCamera { get; private set; }
public Transform cinemachineFollowTarget;
@@ -35,11 +37,12 @@ namespace Darkmatter.Presentation
public Transform aim;
Vector3 mouseWorldPos = Vector3.zero;
public Transform muzzlePos;
public Gun gun;
public float fireRate = 0.1f;
float nextFiretime=0;
public ParticleSystem particle;
public ParticleSystem muzzleFlashParticle;
public ParticleSystem bulletHitParticle;
public GameObject BulletHole;
[Inject] private IInputReader inputReader;
@@ -63,30 +66,64 @@ namespace Darkmatter.Presentation
{
}
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);
//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)
if(Time.time>=nextFiretime && bulletAmount > 0)
{
bulletAmount--;
nextFiretime = Time.time + fireRate;
gun.Init(muzzlePos.position, aim.position);
particle.Play();
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());
}
}
}
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;
mouseWorldPos= hitPoint.point;
aim.position = mouseWorldPos;
//aim.position = Vector3.Lerp(aim.position, hitPoint.point, Time.deltaTime * smoothing);
}

View File

@@ -5,7 +5,8 @@
"GUID:cf1df9e1968a94c4686f2fbe5ef907fc",
"GUID:23f9a018fbd2e1242a0525718cc761d6",
"GUID:b0214a6008ed146ff8f122a6a9c2f6cc",
"GUID:4307f53044263cf4b835bd812fc161a4"
"GUID:4307f53044263cf4b835bd812fc161a4",
"GUID:7f7d1af65c2641843945d409d28f2e20"
],
"includePlatforms": [],
"excludePlatforms": [],