namespacing and multiplayer lobby
This commit is contained in:
@ -1,49 +1,51 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraController : MonoBehaviour
|
||||
namespace Player
|
||||
{
|
||||
//private float mouseX = 0;
|
||||
//private float mouseY;
|
||||
[SerializeField] private Camera cam;
|
||||
|
||||
|
||||
[SerializeField] private Transform target;
|
||||
|
||||
private Vector3 offset;
|
||||
public Vector3 Forward { get; private set; } = Vector3.zero;
|
||||
|
||||
public Vector3 Right { get; private set; } = Vector3.zero;
|
||||
|
||||
//private float originalDist = 0;
|
||||
//private float newDist = 0;
|
||||
//[SerializeField]
|
||||
// private bool isChild = false;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
public class CameraController : MonoBehaviour
|
||||
{
|
||||
//private float mouseX = 0;
|
||||
//private float mouseY;
|
||||
[SerializeField] private Camera cam;
|
||||
|
||||
|
||||
[SerializeField] private Transform target;
|
||||
|
||||
private Vector3 offset;
|
||||
public Vector3 Forward { get; private set; } = Vector3.zero;
|
||||
|
||||
public Vector3 Right { get; private set; } = Vector3.zero;
|
||||
|
||||
//private float originalDist = 0;
|
||||
//private float newDist = 0;
|
||||
//[SerializeField]
|
||||
// private bool isChild = false;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
GetMouseLook();
|
||||
//if(target!=null&&!isChild)
|
||||
//transform.position = target.transform.position+offset;
|
||||
Forward = new Vector3(cam.transform.forward.x, target.transform.forward.y, cam.transform.forward.z);
|
||||
Right = new Vector3(cam.transform.right.x, target.transform.right.y, cam.transform.right.z);
|
||||
}
|
||||
|
||||
private void GetMouseLook()
|
||||
{
|
||||
//mouseX = Input.GetAxis("Mouse X");
|
||||
//mouseY = Input.GetAxis("Mouse Y");
|
||||
|
||||
//transform.Rotate(0, mouseX * Time.deltaTime * 180f, 0);
|
||||
//cam.transform.parent.parent.transform.Rotate(mouseY * Time.deltaTime * 180f, 0, 0);
|
||||
|
||||
//Cursor.visible = false;
|
||||
//Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
GetMouseLook();
|
||||
//if(target!=null&&!isChild)
|
||||
//transform.position = target.transform.position+offset;
|
||||
Forward = new Vector3(cam.transform.forward.x, target.transform.forward.y, cam.transform.forward.z);
|
||||
Right = new Vector3(cam.transform.right.x, target.transform.right.y, cam.transform.right.z);
|
||||
}
|
||||
|
||||
private void GetMouseLook()
|
||||
{
|
||||
//mouseX = Input.GetAxis("Mouse X");
|
||||
//mouseY = Input.GetAxis("Mouse Y");
|
||||
|
||||
//transform.Rotate(0, mouseX * Time.deltaTime * 180f, 0);
|
||||
//cam.transform.parent.parent.transform.Rotate(mouseY * Time.deltaTime * 180f, 0, 0);
|
||||
|
||||
//Cursor.visible = false;
|
||||
//Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,62 +1,65 @@
|
||||
using Cinemachine;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraShift : MonoBehaviour
|
||||
namespace Player
|
||||
{
|
||||
public static CameraShift active;
|
||||
|
||||
[SerializeField] private Camera childCam;
|
||||
|
||||
[SerializeField] private Transform offset;
|
||||
|
||||
[SerializeField] private float cameraSpeed = 5f;
|
||||
|
||||
[SerializeField] private CinemachineFreeLook freelook;
|
||||
|
||||
[SerializeField] private float initRadius = 3f;
|
||||
|
||||
[SerializeField] private float aimingRadius = 2f;
|
||||
|
||||
private bool isCenter = true;
|
||||
private Vector3 targetOffset;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
public class CameraShift : MonoBehaviour
|
||||
{
|
||||
targetOffset = Vector3.zero;
|
||||
}
|
||||
public static CameraShift active;
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
active = this;
|
||||
if (isCenter)
|
||||
[SerializeField] private Camera childCam;
|
||||
|
||||
[SerializeField] private Transform offset;
|
||||
|
||||
[SerializeField] private float cameraSpeed = 5f;
|
||||
|
||||
[SerializeField] private CinemachineFreeLook freelook;
|
||||
|
||||
[SerializeField] private float initRadius = 3f;
|
||||
|
||||
[SerializeField] private float aimingRadius = 2f;
|
||||
|
||||
private bool isCenter = true;
|
||||
private Vector3 targetOffset;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
targetOffset = Vector3.zero;
|
||||
freelook.m_Orbits[1].m_Radius =
|
||||
Mathf.Lerp(freelook.m_Orbits[1].m_Radius, initRadius, Time.deltaTime * cameraSpeed);
|
||||
}
|
||||
else
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
targetOffset = offset.localPosition;
|
||||
freelook.m_Orbits[1].m_Radius =
|
||||
Mathf.Lerp(freelook.m_Orbits[1].m_Radius, aimingRadius, Time.deltaTime * cameraSpeed);
|
||||
active = this;
|
||||
if (isCenter)
|
||||
{
|
||||
targetOffset = Vector3.zero;
|
||||
freelook.m_Orbits[1].m_Radius =
|
||||
Mathf.Lerp(freelook.m_Orbits[1].m_Radius, initRadius, Time.deltaTime * cameraSpeed);
|
||||
}
|
||||
else
|
||||
{
|
||||
targetOffset = offset.localPosition;
|
||||
freelook.m_Orbits[1].m_Radius =
|
||||
Mathf.Lerp(freelook.m_Orbits[1].m_Radius, aimingRadius, Time.deltaTime * cameraSpeed);
|
||||
}
|
||||
|
||||
childCam.transform.localPosition =
|
||||
Vector3.Lerp(childCam.transform.localPosition, targetOffset, Time.deltaTime * cameraSpeed);
|
||||
}
|
||||
//[SerializeField]
|
||||
//private PlayerMovementController movementController;
|
||||
|
||||
|
||||
public void ToggleCenter()
|
||||
{
|
||||
isCenter = !isCenter;
|
||||
}
|
||||
|
||||
childCam.transform.localPosition =
|
||||
Vector3.Lerp(childCam.transform.localPosition, targetOffset, Time.deltaTime * cameraSpeed);
|
||||
}
|
||||
//[SerializeField]
|
||||
//private PlayerMovementController movementController;
|
||||
|
||||
|
||||
public void ToggleCenter()
|
||||
{
|
||||
isCenter = !isCenter;
|
||||
}
|
||||
|
||||
public void SetCenter(bool isCenter)
|
||||
{
|
||||
this.isCenter = isCenter;
|
||||
public void SetCenter(bool isCenter)
|
||||
{
|
||||
this.isCenter = isCenter;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,62 +1,65 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class NoiseVisibilitySettingsManager : MonoBehaviour
|
||||
namespace Player
|
||||
{
|
||||
[SerializeField] private float sneakNoiseDistance = 5f;
|
||||
|
||||
[SerializeField] private float runNoiseDistance = 10f;
|
||||
|
||||
[SerializeField] private float shootNoiseDistance = 30f;
|
||||
|
||||
[SerializeField] private float standNoiseDistance;
|
||||
|
||||
[SerializeField] private float shootNoiseDuration = 2f;
|
||||
|
||||
private bool isRunning;
|
||||
private bool isSneaking;
|
||||
|
||||
private float timeSinceLastShot;
|
||||
|
||||
public float SneakNoiseDistance => sneakNoiseDistance;
|
||||
public float RunNoiseDistance => runNoiseDistance;
|
||||
public float ShootNoiseDistance => shootNoiseDistance;
|
||||
public float StandNoiseDistance => standNoiseDistance;
|
||||
|
||||
public float NoiseDistance { get; private set; }
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
public class NoiseVisibilitySettingsManager : MonoBehaviour
|
||||
{
|
||||
}
|
||||
[SerializeField] private float sneakNoiseDistance = 5f;
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
if (timeSinceLastShot > 0)
|
||||
NoiseDistance = shootNoiseDistance;
|
||||
else if (isRunning)
|
||||
NoiseDistance = runNoiseDistance;
|
||||
else if (isSneaking)
|
||||
NoiseDistance = sneakNoiseDistance;
|
||||
else
|
||||
NoiseDistance = standNoiseDistance;
|
||||
[SerializeField] private float runNoiseDistance = 10f;
|
||||
|
||||
timeSinceLastShot -= Time.deltaTime;
|
||||
}
|
||||
[SerializeField] private float shootNoiseDistance = 30f;
|
||||
|
||||
public void ShotFired()
|
||||
{
|
||||
timeSinceLastShot = shootNoiseDuration;
|
||||
}
|
||||
[SerializeField] private float standNoiseDistance;
|
||||
|
||||
public void SetRunning(bool isRunning)
|
||||
{
|
||||
this.isRunning = isRunning;
|
||||
}
|
||||
[SerializeField] private float shootNoiseDuration = 2f;
|
||||
|
||||
public void SetSneaking(bool isSneaking)
|
||||
{
|
||||
this.isSneaking = isSneaking;
|
||||
private bool isRunning;
|
||||
private bool isSneaking;
|
||||
|
||||
private float timeSinceLastShot;
|
||||
|
||||
public float SneakNoiseDistance => sneakNoiseDistance;
|
||||
public float RunNoiseDistance => runNoiseDistance;
|
||||
public float ShootNoiseDistance => shootNoiseDistance;
|
||||
public float StandNoiseDistance => standNoiseDistance;
|
||||
|
||||
public float NoiseDistance { get; private set; }
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
if (timeSinceLastShot > 0)
|
||||
NoiseDistance = shootNoiseDistance;
|
||||
else if (isRunning)
|
||||
NoiseDistance = runNoiseDistance;
|
||||
else if (isSneaking)
|
||||
NoiseDistance = sneakNoiseDistance;
|
||||
else
|
||||
NoiseDistance = standNoiseDistance;
|
||||
|
||||
timeSinceLastShot -= Time.deltaTime;
|
||||
}
|
||||
|
||||
public void ShotFired()
|
||||
{
|
||||
timeSinceLastShot = shootNoiseDuration;
|
||||
}
|
||||
|
||||
public void SetRunning(bool isRunning)
|
||||
{
|
||||
this.isRunning = isRunning;
|
||||
}
|
||||
|
||||
public void SetSneaking(bool isSneaking)
|
||||
{
|
||||
this.isSneaking = isSneaking;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,24 +1,27 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerAim : MonoBehaviour
|
||||
namespace Player
|
||||
{
|
||||
public static PlayerAim active;
|
||||
public Vector3 targetPosition;
|
||||
|
||||
private Camera cam;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
public class PlayerAim : MonoBehaviour
|
||||
{
|
||||
active = this;
|
||||
cam = GetComponent<Camera>();
|
||||
}
|
||||
public static PlayerAim active;
|
||||
public Vector3 targetPosition;
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
var r = new Ray(cam.transform.position, cam.transform.forward);
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(r, out hit)) targetPosition = hit.point;
|
||||
private Camera cam;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
active = this;
|
||||
cam = GetComponent<Camera>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
var r = new Ray(cam.transform.position, cam.transform.forward);
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(r, out hit)) targetPosition = hit.point;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,116 +1,120 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerAnimationController : MonoBehaviour
|
||||
namespace Player
|
||||
{
|
||||
[SerializeField] private Animator animController;
|
||||
|
||||
[SerializeField] private string runningParameter;
|
||||
|
||||
[SerializeField] private string runningSpeedParameter;
|
||||
|
||||
[SerializeField] private string sideStepSpeedParameter;
|
||||
|
||||
//private bool movementInterrupt = false;
|
||||
[SerializeField] private PlayerInteractionHandler interactionHandler;
|
||||
|
||||
[SerializeField] private PlayerMovementController movement;
|
||||
|
||||
//private float verticalAiming = 0;
|
||||
[SerializeField] private Camera hiddenCam;
|
||||
|
||||
private bool isRunning;
|
||||
|
||||
private float runningSpeed;
|
||||
private float sideStepSpeed;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
public class PlayerAnimationController : MonoBehaviour
|
||||
{
|
||||
}
|
||||
[SerializeField] private Animator animController;
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
animController.SetBool("IsCarrying", interactionHandler.IsCarrying);
|
||||
animController.SetBool("HasGun", interactionHandler.GunEnabled);
|
||||
[SerializeField] private string runningParameter;
|
||||
|
||||
if (interactionHandler.GunEnabled && !interactionHandler.isDead && movement.AllowRotation)
|
||||
[SerializeField] private string runningSpeedParameter;
|
||||
|
||||
[SerializeField] private string sideStepSpeedParameter;
|
||||
|
||||
//private bool movementInterrupt = false;
|
||||
[SerializeField] private PlayerInteractionHandler interactionHandler;
|
||||
|
||||
[SerializeField] private PlayerMovementController movement;
|
||||
|
||||
//private float verticalAiming = 0;
|
||||
[SerializeField] private Camera hiddenCam;
|
||||
|
||||
private bool isRunning;
|
||||
|
||||
private float runningSpeed;
|
||||
private float sideStepSpeed;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
if (hiddenCam.transform.localEulerAngles.x < 90)
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
animController.SetBool("IsCarrying", interactionHandler.IsCarrying);
|
||||
animController.SetBool("HasGun", interactionHandler.GunEnabled);
|
||||
|
||||
if (interactionHandler.GunEnabled && !interactionHandler.isDead && movement.AllowRotation)
|
||||
{
|
||||
//DOWN
|
||||
var target = Mathf.Lerp(animController.GetLayerWeight(3), hiddenCam.transform.localEulerAngles.x / 70f,
|
||||
Time.deltaTime * 10f);
|
||||
animController.SetLayerWeight(3, target);
|
||||
animController.SetLayerWeight(2, 0);
|
||||
if (hiddenCam.transform.localEulerAngles.x < 90)
|
||||
{
|
||||
//DOWN
|
||||
var target = Mathf.Lerp(animController.GetLayerWeight(3), hiddenCam.transform.localEulerAngles.x / 70f,
|
||||
Time.deltaTime * 10f);
|
||||
animController.SetLayerWeight(3, target);
|
||||
animController.SetLayerWeight(2, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
//UP
|
||||
animController.SetLayerWeight(3, 0);
|
||||
var target = Mathf.Lerp(animController.GetLayerWeight(2),
|
||||
(360f - hiddenCam.transform.localEulerAngles.x) / (360f - 300f), Time.deltaTime * 10);
|
||||
animController.SetLayerWeight(2, target);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//UP
|
||||
animController.SetLayerWeight(3, 0);
|
||||
var target = Mathf.Lerp(animController.GetLayerWeight(2),
|
||||
(360f - hiddenCam.transform.localEulerAngles.x) / (360f - 300f), Time.deltaTime * 10);
|
||||
animController.SetLayerWeight(2, target);
|
||||
animController.SetLayerWeight(2, Mathf.Lerp(animController.GetLayerWeight(2), 0, Time.deltaTime * 10));
|
||||
animController.SetLayerWeight(3, Mathf.Lerp(animController.GetLayerWeight(3), 0, Time.deltaTime * 10));
|
||||
}
|
||||
|
||||
//print("carrying:" + interactionHandler.IsCarrying + " running:"+animController.GetBool(runningParameter)+" running speed:" + animController.GetFloat(runningSpeedParameter));
|
||||
}
|
||||
|
||||
public void Animate(Vector2 movement, bool jump, bool isMoving)
|
||||
{
|
||||
animController.SetFloat(runningSpeedParameter, movement.magnitude);
|
||||
animController.SetBool(runningParameter, isMoving);
|
||||
|
||||
if (this.movement.IsAiming)
|
||||
{
|
||||
animController.SetFloat("StrafingSpeed", movement.x);
|
||||
float dir = 0;
|
||||
if (movement.x > 0)
|
||||
dir = 1;
|
||||
else if (movement.x < 0) dir = -1;
|
||||
animController.SetFloat("StrafingDirection", dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
animController.SetFloat("StrafingSpeed", 0);
|
||||
animController.SetFloat("StrafingDirection", 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
public void Animate(PlayerQuickAnimationType animation)
|
||||
{
|
||||
animController.SetLayerWeight(2, Mathf.Lerp(animController.GetLayerWeight(2), 0, Time.deltaTime * 10));
|
||||
animController.SetLayerWeight(3, Mathf.Lerp(animController.GetLayerWeight(3), 0, Time.deltaTime * 10));
|
||||
switch (animation)
|
||||
{
|
||||
case PlayerQuickAnimationType.Grab:
|
||||
print("grabbing...");
|
||||
break;
|
||||
case PlayerQuickAnimationType.Shoot:
|
||||
print("shooting...");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//print("carrying:" + interactionHandler.IsCarrying + " running:"+animController.GetBool(runningParameter)+" running speed:" + animController.GetFloat(runningSpeedParameter));
|
||||
public void Hit(bool isDead)
|
||||
{
|
||||
animController.SetTrigger("WasHit");
|
||||
animController.SetBool("IsDead", isDead);
|
||||
}
|
||||
}
|
||||
|
||||
public void Animate(Vector2 movement, bool jump, bool isMoving)
|
||||
public enum PlayerAnimationType
|
||||
{
|
||||
animController.SetFloat(runningSpeedParameter, movement.magnitude);
|
||||
animController.SetBool(runningParameter, isMoving);
|
||||
|
||||
if (this.movement.IsAiming)
|
||||
{
|
||||
animController.SetFloat("StrafingSpeed", movement.x);
|
||||
float dir = 0;
|
||||
if (movement.x > 0)
|
||||
dir = 1;
|
||||
else if (movement.x < 0) dir = -1;
|
||||
animController.SetFloat("StrafingDirection", dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
animController.SetFloat("StrafingSpeed", 0);
|
||||
animController.SetFloat("StrafingDirection", 1);
|
||||
}
|
||||
Movement,
|
||||
Action
|
||||
}
|
||||
|
||||
public void Animate(PlayerQuickAnimationType animation)
|
||||
public enum PlayerQuickAnimationType
|
||||
{
|
||||
switch (animation)
|
||||
{
|
||||
case PlayerQuickAnimationType.Grab:
|
||||
print("grabbing...");
|
||||
break;
|
||||
case PlayerQuickAnimationType.Shoot:
|
||||
print("shooting...");
|
||||
break;
|
||||
}
|
||||
Grab,
|
||||
Shoot
|
||||
}
|
||||
|
||||
public void Hit(bool isDead)
|
||||
{
|
||||
animController.SetTrigger("WasHit");
|
||||
animController.SetBool("IsDead", isDead);
|
||||
}
|
||||
}
|
||||
|
||||
public enum PlayerAnimationType
|
||||
{
|
||||
Movement,
|
||||
Action
|
||||
}
|
||||
|
||||
public enum PlayerQuickAnimationType
|
||||
{
|
||||
Grab,
|
||||
Shoot
|
||||
}
|
@ -1,104 +1,107 @@
|
||||
using Cinemachine;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerComponent : MonoBehaviour
|
||||
namespace Player
|
||||
{
|
||||
[SerializeField] private float health = 5f;
|
||||
|
||||
[SerializeField] private float maxHealth = 5f;
|
||||
|
||||
[SerializeField] private float stamina = 20f;
|
||||
|
||||
[SerializeField] private float maxStamina = 20f;
|
||||
|
||||
[SerializeField] private NoiseVisibilitySettingsManager noiseManager;
|
||||
[SerializeField] private PlayerMovementController movementController;
|
||||
|
||||
[SerializeField] private PlayerAnimationController animationController;
|
||||
|
||||
[HideInInspector] public FlareRegister flareRegister;
|
||||
|
||||
[SerializeField] private CinemachineFreeLook cameraFreeLook;
|
||||
|
||||
[SerializeField] private float knockbackDuration = 1f;
|
||||
|
||||
[SerializeField] private float knockbackDistance = 5f;
|
||||
|
||||
[SerializeField] private StatsOutputScreen statsOutput;
|
||||
|
||||
private CinemachineBasicMultiChannelPerlin perlin;
|
||||
private float shakeTimer;
|
||||
|
||||
public NoiseVisibilitySettingsManager NoiseManager => noiseManager;
|
||||
public PlayerMovementController MovementController => movementController;
|
||||
|
||||
[HideInInspector] public bool IsAlive => health > 0;
|
||||
|
||||
private void Awake()
|
||||
public class PlayerComponent : MonoBehaviour
|
||||
{
|
||||
flareRegister = FindObjectOfType<FlareRegister>();
|
||||
}
|
||||
[SerializeField] private float health = 5f;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
perlin = cameraFreeLook.GetRig(1).GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
||||
}
|
||||
[SerializeField] private float maxHealth = 5f;
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
NoiseManager.SetRunning(MovementController.IsRunning);
|
||||
statsOutput.health = health;
|
||||
statsOutput.stamina = 20f;
|
||||
statsOutput.oxygen = 100f;
|
||||
[SerializeField] private float stamina = 20f;
|
||||
|
||||
if (shakeTimer > 0)
|
||||
[SerializeField] private float maxStamina = 20f;
|
||||
|
||||
[SerializeField] private NoiseVisibilitySettingsManager noiseManager;
|
||||
[SerializeField] private PlayerMovementController movementController;
|
||||
|
||||
[SerializeField] private PlayerAnimationController animationController;
|
||||
|
||||
[HideInInspector] public FlareRegister flareRegister;
|
||||
|
||||
[SerializeField] private CinemachineFreeLook cameraFreeLook;
|
||||
|
||||
[SerializeField] private float knockbackDuration = 1f;
|
||||
|
||||
[SerializeField] private float knockbackDistance = 5f;
|
||||
|
||||
[SerializeField] private StatsOutputScreen statsOutput;
|
||||
|
||||
private CinemachineBasicMultiChannelPerlin perlin;
|
||||
private float shakeTimer;
|
||||
|
||||
public NoiseVisibilitySettingsManager NoiseManager => noiseManager;
|
||||
public PlayerMovementController MovementController => movementController;
|
||||
|
||||
[HideInInspector] public bool IsAlive => health > 0;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
shakeTimer -= Time.deltaTime;
|
||||
|
||||
// perlin.m_AmplitudeGain = 0;
|
||||
perlin.m_AmplitudeGain = Mathf.Lerp(perlin.m_AmplitudeGain, 0, .1f);
|
||||
if (shakeTimer <= 0f) perlin.m_AmplitudeGain = 0;
|
||||
flareRegister = FindObjectOfType<FlareRegister>();
|
||||
}
|
||||
|
||||
if (!IsAlive)
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
PlayerInteractionHandler.instance.isDead = true;
|
||||
movementController.isDead = true;
|
||||
perlin = cameraFreeLook.GetRig(1).GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.CompareTag("Damaging"))
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
print("HIT!");
|
||||
var monster = other.GetComponentInParent<MonsterComponent>();
|
||||
NoiseManager.SetRunning(MovementController.IsRunning);
|
||||
statsOutput.health = health;
|
||||
statsOutput.stamina = 20f;
|
||||
statsOutput.oxygen = 100f;
|
||||
|
||||
Damage(monster.AttackDamage, monster.ShakeCameraOnHit);
|
||||
animationController.Hit(health <= 0);
|
||||
movementController.PhysicalForceMove((transform.position - monster.transform.position) * knockbackDistance);
|
||||
movementController.LockMovement(knockbackDuration);
|
||||
if (shakeTimer > 0)
|
||||
{
|
||||
shakeTimer -= Time.deltaTime;
|
||||
|
||||
// perlin.m_AmplitudeGain = 0;
|
||||
perlin.m_AmplitudeGain = Mathf.Lerp(perlin.m_AmplitudeGain, 0, .1f);
|
||||
if (shakeTimer <= 0f) perlin.m_AmplitudeGain = 0;
|
||||
}
|
||||
|
||||
if (!IsAlive)
|
||||
{
|
||||
PlayerInteractionHandler.instance.isDead = true;
|
||||
movementController.isDead = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.CompareTag("Damaging"))
|
||||
{
|
||||
print("HIT!");
|
||||
var monster = other.GetComponentInParent<Enemy.MonsterComponent>();
|
||||
|
||||
Damage(monster.AttackDamage, monster.ShakeCameraOnHit);
|
||||
animationController.Hit(health <= 0);
|
||||
movementController.PhysicalForceMove((transform.position - monster.transform.position) * knockbackDistance);
|
||||
movementController.LockMovement(knockbackDuration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void ShakeCamera(float intensity, float time)
|
||||
{
|
||||
var perlin = cameraFreeLook.GetRig(1).GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
||||
perlin.m_AmplitudeGain = intensity;
|
||||
shakeTimer = time;
|
||||
}
|
||||
public void ShakeCamera(float intensity, float time)
|
||||
{
|
||||
var perlin = cameraFreeLook.GetRig(1).GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
||||
perlin.m_AmplitudeGain = intensity;
|
||||
shakeTimer = time;
|
||||
}
|
||||
|
||||
public void SetSensitivity(float magnitude)
|
||||
{
|
||||
movementController.SetSensitivity(magnitude);
|
||||
}
|
||||
public void SetSensitivity(float magnitude)
|
||||
{
|
||||
movementController.SetSensitivity(magnitude);
|
||||
}
|
||||
|
||||
public void Damage(float damage, bool applyShake = false)
|
||||
{
|
||||
health -= damage;
|
||||
if (applyShake) ShakeCamera(15, 5);
|
||||
public void Damage(float damage, bool applyShake = false)
|
||||
{
|
||||
health -= damage;
|
||||
if (applyShake) ShakeCamera(15, 5);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Player
|
||||
{
|
||||
|
||||
|
||||
[RequireComponent(typeof(Collider))]
|
||||
public class PlayerInteractionHandler : MonoBehaviour
|
||||
{
|
||||
@ -36,7 +40,7 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
private ItemSelector itemSelector;
|
||||
private readonly List<InteractableItem> itemsInRange = new();
|
||||
|
||||
private InGameManager manager;
|
||||
private Game.InGameManager manager;
|
||||
private Material selMaterial;
|
||||
private TempInventory tempInvent;
|
||||
public Inventory Inventory => invent;
|
||||
@ -58,7 +62,7 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
itemSelector = ItemSelector.instance;
|
||||
pistol.gameObject.SetActive(GunEnabled);
|
||||
flashlightEnabled = flashlight.gameObject.activeSelf;
|
||||
manager = FindObjectOfType<InGameManager>();
|
||||
manager = FindObjectOfType<Game.InGameManager>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@ -313,4 +317,6 @@ internal class AxisIsDown
|
||||
{
|
||||
return down;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -2,162 +2,166 @@ using System.Collections;
|
||||
using Cinemachine;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerMovementController : MonoBehaviour
|
||||
namespace Player
|
||||
{
|
||||
[SerializeField] private PlayerAnimationController animcontroller;
|
||||
|
||||
[SerializeField] private CharacterController ccontroller;
|
||||
|
||||
[SerializeField] private CameraController cameraController;
|
||||
|
||||
[SerializeField] private float speed = 1f;
|
||||
|
||||
[SerializeField] private float sideSpeed = 0.5f;
|
||||
|
||||
[SerializeField] private float animatedRotationSpeed = 5f;
|
||||
|
||||
[SerializeField] public Camera cam;
|
||||
|
||||
[HideInInspector] public bool AllowRotation;
|
||||
|
||||
[HideInInspector] public bool IsAiming;
|
||||
|
||||
[SerializeField] private NoiseVisibilitySettingsManager noiseSettings;
|
||||
|
||||
[SerializeField] private CinemachineFreeLook freelook;
|
||||
|
||||
[SerializeField] private string mouseXAxis = "Mouse X";
|
||||
|
||||
[SerializeField] private string mouseYAxis = "Mouse Y";
|
||||
|
||||
public bool isDead;
|
||||
private CharacterControllerForce ccForceAddon;
|
||||
private float initXSensitivity = 250f;
|
||||
|
||||
private float initYSensitivity = 10f;
|
||||
//private float mouseX = 0;
|
||||
|
||||
private bool isSneaking = false;
|
||||
|
||||
|
||||
private Vector3 lookingDirectionVector;
|
||||
|
||||
private InGameManager manager;
|
||||
|
||||
private bool movementLocked;
|
||||
|
||||
private float x;
|
||||
private float y;
|
||||
public bool IsRunning { get; private set; }
|
||||
|
||||
|
||||
public float NoiseDistance => noiseSettings.NoiseDistance;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
public class PlayerMovementController : MonoBehaviour
|
||||
{
|
||||
ccForceAddon = ccontroller.gameObject.GetComponent<CharacterControllerForce>();
|
||||
manager = FindObjectOfType<InGameManager>();
|
||||
initXSensitivity = freelook.m_XAxis.m_MaxSpeed;
|
||||
initYSensitivity = freelook.m_YAxis.m_MaxSpeed;
|
||||
}
|
||||
[SerializeField] private PlayerAnimationController animcontroller;
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
if (isDead) return;
|
||||
AllowRotation = IsAiming || IsRunning;
|
||||
IsAiming = Input.GetMouseButton(1) || Input.GetAxis("Aim") > 0.5f;
|
||||
GetMovementOld();
|
||||
MovePlayer();
|
||||
[SerializeField] private CharacterController ccontroller;
|
||||
|
||||
animcontroller.Animate(new Vector2(x, y), false, IsRunning);
|
||||
[SerializeField] private CameraController cameraController;
|
||||
|
||||
lookingDirectionVector = (cameraController.Forward * y + cameraController.Right * x).normalized;
|
||||
if ((IsRunning && !Input.GetMouseButtonDown(1)) || AllowRotation)
|
||||
[SerializeField] private float speed = 1f;
|
||||
|
||||
[SerializeField] private float sideSpeed = 0.5f;
|
||||
|
||||
[SerializeField] private float animatedRotationSpeed = 5f;
|
||||
|
||||
[SerializeField] public Camera cam;
|
||||
|
||||
[HideInInspector] public bool AllowRotation;
|
||||
|
||||
[HideInInspector] public bool IsAiming;
|
||||
|
||||
[SerializeField] private NoiseVisibilitySettingsManager noiseSettings;
|
||||
|
||||
[SerializeField] private CinemachineFreeLook freelook;
|
||||
|
||||
[SerializeField] private string mouseXAxis = "Mouse X";
|
||||
|
||||
[SerializeField] private string mouseYAxis = "Mouse Y";
|
||||
|
||||
public bool isDead;
|
||||
private CharacterControllerForce ccForceAddon;
|
||||
private float initXSensitivity = 250f;
|
||||
|
||||
private float initYSensitivity = 10f;
|
||||
//private float mouseX = 0;
|
||||
|
||||
private bool isSneaking = false;
|
||||
|
||||
|
||||
private Vector3 lookingDirectionVector;
|
||||
|
||||
private Game.InGameManager manager;
|
||||
|
||||
private bool movementLocked;
|
||||
|
||||
private float x;
|
||||
private float y;
|
||||
public bool IsRunning { get; private set; }
|
||||
|
||||
|
||||
public float NoiseDistance => noiseSettings.NoiseDistance;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
ccForceAddon = ccontroller.gameObject.GetComponent<CharacterControllerForce>();
|
||||
manager = FindObjectOfType<Game.InGameManager>();
|
||||
initXSensitivity = freelook.m_XAxis.m_MaxSpeed;
|
||||
initYSensitivity = freelook.m_YAxis.m_MaxSpeed;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
if (isDead) return;
|
||||
AllowRotation = IsAiming || IsRunning;
|
||||
IsAiming = Input.GetMouseButton(1) || Input.GetAxis("Aim") > 0.5f;
|
||||
GetMovementOld();
|
||||
MovePlayer();
|
||||
|
||||
animcontroller.Animate(new Vector2(x, y), false, IsRunning);
|
||||
|
||||
lookingDirectionVector = (cameraController.Forward * y + cameraController.Right * x).normalized;
|
||||
if ((IsRunning && !Input.GetMouseButtonDown(1)) || AllowRotation)
|
||||
{
|
||||
if ((AllowRotation && x == 0 && y == 0) || (IsAiming && PlayerInteractionHandler.instance.GunEnabled))
|
||||
lookingDirectionVector = cameraController.Forward.normalized;
|
||||
SlowLookAt(lookingDirectionVector);
|
||||
}
|
||||
|
||||
|
||||
freelook.m_XAxis.m_InputAxisName = !manager.IsPaused ? mouseXAxis : "";
|
||||
freelook.m_YAxis.m_InputAxisName = !manager.IsPaused ? mouseYAxis : "";
|
||||
}
|
||||
|
||||
private void GetMovementOld()
|
||||
{
|
||||
x = Input.GetAxis("Horizontal");
|
||||
y = Input.GetAxis("Vertical");
|
||||
if (movementLocked || manager.IsPaused)
|
||||
{
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
|
||||
IsRunning = Mathf.Abs(y) > 0.1f || Mathf.Abs(x) > 0.1f;
|
||||
}
|
||||
|
||||
public void SetSensitivity(float sensitivity)
|
||||
{
|
||||
freelook.m_XAxis.m_MaxSpeed = initXSensitivity * sensitivity;
|
||||
freelook.m_YAxis.m_MaxSpeed = initYSensitivity * sensitivity;
|
||||
}
|
||||
|
||||
private void MovePlayer()
|
||||
{
|
||||
var movement = Vector3.zero;
|
||||
//movement += transform.forward * Mathf.Abs(y) * Time.deltaTime * speed;//+(transform.right*x*Time.deltaTime*speed);
|
||||
movement += cam.transform.forward * y * Time.deltaTime * speed;
|
||||
|
||||
//movement += transform.forward * Mathf.Abs(x) * Time.deltaTime * speed;
|
||||
|
||||
if (!IsAiming)
|
||||
movement += cam.transform.right * x * Time.deltaTime * speed;
|
||||
else
|
||||
movement += cam.transform.right * x * Time.deltaTime * sideSpeed;
|
||||
|
||||
|
||||
movement += Vector3.down * Time.deltaTime * 9.8f;
|
||||
ccontroller.Move(movement);
|
||||
}
|
||||
|
||||
public void SetSpeed(float speed)
|
||||
{
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
private void GetJumpOld()
|
||||
{
|
||||
if ((AllowRotation && x == 0 && y == 0) || (IsAiming && PlayerInteractionHandler.instance.GunEnabled))
|
||||
lookingDirectionVector = cameraController.Forward.normalized;
|
||||
SlowLookAt(lookingDirectionVector);
|
||||
}
|
||||
|
||||
|
||||
freelook.m_XAxis.m_InputAxisName = !manager.IsPaused ? mouseXAxis : "";
|
||||
freelook.m_YAxis.m_InputAxisName = !manager.IsPaused ? mouseYAxis : "";
|
||||
}
|
||||
|
||||
private void GetMovementOld()
|
||||
{
|
||||
x = Input.GetAxis("Horizontal");
|
||||
y = Input.GetAxis("Vertical");
|
||||
if (movementLocked || manager.IsPaused)
|
||||
private void SlowLookAt(Vector3 targetVector)
|
||||
{
|
||||
x = 0;
|
||||
y = 0;
|
||||
var relativePos = targetVector;
|
||||
var toRotation = Quaternion.LookRotation(relativePos);
|
||||
|
||||
transform.rotation = Quaternion.Lerp(transform.rotation, toRotation, animatedRotationSpeed * Time.deltaTime);
|
||||
}
|
||||
|
||||
IsRunning = Mathf.Abs(y) > 0.1f || Mathf.Abs(x) > 0.1f;
|
||||
}
|
||||
|
||||
public void SetSensitivity(float sensitivity)
|
||||
{
|
||||
freelook.m_XAxis.m_MaxSpeed = initXSensitivity * sensitivity;
|
||||
freelook.m_YAxis.m_MaxSpeed = initYSensitivity * sensitivity;
|
||||
}
|
||||
public void PhysicalForceMove(Vector3 vector)
|
||||
{
|
||||
ccontroller.Move(vector);
|
||||
ccForceAddon.AddImpact(vector, vector.magnitude);
|
||||
}
|
||||
|
||||
private void MovePlayer()
|
||||
{
|
||||
var movement = Vector3.zero;
|
||||
//movement += transform.forward * Mathf.Abs(y) * Time.deltaTime * speed;//+(transform.right*x*Time.deltaTime*speed);
|
||||
movement += cam.transform.forward * y * Time.deltaTime * speed;
|
||||
public void LockMovement(float duration)
|
||||
{
|
||||
StartCoroutine(lockMovement(duration));
|
||||
}
|
||||
|
||||
//movement += transform.forward * Mathf.Abs(x) * Time.deltaTime * speed;
|
||||
|
||||
if (!IsAiming)
|
||||
movement += cam.transform.right * x * Time.deltaTime * speed;
|
||||
else
|
||||
movement += cam.transform.right * x * Time.deltaTime * sideSpeed;
|
||||
|
||||
|
||||
movement += Vector3.down * Time.deltaTime * 9.8f;
|
||||
ccontroller.Move(movement);
|
||||
}
|
||||
|
||||
public void SetSpeed(float speed)
|
||||
{
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
private void GetJumpOld()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
private void SlowLookAt(Vector3 targetVector)
|
||||
{
|
||||
var relativePos = targetVector;
|
||||
var toRotation = Quaternion.LookRotation(relativePos);
|
||||
|
||||
transform.rotation = Quaternion.Lerp(transform.rotation, toRotation, animatedRotationSpeed * Time.deltaTime);
|
||||
}
|
||||
|
||||
|
||||
public void PhysicalForceMove(Vector3 vector)
|
||||
{
|
||||
ccontroller.Move(vector);
|
||||
ccForceAddon.AddImpact(vector, vector.magnitude);
|
||||
}
|
||||
|
||||
public void LockMovement(float duration)
|
||||
{
|
||||
StartCoroutine(lockMovement(duration));
|
||||
}
|
||||
|
||||
private IEnumerator lockMovement(float duration)
|
||||
{
|
||||
movementLocked = true;
|
||||
yield return new WaitForSeconds(duration);
|
||||
movementLocked = false;
|
||||
private IEnumerator lockMovement(float duration)
|
||||
{
|
||||
movementLocked = true;
|
||||
yield return new WaitForSeconds(duration);
|
||||
movementLocked = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,49 +1,52 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class StatsOutputScreen : MonoBehaviour
|
||||
namespace Player
|
||||
{
|
||||
[SerializeField] private TMP_Text healthText;
|
||||
|
||||
[SerializeField] private TMP_Text staminaText;
|
||||
|
||||
[SerializeField] private TMP_Text oxygenText;
|
||||
|
||||
[HideInInspector] public float health;
|
||||
|
||||
[HideInInspector] public float stamina;
|
||||
|
||||
[HideInInspector] public float oxygen;
|
||||
|
||||
private Color initColor;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
public class StatsOutputScreen : MonoBehaviour
|
||||
{
|
||||
initColor = healthText.color;
|
||||
InvokeRepeating("ToggleColor", 0.5f, 0.5f);
|
||||
[SerializeField] private TMP_Text healthText;
|
||||
|
||||
[SerializeField] private TMP_Text staminaText;
|
||||
|
||||
[SerializeField] private TMP_Text oxygenText;
|
||||
|
||||
[HideInInspector] public float health;
|
||||
|
||||
[HideInInspector] public float stamina;
|
||||
|
||||
[HideInInspector] public float oxygen;
|
||||
|
||||
private Color initColor;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
initColor = healthText.color;
|
||||
InvokeRepeating("ToggleColor", 0.5f, 0.5f);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
healthText.text = "Health:" + health;
|
||||
|
||||
if (health <= 1)
|
||||
//Dark Red
|
||||
healthText.color = new Color(50, 0, 0);
|
||||
else if (health <= 3)
|
||||
healthText.color = Color.red;
|
||||
else
|
||||
healthText.color = initColor;
|
||||
|
||||
staminaText.text = "Stamina:" + stamina;
|
||||
oxygenText.text = "Oxygen:" + oxygen;
|
||||
}
|
||||
|
||||
private void ToggleColor()
|
||||
{
|
||||
if (health <= 1)
|
||||
healthText.gameObject.SetActive(!healthText.gameObject.activeSelf);
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
healthText.text = "Health:" + health;
|
||||
|
||||
if (health <= 1)
|
||||
//Dark Red
|
||||
healthText.color = new Color(50, 0, 0);
|
||||
else if (health <= 3)
|
||||
healthText.color = Color.red;
|
||||
else
|
||||
healthText.color = initColor;
|
||||
|
||||
staminaText.text = "Stamina:" + stamina;
|
||||
oxygenText.text = "Oxygen:" + oxygen;
|
||||
}
|
||||
|
||||
private void ToggleColor()
|
||||
{
|
||||
if (health <= 1)
|
||||
healthText.gameObject.SetActive(!healthText.gameObject.activeSelf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user