started building logics for enemy
This commit is contained in:
@@ -28,7 +28,7 @@ namespace Darkmatter.App
|
||||
builder.RegisterComponent<ITargetProvider>(TargetProvider);
|
||||
builder.RegisterComponent(playerConfig);
|
||||
builder.RegisterComponent(cameraConfig);
|
||||
builder.RegisterComponent<IWeapon>(gunWeapon);
|
||||
builder.RegisterComponent<IReloadableWeapon>(gunWeapon);
|
||||
builder.Register<PlayerStateMachine>(Lifetime.Scoped);
|
||||
builder.RegisterComponentInHierarchy<CameraService>().As<ICameraService>();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Darkmatter.Core
|
||||
{
|
||||
public interface IReloadableWeapon
|
||||
{
|
||||
bool canAttack { get; }
|
||||
bool isReloading { get; set; }
|
||||
int AmmoCount { get; }
|
||||
int initialAmmoCount { get; }
|
||||
void Reload();
|
||||
void Attack();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e1f1c00d28297145ae2503fa9cda9c4
|
||||
@@ -1,15 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Darkmatter.Core
|
||||
{
|
||||
public interface IWeapon
|
||||
{
|
||||
public void Attack();
|
||||
public void Reload();
|
||||
bool canAttack { get; }
|
||||
string WeaponName { get; }
|
||||
public int AmmoCount { get; }
|
||||
public int maxAmmoCount { get; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f82b92b1e5608845a9706ad20b155f8
|
||||
@@ -5,7 +5,7 @@ namespace Darkmatter.Core
|
||||
{
|
||||
public interface IPlayerAnim : IHumonoidAnim
|
||||
{
|
||||
public void PlayReloadAnim(IWeapon currentWeapon);
|
||||
public void PlayReloadAnim(IReloadableWeapon reloadableWeapon);
|
||||
void PlayShootAnim();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 156c6779124556c48b177104c19c29f9
|
||||
guid: d918fdc659ee8fe4e8c97089cf4bc09b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
21
Assets/Darkmatter/Code/Domain/Enemy/EnemyController.cs
Normal file
21
Assets/Darkmatter/Code/Domain/Enemy/EnemyController.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
using VContainer.Unity;
|
||||
|
||||
namespace Darkmatter.Domain
|
||||
{
|
||||
public class EnemyController : IStartable, ITickable
|
||||
{
|
||||
[Inject] EnemyStateMachine esm;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
esm.Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2fbe43d3f58deb3489ba1565abc2b050
|
||||
9
Assets/Darkmatter/Code/Domain/Enemy/EnemyStateMachine.cs
Normal file
9
Assets/Darkmatter/Code/Domain/Enemy/EnemyStateMachine.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Darkmatter.Domain
|
||||
{
|
||||
public class EnemyStateMachine:StateMachine
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c90488ca687a5724bbff14600be305d6
|
||||
@@ -13,7 +13,7 @@ namespace Darkmatter.Domain
|
||||
[Inject] public readonly IPlayerAnim playerAnim;
|
||||
[Inject] public readonly ITargetProvider targetProvider;
|
||||
[Inject] public readonly ICameraService cameraService;
|
||||
[Inject] public readonly IWeapon GunWeapon;
|
||||
[Inject] public readonly IReloadableWeapon currentWeapon;
|
||||
[Inject] public readonly PlayerConfigSO playerConfig;
|
||||
[Inject] public readonly CameraConfigSO cameraConfig;
|
||||
|
||||
@@ -54,23 +54,23 @@ namespace Darkmatter.Domain
|
||||
public void Shoot(bool isShooting)
|
||||
{
|
||||
if (!isShooting) return;
|
||||
if(GunWeapon.canAttack)
|
||||
if(currentWeapon.canAttack)
|
||||
{
|
||||
GunWeapon.Attack();
|
||||
currentWeapon.Attack();
|
||||
}
|
||||
if(GunWeapon.AmmoCount==0)
|
||||
if (currentWeapon.AmmoCount == 0)
|
||||
{
|
||||
playerAnim.PlayReloadAnim(GunWeapon);
|
||||
playerAnim.PlayReloadAnim(currentWeapon);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Reload()
|
||||
{
|
||||
if(GunWeapon.AmmoCount < GunWeapon.maxAmmoCount)
|
||||
if(currentWeapon.AmmoCount<currentWeapon.initialAmmoCount)
|
||||
{
|
||||
playerAnim.PlayReloadAnim(GunWeapon);
|
||||
playerAnim.PlayReloadAnim(currentWeapon);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
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 virtual int AmmoCount { get; set; }
|
||||
|
||||
public int maxAmmoCount { get; private set; } = 40;
|
||||
|
||||
public abstract void Attack();
|
||||
|
||||
public virtual void Reload()
|
||||
{
|
||||
Debug.Log("Reloading");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 87a4d2aa64c2bc1468b8e548d66764e1
|
||||
@@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
public class EnemyAnimationController : MonoBehaviour
|
||||
{
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2db86e800d68dad4d98796670a91a679
|
||||
@@ -16,27 +16,27 @@ namespace Darkmatter.Presentation
|
||||
public TwoBoneIKConstraint HandOnGunIK; //for gunHand Ik
|
||||
private Coroutine reloadCoroutine;
|
||||
|
||||
public void PlayReloadAnim(IWeapon currentWeapon)
|
||||
public void PlayReloadAnim(IReloadableWeapon reloadableWeapon)
|
||||
{
|
||||
if (reloadCoroutine == null)
|
||||
{
|
||||
reloadCoroutine = StartCoroutine(ReloadRoutine(currentWeapon));
|
||||
reloadCoroutine = StartCoroutine(ReloadRoutine(reloadableWeapon));
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator ReloadRoutine(IWeapon currentWeapon)
|
||||
IEnumerator ReloadRoutine(IReloadableWeapon reloadableWeapon)
|
||||
{
|
||||
reloadableWeapon.isReloading = true;
|
||||
yield return BlendLayerWeight(1, 1, 0.2f);
|
||||
//animator.SetLayerWeight(1,1);
|
||||
HandOnGunIK.weight = 0f;
|
||||
animator.SetTrigger(reloadHash);
|
||||
|
||||
yield return new WaitForSeconds(3f); //gave the length of the animation very bad practice
|
||||
|
||||
// animator.SetLayerWeight(1, 0);
|
||||
yield return BlendLayerWeight(1, 0, 0.2f);
|
||||
HandOnGunIK.weight = 1f;
|
||||
currentWeapon.Reload();
|
||||
reloadableWeapon.Reload();
|
||||
reloadableWeapon.isReloading = false;
|
||||
reloadCoroutine = null;
|
||||
|
||||
}
|
||||
|
||||
23
Assets/Darkmatter/Code/Presentation/Enemies/EnemyMotor.cs
Normal file
23
Assets/Darkmatter/Code/Presentation/Enemies/EnemyMotor.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
public class EnemyMotor : MonoBehaviour
|
||||
{
|
||||
[SerializeField] NavMeshAgent enemyAI;
|
||||
public Transform playerTransform;
|
||||
|
||||
[Header("Enemy Data")]
|
||||
public float walkSpeed = 3f;
|
||||
public float chaseSpeed = 5f;
|
||||
public float visionRange = 15f;
|
||||
public float attackRange = 2f;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
enemyAI.SetDestination(playerTransform.position);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df95acdebfef05045a08adb2e752fd26
|
||||
@@ -29,28 +29,10 @@ namespace Darkmatter.Presentation
|
||||
public float turnSpeed = 5f;
|
||||
[Inject] private PlayerConfigSO playerConfig;
|
||||
|
||||
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
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(gunWeapon.canAttack)
|
||||
//{
|
||||
// gunWeapon.Attack();
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
//state based functions
|
||||
public void Move(Vector3 motion)
|
||||
|
||||
@@ -6,7 +6,7 @@ using VContainer;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
public class GunWeapon : WeaponBase
|
||||
public class GunWeapon : MonoBehaviour, IReloadableWeapon
|
||||
{
|
||||
[Header("VFX")]
|
||||
public ParticleSystem MuzzleFlashParticle;
|
||||
@@ -14,24 +14,21 @@ namespace Darkmatter.Presentation
|
||||
|
||||
[Header("Weapon Data")]
|
||||
public float fireRate = 0.1f;
|
||||
[SerializeField] private int ammoCount = 40;
|
||||
public bool isReloading { get; set; }
|
||||
public int AmmoCount { get; set; } = 40;
|
||||
public int initialAmmoCount { get; set; } = 40;
|
||||
private float lastUsedTime;
|
||||
public GameObject BulletHole;
|
||||
public override string WeaponName => "Rifel";
|
||||
public override int AmmoCount { get => this.ammoCount; set => ammoCount = value; }
|
||||
|
||||
|
||||
public override bool canAttack => Time.time >= lastUsedTime + fireRate && ammoCount > 0;
|
||||
public bool canAttack => Time.time >= lastUsedTime + fireRate && AmmoCount > 0 && !isReloading;
|
||||
|
||||
[Inject] private ITargetProvider targetProvider;
|
||||
private RaycastHit hitPoint => targetProvider.hitPoint;
|
||||
|
||||
|
||||
|
||||
public override void Attack()
|
||||
public void Attack()
|
||||
{
|
||||
lastUsedTime = Time.time;
|
||||
ammoCount--;
|
||||
AmmoCount--;
|
||||
|
||||
PlayMuzzleFlash();
|
||||
if (hitPoint.transform != null) PlayBulletHitEffectParticle();
|
||||
@@ -55,14 +52,13 @@ namespace Darkmatter.Presentation
|
||||
|
||||
BulletHitEffectParticle.transform.position = spawnPos;
|
||||
BulletHitEffectParticle.transform.rotation = Quaternion.LookRotation(hitPoint.normal);
|
||||
|
||||
|
||||
BulletHitEffectParticle.Play(true);
|
||||
}
|
||||
|
||||
public override void Reload()
|
||||
public void Reload()
|
||||
{
|
||||
base.Reload();
|
||||
ammoCount = maxAmmoCount;
|
||||
AmmoCount = initialAmmoCount;
|
||||
}
|
||||
|
||||
private void PlayMuzzleFlash()
|
||||
|
||||
Reference in New Issue
Block a user