Initial commit
This commit is contained in:
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:
|
||||
30
Assets/Darkmatter/Code/Presentation/Player/Gun.cs
Normal file
30
Assets/Darkmatter/Code/Presentation/Player/Gun.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Darkmatter/Code/Presentation/Player/Gun.cs.meta
Normal file
2
Assets/Darkmatter/Code/Presentation/Player/Gun.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c3f99ff473a5f474099e6dd5f8dcde78
|
||||
148
Assets/Darkmatter/Code/Presentation/Player/PlayerMotor.cs
Normal file
148
Assets/Darkmatter/Code/Presentation/Player/PlayerMotor.cs
Normal file
@@ -0,0 +1,148 @@
|
||||
using Darkmatter.Core;
|
||||
using Darkmatter.Domain;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
public class PlayerMotor : MonoBehaviour, IPlayerPawn
|
||||
{
|
||||
|
||||
[Header("LookSetting")]
|
||||
public Camera mainCamera { get; private set; }
|
||||
public Transform cinemachineFollowTarget;
|
||||
|
||||
[Header("MoveSetting")]
|
||||
public CharacterController characterController;
|
||||
|
||||
[Header("GravitySetting")]
|
||||
private float verticalVelocity;
|
||||
public bool isGrounded => IsOnGround();
|
||||
|
||||
[Header("GroundCheckSensorSetting")]
|
||||
public float groundOffset;
|
||||
public float groundCheckRadius;
|
||||
public LayerMask groundLayer;
|
||||
|
||||
[Header("TurnSetting")]
|
||||
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 Gun gun;
|
||||
public float fireRate = 0.1f;
|
||||
float nextFiretime=0;
|
||||
|
||||
|
||||
[Inject] private IInputReader inputReader;
|
||||
[Inject] private PlayerConfigSO playerConfig;
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
if(animator==null) animator = GetComponent<Animator>();
|
||||
mainCamera = Camera.main;
|
||||
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
//HandleAim();
|
||||
HandleShooting();
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
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)
|
||||
{
|
||||
nextFiretime = Time.time + fireRate;
|
||||
gun.Init(muzzlePos.position, aim.position);
|
||||
}
|
||||
}
|
||||
|
||||
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.y = 0; //
|
||||
Quaternion targetRot = Quaternion.LookRotation(aimDir);
|
||||
transform.rotation = Quaternion.Slerp(transform.rotation, targetRot, Time.deltaTime * turnSpeed);
|
||||
}
|
||||
|
||||
|
||||
//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);
|
||||
HandleAim();
|
||||
//transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0,yaw,0), Time.deltaTime*turnSpeed);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0dd0478b6c34c674aa4378c3ad35088f
|
||||
Reference in New Issue
Block a user