Initial commit
This commit is contained in:
8
Assets/Darkmatter/Code/Presentation/Animation.meta
Normal file
8
Assets/Darkmatter/Code/Presentation/Animation.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 588d14d62487efd48ae44adbf2cdfbb7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,41 @@
|
||||
using Darkmatter.Core;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
public class EnemyAnimController : HumonoidAnim, IEnemyAnimController
|
||||
{
|
||||
private readonly int walkHash = Animator.StringToHash("walk");
|
||||
private readonly int chaseHash = Animator.StringToHash("chase");
|
||||
private readonly int attackHash = Animator.StringToHash("attack");
|
||||
private readonly int deadHash = Animator.StringToHash("dead");
|
||||
|
||||
public void PlayWalkAnim(bool value)
|
||||
{
|
||||
animator.SetBool(walkHash, value);
|
||||
}
|
||||
|
||||
public void PlayAttackAnim(bool value)
|
||||
{
|
||||
animator.SetBool(attackHash, value);
|
||||
}
|
||||
|
||||
public void PlayeChaseAnim(bool value)
|
||||
{
|
||||
animator.SetBool(chaseHash, value);
|
||||
}
|
||||
|
||||
public void PlayDeadAnim()
|
||||
{
|
||||
resetValues();
|
||||
animator.SetTrigger(deadHash);
|
||||
}
|
||||
|
||||
public void resetValues()
|
||||
{
|
||||
animator.SetBool("walk", false);
|
||||
animator.SetBool("chase", false);
|
||||
animator.SetBool("attack", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2db86e800d68dad4d98796670a91a679
|
||||
@@ -0,0 +1,17 @@
|
||||
using Darkmatter.Core;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
public abstract class HumonoidAnim : MonoBehaviour, IHumonoidAnim
|
||||
{
|
||||
public Animator animator;
|
||||
|
||||
protected readonly int jumpHash = Animator.StringToHash("Jump");
|
||||
|
||||
public void PlayJumpAnim()
|
||||
{
|
||||
animator.SetTrigger(jumpHash);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0456d664cb3848c4bb8a381db3fe819a
|
||||
@@ -0,0 +1,81 @@
|
||||
using Darkmatter.Core;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
using VContainer;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
public class PlayerAnimController : HumonoidAnim, IPlayerAnim
|
||||
{
|
||||
private readonly int shootHash = Animator.StringToHash("IsShooting");
|
||||
protected readonly int moveXhash = Animator.StringToHash("MoveX");
|
||||
protected readonly int moveYhash = Animator.StringToHash("MoveY");
|
||||
private readonly int reloadHash = Animator.StringToHash("Reload");
|
||||
private readonly int deadHash = Animator.StringToHash("Dead");
|
||||
public TwoBoneIKConstraint HandOnGunIK; //for gunHand Ik
|
||||
private Coroutine reloadCoroutine;
|
||||
|
||||
public void PlayReloadAnim(IReloadableWeapon reloadableWeapon)
|
||||
{
|
||||
if (reloadCoroutine == null)
|
||||
{
|
||||
reloadCoroutine = StartCoroutine(ReloadRoutine(reloadableWeapon));
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator ReloadRoutine(IReloadableWeapon reloadableWeapon)
|
||||
{
|
||||
reloadableWeapon.isReloading = true;
|
||||
yield return BlendLayerWeight(1, 1, 0.2f);
|
||||
HandOnGunIK.weight = 0f;
|
||||
animator.SetTrigger(reloadHash);
|
||||
|
||||
yield return new WaitForSeconds(3f); //gave the length of the animation very bad practice
|
||||
|
||||
yield return BlendLayerWeight(1, 0, 0.2f);
|
||||
HandOnGunIK.weight = 1f;
|
||||
reloadableWeapon.Reload();
|
||||
reloadableWeapon.isReloading = false;
|
||||
reloadCoroutine = null;
|
||||
|
||||
}
|
||||
|
||||
IEnumerator BlendLayerWeight(int layerIndex, float targetWeight, float blendTime)
|
||||
{
|
||||
float startWeight = animator.GetLayerWeight(layerIndex);
|
||||
float time = 0f;
|
||||
|
||||
while (time < blendTime)
|
||||
{
|
||||
time += Time.deltaTime;
|
||||
float t = time / blendTime;
|
||||
float weight = Mathf.Lerp(startWeight, targetWeight, t);
|
||||
animator.SetLayerWeight(layerIndex, weight);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
animator.SetLayerWeight(layerIndex, targetWeight);
|
||||
}
|
||||
|
||||
|
||||
public void PlayMovementAnim(Vector2 velocity)
|
||||
{
|
||||
animator.SetFloat(moveXhash, velocity.x, 0.4f, Time.deltaTime);
|
||||
animator.SetFloat(moveYhash, velocity.y, 0.4f, Time.deltaTime);
|
||||
}
|
||||
|
||||
public void PlayShootAnim()
|
||||
{
|
||||
Debug.Log("player Shoot");
|
||||
}
|
||||
|
||||
public void PlayDeadAnim()
|
||||
{
|
||||
animator.SetTrigger(deadHash);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0bcf4be752bf7ad448fd187a62487726
|
||||
8
Assets/Darkmatter/Code/Presentation/Audio.meta
Normal file
8
Assets/Darkmatter/Code/Presentation/Audio.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 34c3dab5409b0d74783cac7f227e35ad
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
65
Assets/Darkmatter/Code/Presentation/Audio/AudioService.cs
Normal file
65
Assets/Darkmatter/Code/Presentation/Audio/AudioService.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using Darkmatter.Core;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
|
||||
[System.Serializable]
|
||||
public struct AudioEntry
|
||||
{
|
||||
public AudioId id;
|
||||
public AudioClip clip;
|
||||
}
|
||||
public class AudioService : MonoBehaviour, IAudioService
|
||||
{
|
||||
[Header("Audio Sources")]
|
||||
[SerializeField] private AudioSource musicSource;
|
||||
[SerializeField] private AudioSource sfxSource;
|
||||
|
||||
[Header("Audio Clips")]
|
||||
[SerializeField] private AudioEntry[] clips;
|
||||
|
||||
private Dictionary<AudioId, AudioClip> _clipMap;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_clipMap = new Dictionary<AudioId, AudioClip>();
|
||||
|
||||
foreach (var entry in clips)
|
||||
{
|
||||
if (!_clipMap.ContainsKey(entry.id))
|
||||
_clipMap.Add(entry.id, entry.clip);
|
||||
}
|
||||
|
||||
DontDestroyOnLoad(gameObject);
|
||||
PlayMusic(AudioId.Music_Gameplay);
|
||||
}
|
||||
|
||||
public void PlayMusic(AudioId id)
|
||||
{
|
||||
if (!_clipMap.TryGetValue(id, out var clip)) return;
|
||||
|
||||
musicSource.clip = clip;
|
||||
musicSource.loop = true;
|
||||
musicSource.Play();
|
||||
}
|
||||
|
||||
public void StopMusic()
|
||||
{
|
||||
musicSource.Stop();
|
||||
}
|
||||
|
||||
public void PlaySFX(AudioId id,float volume)
|
||||
{
|
||||
if (!_clipMap.TryGetValue(id, out var clip)) return;
|
||||
sfxSource.PlayOneShot(clip,volume);
|
||||
}
|
||||
|
||||
public void PlaySFXAt(AudioId id, Vector3 position)
|
||||
{
|
||||
if (!_clipMap.TryGetValue(id, out var clip)) return;
|
||||
AudioSource.PlayClipAtPoint(clip, position);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e1cf6936af3bcb942b8d98990ed4f7ae
|
||||
8
Assets/Darkmatter/Code/Presentation/Camera.meta
Normal file
8
Assets/Darkmatter/Code/Presentation/Camera.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44cee54525ff71e468d5c70145e8c0e6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
32
Assets/Darkmatter/Code/Presentation/Camera/CameraService.cs
Normal file
32
Assets/Darkmatter/Code/Presentation/Camera/CameraService.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Darkmatter.Core;
|
||||
using System;
|
||||
using Unity.Cinemachine;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
public class CameraService : MonoBehaviour, ICameraService
|
||||
{
|
||||
public Camera mainCamera { get; private set; }
|
||||
public CinemachineThirdPersonFollow AdsCamera;
|
||||
[Inject] private IInputReader inputReader;
|
||||
public bool isAiming = false;
|
||||
private void Start()
|
||||
{
|
||||
mainCamera = Camera.main;
|
||||
inputReader.OnAdsCameraSwitch += SwitchADSCamera;
|
||||
AdsCamera.gameObject.SetActive(false);
|
||||
}
|
||||
private void OnDisable()
|
||||
{
|
||||
inputReader.OnAdsCameraSwitch -= SwitchADSCamera;
|
||||
}
|
||||
|
||||
private void SwitchADSCamera()
|
||||
{
|
||||
isAiming = !isAiming;
|
||||
AdsCamera.gameObject.SetActive(isAiming);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0a5885776e435440ab9d5cf33f86d63
|
||||
8
Assets/Darkmatter/Code/Presentation/Enemies.meta
Normal file
8
Assets/Darkmatter/Code/Presentation/Enemies.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 99f130bb5ff02fa4e8fbb2b3269771f7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,77 @@
|
||||
using Darkmatter.Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Pool;
|
||||
using VContainer;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
public class EnemiesSpawnner : MonoBehaviour
|
||||
{
|
||||
[Inject] IEnemyFactory _enemyFactory;
|
||||
[Inject] IGameScreenController gameScreenController;
|
||||
public int baseEnemyCount =2;
|
||||
private ObjectPool<IEnemyPawn> _enemyPool;
|
||||
|
||||
private int killedEnemies = 0;
|
||||
private int enemiesMultiplier = 1;
|
||||
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
EnemyMotor.OnEnemyDead += ReturnEnemy;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
EnemyMotor.OnEnemyDead -= ReturnEnemy;
|
||||
}
|
||||
private void Awake()
|
||||
{
|
||||
_enemyPool = new ObjectPool<IEnemyPawn>(
|
||||
createFunc: () => _enemyFactory.GetEnemy(GetRandomType()),
|
||||
actionOnGet: enemy => enemy.GameObject.SetActive(true),
|
||||
actionOnRelease: enemy => enemy.GameObject.SetActive(false),
|
||||
actionOnDestroy: enemy => Destroy(enemy.GameObject),
|
||||
collectionCheck: true,
|
||||
defaultCapacity: 10,
|
||||
maxSize: 50
|
||||
);
|
||||
}
|
||||
|
||||
private ZombieType GetRandomType()
|
||||
{
|
||||
return Random.value > 0.5f ? ZombieType.Fat : ZombieType.slim;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
SpawnWave(enemiesMultiplier);
|
||||
}
|
||||
|
||||
private void SpawnWave(int multiplier)
|
||||
{
|
||||
gameScreenController.UpdateTotalZombiesCount(baseEnemyCount*multiplier);
|
||||
gameScreenController.UpdateRemainingZombiesCount(baseEnemyCount*multiplier);
|
||||
for (int i = 0; i < baseEnemyCount*multiplier; i++)
|
||||
{
|
||||
IEnemyPawn enemy = _enemyPool.Get();
|
||||
enemy.GameObject.transform.position = enemy.PatrolPoints[Random.Range(0, enemy.PatrolPoints.Count)].position;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void ReturnEnemy(IEnemyPawn enemy)
|
||||
{
|
||||
enemy.Reset();
|
||||
_enemyPool.Release(enemy);
|
||||
killedEnemies++;
|
||||
gameScreenController.UpdateRemainingZombiesCount(baseEnemyCount*enemiesMultiplier - killedEnemies);
|
||||
if(killedEnemies == baseEnemyCount*enemiesMultiplier)
|
||||
{
|
||||
killedEnemies = 0;
|
||||
enemiesMultiplier++;
|
||||
SpawnWave(enemiesMultiplier);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a025e89a66ec0f147a00c91dcb63c22f
|
||||
69
Assets/Darkmatter/Code/Presentation/Enemies/EnemyMotor.cs
Normal file
69
Assets/Darkmatter/Code/Presentation/Enemies/EnemyMotor.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using Darkmatter.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
using VContainer;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
public class EnemyMotor : MonoBehaviour, IEnemyPawn
|
||||
{
|
||||
public static event Action<IEnemyPawn> OnEnemyDead;
|
||||
public GameObject GameObject => this.gameObject;
|
||||
[SerializeField] private NavMeshAgent enemyAI;
|
||||
|
||||
public Transform PlayerTarget { get; private set; }
|
||||
public NavMeshAgent EnemyAI => enemyAI;
|
||||
public List<Transform> PatrolPoints { get; private set; } = new List<Transform>();
|
||||
|
||||
public float Health { get; set; } = 100;
|
||||
|
||||
public bool isDead { get; set; } = false;
|
||||
|
||||
public event Action<float> OnHealthDecreased;
|
||||
|
||||
public void Die()
|
||||
{
|
||||
if(isDead) return;
|
||||
isDead = true;
|
||||
enemyAI.enabled = false;
|
||||
Invoke(nameof(Hide), 5f);
|
||||
}
|
||||
|
||||
private void Hide()
|
||||
{
|
||||
OnEnemyDead?.Invoke(this);
|
||||
}
|
||||
|
||||
public Vector3 ReturnMyPos()
|
||||
{
|
||||
return this.transform.position;
|
||||
}
|
||||
|
||||
|
||||
public void SetDestination(Vector3 destination)
|
||||
{
|
||||
enemyAI.SetDestination(destination);
|
||||
}
|
||||
|
||||
public void TakeDamage(float damage)
|
||||
{
|
||||
Health -= damage;
|
||||
OnHealthDecreased?.Invoke(Health);
|
||||
}
|
||||
|
||||
public void InitializeFromFactory(Transform player, List<Transform> patrolPoints)
|
||||
{
|
||||
this.PlayerTarget = player;
|
||||
this.PatrolPoints = patrolPoints;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Health = 100;
|
||||
enemyAI.enabled = true;
|
||||
isDead = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df95acdebfef05045a08adb2e752fd26
|
||||
8
Assets/Darkmatter/Code/Presentation/Player.meta
Normal file
8
Assets/Darkmatter/Code/Presentation/Player.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61cdaef640578c9429e0b3f1a12a3e59
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
159
Assets/Darkmatter/Code/Presentation/Player/BulletRenderer.prefab
Normal file
159
Assets/Darkmatter/Code/Presentation/Player/BulletRenderer.prefab
Normal file
@@ -0,0 +1,159 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &8503761475068701983
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 543925742380460365}
|
||||
- component: {fileID: 6906598175330505539}
|
||||
- component: {fileID: 8812288568393030278}
|
||||
m_Layer: 0
|
||||
m_Name: BulletRenderer
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &543925742380460365
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8503761475068701983}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: -9.016138, y: 2.43599, z: 10.534973}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!120 &6906598175330505539
|
||||
LineRenderer:
|
||||
serializedVersion: 3
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8503761475068701983}
|
||||
m_Enabled: 0
|
||||
m_CastShadows: 1
|
||||
m_ReceiveShadows: 1
|
||||
m_DynamicOccludee: 1
|
||||
m_StaticShadowCaster: 0
|
||||
m_MotionVectors: 0
|
||||
m_LightProbeUsage: 0
|
||||
m_ReflectionProbeUsage: 0
|
||||
m_RayTracingMode: 0
|
||||
m_RayTraceProcedural: 0
|
||||
m_RayTracingAccelStructBuildFlagsOverride: 0
|
||||
m_RayTracingAccelStructBuildFlags: 1
|
||||
m_SmallMeshCulling: 1
|
||||
m_ForceMeshLod: -1
|
||||
m_MeshLodSelectionBias: 0
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 2100000, guid: ffcd02750402e264babfe88a9b5f9422, type: 2}
|
||||
m_StaticBatchInfo:
|
||||
firstSubMesh: 0
|
||||
subMeshCount: 0
|
||||
m_StaticBatchRoot: {fileID: 0}
|
||||
m_ProbeAnchor: {fileID: 0}
|
||||
m_LightProbeVolumeOverride: {fileID: 0}
|
||||
m_ScaleInLightmap: 1
|
||||
m_ReceiveGI: 1
|
||||
m_PreserveUVs: 0
|
||||
m_IgnoreNormalsForChartDetection: 0
|
||||
m_ImportantGI: 0
|
||||
m_StitchLightmapSeams: 1
|
||||
m_SelectedEditorRenderState: 3
|
||||
m_MinimumChartSize: 4
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_GlobalIlluminationMeshLod: 0
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 0
|
||||
m_MaskInteraction: 0
|
||||
m_Positions:
|
||||
- {x: 0.47888803, y: 1.0178367, z: 1.3048704}
|
||||
- {x: -24.632084, y: 1.7695255, z: 0.94831866}
|
||||
m_Parameters:
|
||||
serializedVersion: 3
|
||||
widthMultiplier: 1
|
||||
widthCurve:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 0.01629239
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
colorGradient:
|
||||
serializedVersion: 2
|
||||
key0: {r: 1, g: 1, b: 1, a: 1}
|
||||
key1: {r: 1, g: 1, b: 1, a: 1}
|
||||
key2: {r: 0, g: 0, b: 0, a: 0}
|
||||
key3: {r: 0, g: 0, b: 0, a: 0}
|
||||
key4: {r: 0, g: 0, b: 0, a: 0}
|
||||
key5: {r: 0, g: 0, b: 0, a: 0}
|
||||
key6: {r: 0, g: 0, b: 0, a: 0}
|
||||
key7: {r: 0, g: 0, b: 0, a: 0}
|
||||
ctime0: 0
|
||||
ctime1: 65535
|
||||
ctime2: 0
|
||||
ctime3: 0
|
||||
ctime4: 0
|
||||
ctime5: 0
|
||||
ctime6: 0
|
||||
ctime7: 0
|
||||
atime0: 0
|
||||
atime1: 65535
|
||||
atime2: 0
|
||||
atime3: 0
|
||||
atime4: 0
|
||||
atime5: 0
|
||||
atime6: 0
|
||||
atime7: 0
|
||||
m_Mode: 0
|
||||
m_ColorSpace: -1
|
||||
m_NumColorKeys: 2
|
||||
m_NumAlphaKeys: 2
|
||||
numCornerVertices: 0
|
||||
numCapVertices: 0
|
||||
alignment: 0
|
||||
textureMode: 0
|
||||
textureScale: {x: 1, y: 1}
|
||||
shadowBias: 0
|
||||
generateLightingData: 0
|
||||
m_UseWorldSpace: 1
|
||||
m_Loop: 0
|
||||
m_ApplyActiveColorSpace: 1
|
||||
--- !u!114 &8812288568393030278
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8503761475068701983}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: c3f99ff473a5f474099e6dd5f8dcde78, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: PresentationAssembly::Darkmatter.Presentation.Gun
|
||||
lineRenderer: {fileID: 6906598175330505539}
|
||||
LifeTime: 0.05
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66690771668559c4d94e4475af123c1e
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,41 @@
|
||||
using Darkmatter.Core;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
public class PlayerAimTargetProvider : 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
|
||||
131
Assets/Darkmatter/Code/Presentation/Player/PlayerMotor.cs
Normal file
131
Assets/Darkmatter/Code/Presentation/Player/PlayerMotor.cs
Normal file
@@ -0,0 +1,131 @@
|
||||
using Darkmatter.Core;
|
||||
using Darkmatter.Domain;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
using UnityEngine.SceneManagement;
|
||||
using VContainer;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
public class PlayerMotor : MonoBehaviour, IPlayerPawn
|
||||
{
|
||||
|
||||
[Header("LookSetting")]
|
||||
public Transform cinemachineFollowTarget;
|
||||
|
||||
[Header("MoveSetting")]
|
||||
public CharacterController characterController;
|
||||
|
||||
[Header("GravitySetting")]
|
||||
private float verticalVelocity;
|
||||
public bool isGrounded => IsOnGround();
|
||||
|
||||
public float Health { get; set; } = 100;
|
||||
|
||||
[Header("GroundCheckSensorSetting")]
|
||||
public float groundOffset;
|
||||
public float groundCheckRadius;
|
||||
public LayerMask groundLayer;
|
||||
|
||||
[Header("TurnSetting")]
|
||||
public float turnSpeed = 5f;
|
||||
[Inject] private PlayerConfigSO playerConfig;
|
||||
[Inject] private IPlayerAnim PlayerAnim;
|
||||
[Inject] private IGameScreenController gameScreenController;
|
||||
[Inject] private IInputReader inputReader;
|
||||
|
||||
public event Action<float> OnHealthDecreased;
|
||||
|
||||
private bool isDead=false;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
|
||||
//state based functions
|
||||
public void Move(Vector3 motion)
|
||||
{
|
||||
ApplyGravity(); //apply gravity before moving
|
||||
Vector3 finalMove = motion;
|
||||
finalMove.y = verticalVelocity;
|
||||
characterController.Move(finalMove * Time.deltaTime);
|
||||
}
|
||||
|
||||
public void SetCameraRotation(float pitch, float yaw)
|
||||
{
|
||||
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
|
||||
}
|
||||
|
||||
public void Jump(float jumpForce)
|
||||
{
|
||||
verticalVelocity = jumpForce;
|
||||
}
|
||||
|
||||
public bool IsOnGround()
|
||||
{
|
||||
Vector3 groundPos = transform.position + Vector3.down * groundOffset;
|
||||
|
||||
return Physics.CheckSphere(
|
||||
groundPos,
|
||||
groundCheckRadius,
|
||||
groundLayer,
|
||||
QueryTriggerInteraction.Ignore
|
||||
);
|
||||
|
||||
}
|
||||
public void ApplyGravity()
|
||||
{
|
||||
if (isGrounded && verticalVelocity < 0f)
|
||||
{
|
||||
verticalVelocity = -2f; // snap to ground
|
||||
}
|
||||
verticalVelocity += playerConfig.gravity * Time.deltaTime;
|
||||
}
|
||||
void OnDrawGizmosSelected()
|
||||
{
|
||||
Gizmos.color = Color.green;
|
||||
Vector3 groundPos = transform.position + Vector3.down * groundOffset;
|
||||
Gizmos.DrawWireSphere(groundPos, groundCheckRadius);
|
||||
}
|
||||
float damageCooldown = 1f;
|
||||
float lastHitTime;
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if(other.CompareTag("Enemy")&& !isDead)
|
||||
{
|
||||
TakeDamage(10);
|
||||
}
|
||||
}
|
||||
|
||||
public void TakeDamage(float damage)
|
||||
{
|
||||
Health-=damage;
|
||||
if(Health<=0)
|
||||
{
|
||||
Die();
|
||||
}
|
||||
gameScreenController.ShowPlayerHealth((int)Health);
|
||||
}
|
||||
|
||||
public void Die()
|
||||
{
|
||||
isDead = true;
|
||||
PlayerAnim.PlayDeadAnim();
|
||||
inputReader.DisableInput();
|
||||
Invoke("GameOver", 4f);
|
||||
}
|
||||
|
||||
private void GameOver()
|
||||
{
|
||||
gameScreenController.ShowGameOverText();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0dd0478b6c34c674aa4378c3ad35088f
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "PresentationAssembly",
|
||||
"rootNamespace": "Darkmatter.Presentation",
|
||||
"references": [
|
||||
"GUID:cf1df9e1968a94c4686f2fbe5ef907fc",
|
||||
"GUID:23f9a018fbd2e1242a0525718cc761d6",
|
||||
"GUID:b0214a6008ed146ff8f122a6a9c2f6cc",
|
||||
"GUID:4307f53044263cf4b835bd812fc161a4",
|
||||
"GUID:7f7d1af65c2641843945d409d28f2e20",
|
||||
"GUID:6055be8ebefd69e48b49212b09b47b2f"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00bcf444fe1ffd8468345b96caa37633
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Darkmatter/Code/Presentation/UI.meta
Normal file
8
Assets/Darkmatter/Code/Presentation/UI.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89a481c3f65727c43a170bb2b20ebdf1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,40 @@
|
||||
using Darkmatter.Core;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
public class GameScreenController : IGameScreenController
|
||||
{
|
||||
GameScreenView gameScreenView;
|
||||
|
||||
public GameScreenController(GameScreenView gameScreenView)
|
||||
{
|
||||
this.gameScreenView = gameScreenView;
|
||||
}
|
||||
public void UpdateFireableBulletCount(int bulletCount)
|
||||
{
|
||||
gameScreenView.UpdateBulletText(bulletCount);
|
||||
}
|
||||
|
||||
public void UpdateRemainingZombiesCount(int zombiesCount)
|
||||
{
|
||||
gameScreenView.UpdateRemainingZombiesCountText(zombiesCount);
|
||||
}
|
||||
|
||||
public void UpdateTotalZombiesCount(int totalZombiesCount)
|
||||
{
|
||||
gameScreenView.UpdateTotalZombiesCount(totalZombiesCount);
|
||||
}
|
||||
|
||||
public void ShowGameOverText()
|
||||
{
|
||||
gameScreenView.ShowGameOver();
|
||||
|
||||
}
|
||||
|
||||
public void ShowPlayerHealth(int health)
|
||||
{
|
||||
gameScreenView.ShowPlayerHealth(health);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7143025033c7d9840a214fb5c4bfefb9
|
||||
45
Assets/Darkmatter/Code/Presentation/UI/GameScreenView.cs
Normal file
45
Assets/Darkmatter/Code/Presentation/UI/GameScreenView.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
public class GameScreenView : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI fireableBulletText;
|
||||
public TextMeshProUGUI remainingZombiesCountText;
|
||||
public TextMeshProUGUI totalZombiesCountText;
|
||||
public TextMeshProUGUI playerHealthText;
|
||||
public GameObject GameOverObject;
|
||||
|
||||
public void UpdateBulletText(int bulletCount)
|
||||
{
|
||||
fireableBulletText.text = bulletCount.ToString();
|
||||
}
|
||||
|
||||
public void UpdateRemainingZombiesCountText(int zombiesCount)
|
||||
{
|
||||
remainingZombiesCountText.text = zombiesCount.ToString();
|
||||
}
|
||||
|
||||
public void UpdateTotalZombiesCount(int totalZombies)
|
||||
{
|
||||
totalZombiesCountText.text = totalZombies.ToString();
|
||||
}
|
||||
public void ShowPlayerHealth(int health)
|
||||
{
|
||||
playerHealthText.text = health.ToString();
|
||||
}
|
||||
public void ShowGameOver()
|
||||
{
|
||||
GameOverObject.SetActive(true);
|
||||
Invoke("ChangeScene", 2f);
|
||||
}
|
||||
|
||||
void ChangeScene()
|
||||
{
|
||||
SceneManager.LoadScene(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53b791085ea93e74eb91492d67fa02a6
|
||||
17
Assets/Darkmatter/Code/Presentation/UI/MenuScreen.cs
Normal file
17
Assets/Darkmatter/Code/Presentation/UI/MenuScreen.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
public class MenuScreen : MonoBehaviour
|
||||
{
|
||||
private void Start()
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
}
|
||||
public void OnPlayBtnClick()
|
||||
{
|
||||
SceneManager.LoadScene(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f9f29400af628d418161d7091f4ecc3
|
||||
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:
|
||||
78
Assets/Darkmatter/Code/Presentation/Weapons/GunWeapon.cs
Normal file
78
Assets/Darkmatter/Code/Presentation/Weapons/GunWeapon.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using Darkmatter.Core;
|
||||
using Darkmatter.Domain;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
public class GunWeapon : MonoBehaviour, IReloadableWeapon
|
||||
{
|
||||
[Header("VFX")]
|
||||
public ParticleSystem MuzzleFlashParticle;
|
||||
public ParticleSystem BulletHitEffectParticle;
|
||||
public ParticleSystem ZombieHitEffectParticle;
|
||||
|
||||
[Header("Weapon Data")]
|
||||
public float fireRate = 0.1f;
|
||||
public bool isReloading { get; set; }
|
||||
public int AmmoCount { get; set; } = 40;
|
||||
public int initialAmmoCount { get; set; } = 40;
|
||||
private float lastUsedTime;
|
||||
public GameObject BulletHole;
|
||||
public bool canAttack => Time.time >= lastUsedTime + fireRate && AmmoCount > 0 && !isReloading;
|
||||
|
||||
[Inject] private ITargetProvider targetProvider;
|
||||
private RaycastHit hitPoint => targetProvider.hitPoint;
|
||||
|
||||
|
||||
public void Attack()
|
||||
{
|
||||
lastUsedTime = Time.time;
|
||||
AmmoCount--;
|
||||
|
||||
PlayMuzzleFlash();
|
||||
if (hitPoint.transform != null) PlayBulletHitEffectParticle();
|
||||
}
|
||||
|
||||
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>();
|
||||
Debug.Log(hitPoint.transform);
|
||||
|
||||
Vector3 particleSpawnPos = hitPoint.point + hitPoint.normal * 0.01f;
|
||||
Quaternion ParticleRotation = Quaternion.LookRotation(hitPoint.normal);
|
||||
|
||||
if (damageable != null)
|
||||
{
|
||||
ZombieHitEffectParticle.transform.position = particleSpawnPos;
|
||||
ZombieHitEffectParticle.transform.rotation = ParticleRotation;
|
||||
ZombieHitEffectParticle.Play(true);
|
||||
damageable.TakeDamage(10f);
|
||||
}
|
||||
else
|
||||
{
|
||||
BulletHitEffectParticle.transform.position = particleSpawnPos;
|
||||
BulletHitEffectParticle.transform.rotation = Quaternion.LookRotation(hitPoint.normal);
|
||||
BulletHitEffectParticle.Play(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Reload()
|
||||
{
|
||||
AmmoCount = initialAmmoCount;
|
||||
}
|
||||
|
||||
private void PlayMuzzleFlash()
|
||||
{
|
||||
MuzzleFlashParticle.Play(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf22e36737a853040b18d29e45fa59ee
|
||||
Reference in New Issue
Block a user