Steam lobby implemented

This commit is contained in:
Madhav Kapa
2023-06-01 08:03:48 -07:00
parent c7647c8097
commit 49efee80e2
95 changed files with 10258 additions and 6167 deletions

View File

@ -1,64 +1,49 @@
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
using UnityEngine;
public class CameraController : MonoBehaviour
{
//private float mouseX = 0;
//private float mouseY;
[SerializeField]
private Camera cam;
[SerializeField] private Camera cam;
[SerializeField] private Transform target;
[SerializeField]
private Transform target;
private Vector3 offset;
public Vector3 Forward { get; private set; } = Vector3.zero;
private Vector3 forward= Vector3.zero;
private Vector3 right = Vector3.zero;
public Vector3 Forward { get { return this.forward; } }
public Vector3 Right { get { return this.right; } }
public Vector3 Right { get; private set; } = Vector3.zero;
//private float originalDist = 0;
//private float newDist = 0;
//[SerializeField]
// private bool isChild = false;
// private bool isChild = false;
// Start is called before the first frame update
void Start()
private void Start()
{
}
// Update is called once per frame
void Update()
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);
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;
}
}
}

View File

@ -1,61 +1,62 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
using UnityEngine;
public class CameraShift : MonoBehaviour
{
public static CameraShift active;
[SerializeField]
private Camera childCam;
[SerializeField]
private Transform offset;
[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;
[SerializeField]
private float cameraSpeed = 5f;
[SerializeField]
private CinemachineFreeLook freelook;
[SerializeField]
private float initRadius = 3f;
[SerializeField]
private float aimingRadius = 2f;
// Start is called before the first frame update
private void Start()
{
targetOffset = Vector3.zero;
}
// Update is called once per frame
private void Update()
{
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;
}
public void SetCenter(bool isCenter)
{
this.isCenter = isCenter;
}
// Start is called before the first frame update
void Start()
{
targetOffset = Vector3.zero;
}
// Update is called once per frame
void Update()
{
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);
}
}
}

View File

@ -1,72 +1,62 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
public class NoiseVisibilitySettingsManager : MonoBehaviour
{
[SerializeField]
private float sneakNoiseDistance = 5f;
[SerializeField]
private float runNoiseDistance = 10f;
[SerializeField]
private float shootNoiseDistance = 30f;
[SerializeField]
private float standNoiseDistance = 0f;
private float noiseDistance = 0f;
public float SneakNoiseDistance { get { return sneakNoiseDistance; } }
public float RunNoiseDistance { get { return runNoiseDistance; } }
public float ShootNoiseDistance { get { return shootNoiseDistance; } }
public float StandNoiseDistance { get { return standNoiseDistance; } }
[SerializeField] private float sneakNoiseDistance = 5f;
public float NoiseDistance { get { return this.noiseDistance; } }
[SerializeField] private float runNoiseDistance = 10f;
private float timeSinceLastShot = 0f;
[SerializeField]
private float shootNoiseDuration = 2f;
private bool isSneaking = false;
private bool isRunning = false;
[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
void Start()
private void Start()
{
}
// Update is called once per frame
void Update()
private void Update()
{
if (timeSinceLastShot>0)
{
this.noiseDistance = this.shootNoiseDistance;
}
if (timeSinceLastShot > 0)
NoiseDistance = shootNoiseDistance;
else if (isRunning)
{
this.noiseDistance = this.runNoiseDistance;
}else if (isSneaking)
{
this.noiseDistance = this.sneakNoiseDistance;
}
NoiseDistance = runNoiseDistance;
else if (isSneaking)
NoiseDistance = sneakNoiseDistance;
else
{
this.noiseDistance = standNoiseDistance;
}
NoiseDistance = standNoiseDistance;
timeSinceLastShot -= Time.deltaTime;
}
public void ShotFired()
{
this.timeSinceLastShot = this.shootNoiseDuration;
timeSinceLastShot = shootNoiseDuration;
}
public void SetRunning(bool isRunning)
{
this.isRunning = isRunning;
}
public void SetSneaking(bool isSneaking)
{
this.isSneaking= isSneaking;
this.isSneaking = isSneaking;
}
}
}

View File

@ -1,28 +1,24 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerAim : MonoBehaviour
{
public static PlayerAim active;
public Vector3 targetPosition;
private Camera cam;
// Start is called before the first frame update
void Start()
private void Start()
{
active = this;
cam = GetComponent<Camera>();
}
// Update is called once per frame
void Update()
private void Update()
{
Ray r = new Ray(cam.transform.position,cam.transform.forward);
var r = new Ray(cam.transform.position, cam.transform.forward);
RaycastHit hit;
if(Physics.Raycast(r,out hit))
{
targetPosition = hit.point;
}
if (Physics.Raycast(r, out hit)) targetPosition = hit.point;
}
}
}

View File

@ -1,63 +1,91 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerAnimationController : MonoBehaviour
{
[SerializeField]
private Animator animController;
[SerializeField]
private string runningParameter;
[SerializeField]
private string runningSpeedParameter;
[SerializeField]
private string sideStepSpeedParameter;
[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;
private bool isRunning;
//private bool movementInterrupt = false;
[SerializeField]
private PlayerInteractionHandler interactionHandler;
[SerializeField]
private PlayerMovementController movement;
// Start is called before the first frame update
private void Start()
{
}
//private float verticalAiming = 0;
[SerializeField]
private Camera hiddenCam;
// Update is called once per frame
private void Update()
{
animController.SetBool("IsCarrying", interactionHandler.IsCarrying);
animController.SetBool("HasGun", interactionHandler.GunEnabled);
public void Animate(Vector2 movement,bool jump,bool isMoving)
if (interactionHandler.GunEnabled && !interactionHandler.isDead && movement.AllowRotation)
{
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
{
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);
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;
}
else if (movement.x < 0) dir = -1;
animController.SetFloat("StrafingDirection", dir);
}
else
{
animController.SetFloat("StrafingSpeed", 0);
animController.SetFloat("StrafingDirection", 1);
}
}
public void Animate(PlayerQuickAnimationType animation)
{
switch(animation)
switch (animation)
{
case PlayerQuickAnimationType.Grab:
print("grabbing...");
@ -67,57 +95,22 @@ public class PlayerAnimationController : MonoBehaviour
break;
}
}
public void Hit(bool isDead)
{
animController.SetTrigger("WasHit");
animController.SetBool("IsDead", isDead);
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
animController.SetBool("IsCarrying", interactionHandler.IsCarrying);
animController.SetBool("HasGun",interactionHandler.GunEnabled);
if (interactionHandler.GunEnabled&&!interactionHandler.isDead&&movement.AllowRotation)
{
if (hiddenCam.transform.localEulerAngles.x < 90)
{
//DOWN
float 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);
float target = Mathf.Lerp(animController.GetLayerWeight(2), (360f - hiddenCam.transform.localEulerAngles.x) / (360f - 300f),Time.deltaTime*10);
animController.SetLayerWeight(2, target);
}
}
else
{
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 enum PlayerAnimationType {Movement,Action}
public enum PlayerQuickAnimationType { Grab,Shoot}
public enum PlayerAnimationType
{
Movement,
Action
}
public enum PlayerQuickAnimationType
{
Grab,
Shoot
}

View File

@ -1,103 +1,72 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
using TMPro;
using UnityEngine;
public class PlayerComponent : MonoBehaviour
{
[SerializeField]
private float health = 5f;
[SerializeField]
private float maxHealth = 5f;
[SerializeField]
private float stamina = 20f;
[SerializeField]
private float maxStamina = 20f;
[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;
public NoiseVisibilitySettingsManager NoiseManager { get { return this.noiseManager; } }
public PlayerMovementController MovementController { get { return movementController; } }
[SerializeField]
private PlayerAnimationController animationController;
[SerializeField] private PlayerAnimationController animationController;
[HideInInspector]
public FlareRegister flareRegister;
[SerializeField]
private CinemachineFreeLook cameraFreeLook;
private float shakeTimer = 0;
CinemachineBasicMultiChannelPerlin perlin;
[SerializeField]
private float knockbackDuration = 1f;
[SerializeField]
private float knockbackDistance = 5f;
[SerializeField]
private StatsOutputScreen statsOutput;
[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;
[HideInInspector]
public bool IsAlive { get { return this.health > 0; } }
private void Awake()
{
flareRegister = GameObject.FindObjectOfType<FlareRegister>();
flareRegister = FindObjectOfType<FlareRegister>();
}
// Start is called before the first frame update
void Start()
private void Start()
{
perlin = cameraFreeLook.GetRig(1).GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
}
// Update is called once per frame
void Update()
private void Update()
{
NoiseManager.SetRunning(MovementController.IsRunning);
statsOutput.health = this.health;
statsOutput.health = health;
statsOutput.stamina = 20f;
statsOutput.oxygen = 100f;
if (shakeTimer > 0)
{
shakeTimer -= Time.deltaTime;
// perlin.m_AmplitudeGain = 0;
// perlin.m_AmplitudeGain = 0;
perlin.m_AmplitudeGain = Mathf.Lerp(perlin.m_AmplitudeGain, 0, .1f);
if (shakeTimer <= 0f)
{
perlin.m_AmplitudeGain = 0;
}
if (shakeTimer <= 0f) perlin.m_AmplitudeGain = 0;
}
if (!IsAlive)
{
PlayerInteractionHandler.instance.isDead = true;
movementController.isDead = true;
}
}
public void ShakeCamera(float intensity, float time)
{
CinemachineBasicMultiChannelPerlin perlin = cameraFreeLook.GetRig(1).GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
perlin.m_AmplitudeGain= intensity;
shakeTimer = time;
}
public void SetSensitivity(float magnitude)
{
movementController.SetSensitivity(magnitude);
}
public void Damage(float damage,bool applyShake=false)
{
this.health-=damage;
if (applyShake)
{
ShakeCamera(15, 5);
}
}
private void OnTriggerEnter(Collider other)
@ -105,12 +74,31 @@ public class PlayerComponent : MonoBehaviour
if (other.CompareTag("Damaging"))
{
print("HIT!");
MonsterComponent monster = other.GetComponentInParent<MonsterComponent>();
this.Damage(monster.AttackDamage, monster.ShakeCameraOnHit);
animationController.Hit(this.health<=0);
this.movementController.PhysicalForceMove((transform.position - monster.transform.position)*knockbackDistance);
this.movementController.LockMovement(this.knockbackDuration);
var monster = other.GetComponentInParent<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 SetSensitivity(float magnitude)
{
movementController.SetSensitivity(magnitude);
}
public void Damage(float damage, bool applyShake = false)
{
health -= damage;
if (applyShake) ShakeCamera(15, 5);
}
}

View File

@ -1,83 +1,252 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Xml;
using Unity.VisualScripting;
using Unity.VisualScripting.FullSerializer;
using UnityEngine;
[RequireComponent(typeof(Collider))]
public class PlayerInteractionHandler : MonoBehaviour
{
private List<InteractableItem> itemsInRange= new List<InteractableItem>();
private List<HeavyInteractableItem> heavyItemsInRange = new List<HeavyInteractableItem>();
private Inventory invent;
private TempInventory tempInvent;
public Inventory Inventory { get { return invent; } }
public static PlayerInteractionHandler instance;
[SerializeField]
private Light flashlight;
[SerializeField]
private GameObject flashlight3D;
[SerializeField] private Light flashlight;
[SerializeField] private GameObject flashlight3D;
[SerializeField] private int materialIndex = 1;
[SerializeField] private Transform carryingPos;
[SerializeField] private bool useItemSelector = true;
[SerializeField] private PistolComponent pistol;
[SerializeField] private NoiseVisibilitySettingsManager noiseManager;
[SerializeField] private CameraShift shift;
public bool isDead;
//Check if button down
private readonly AxisIsDown fireDown = new("Fire1");
private bool flashlightEnabled = true;
[SerializeField]
private int materialIndex = 1;
private Material selMaterial;
private Color initColor;
private HeavyInteractableItem heavyInvent;
public bool IsCarrying { get { return heavyInvent !=null; } }
public bool GunEnabled { get { return this.gunEnabled; } }
private bool gunEnabled = false;
[SerializeField]
private Transform carryingPos;
public Transform CarryingPos { get { return this.carryingPos; } }
private readonly List<HeavyInteractableItem> heavyItemsInRange = new();
private Color initColor;
private Inventory invent;
private ItemSelector itemSelector;
[SerializeField]
private bool useItemSelector = true;
[SerializeField]
private PistolComponent pistol;
[SerializeField]
private NoiseVisibilitySettingsManager noiseManager;
private readonly List<InteractableItem> itemsInRange = new();
private InGameManager manager;
[SerializeField]
private CameraShift shift;
private Material selMaterial;
private TempInventory tempInvent;
public Inventory Inventory => invent;
public bool IsCarrying => heavyInvent != null;
public bool GunEnabled { get; private set; }
public Transform CarryingPos => carryingPos;
public bool isDead = false;
//Check if button down
private AxisIsDown fireDown = new AxisIsDown("Fire1");
// Start is called before the first frame update
void Start()
private void Start()
{
instance = this;
invent = this.transform.parent.GetComponent<Inventory>();
invent = transform.parent.GetComponent<Inventory>();
//TEMP FIELD
tempInvent = this.transform.parent.GetComponent<TempInventory>();
tempInvent = transform.parent.GetComponent<TempInventory>();
initColor = flashlight3D.GetComponent<MeshRenderer>().materials[materialIndex].GetColor("_BaseColor");
selMaterial = flashlight3D.GetComponent<MeshRenderer>().materials[materialIndex];
itemSelector = ItemSelector.instance;
pistol.gameObject.SetActive(this.gunEnabled);
flashlightEnabled = this.flashlight.gameObject.activeSelf;
manager = GameObject.FindObjectOfType<InGameManager>();
pistol.gameObject.SetActive(GunEnabled);
flashlightEnabled = flashlight.gameObject.activeSelf;
manager = FindObjectOfType<InGameManager>();
}
// Update is called once per frame
private void Update()
{
fireDown.Check();
if (isDead)
{
DropHeavy();
return;
}
if (manager.IsPaused || isDead) return;
if (Input.GetButtonDown("Fire1") || fireDown.IsDown())
{
if (GunEnabled)
{
if (tempInvent.GetQuantityOf(pistol.projectileName) > 0)
{
pistol.Fire();
noiseManager.ShotFired();
tempInvent.Remove(pistol.projectileName);
}
}
else
{
if (!IsCarrying)
{
var t_index = 0;
var pickupFound = false;
if (itemsInRange.Count > 0)
{
while (t_index < itemsInRange.Count && !itemsInRange[t_index].CanPickup) t_index++;
if (t_index != itemsInRange.Count)
{
pickupFound = true;
invent.AddItem(itemsInRange[t_index]);
itemsInRange[0].transform.gameObject.SetActive(false);
itemsInRange.Remove(itemsInRange[t_index]);
}
}
else if (heavyItemsInRange.Count > 0)
{
pickupFound = true;
heavyInvent = heavyItemsInRange[0];
heavyInvent.transform.parent = carryingPos;
heavyInvent.transform.localPosition = Vector3.zero;
heavyInvent.GetComponent<Rigidbody>().isKinematic = true;
heavyItemsInRange.Remove(heavyItemsInRange[0]);
heavyInvent.Disable();
heavyInvent.DisableAll();
}
if (!pickupFound)
foreach (var item in itemsInRange)
if (!item.CanPickup)
{
if (!item.Interact(ref invent, ref heavyInvent))
item.Interact();
else if (item is HeavyItemReceiver)
if (heavyInvent != null)
{
heavyInvent.transform.parent = carryingPos;
heavyInvent.transform.localPosition = Vector3.zero;
heavyInvent.transform.localEulerAngles = Vector3.zero;
heavyItemsInRange.Remove(heavyInvent);
heavyInvent.GetComponent<Rigidbody>().constraints =
RigidbodyConstraints.FreezeRotation;
heavyInvent.GetComponent<Rigidbody>().isKinematic = true;
heavyInvent.Disable();
heavyInvent.DisableAll();
}
}
}
else
{
int refIndex;
if (itemsInRange.Count > 0 && receiverInRange(out refIndex))
{
((HeavyItemReceiver)itemsInRange[refIndex]).Interact(ref invent, ref heavyInvent);
heavyInvent = null;
}
else
{
DropHeavy();
}
}
}
}
if (Input.GetButtonDown("Fire2"))
{
//print(this.GunEnabled);
if (!GunEnabled)
{
if (!flashlight.gameObject.activeSelf)
EnableFlashlight();
else
DisableFlashlight();
}
else
{
pistol.LightToggle();
}
}
if (Input.GetButtonDown("Fire3"))
if (!IsCarrying)
{
GunEnabled = !GunEnabled;
if (!GunEnabled)
pistol.Disable();
pistol.gameObject.SetActive(GunEnabled);
if (GunEnabled)
pistol.Enable();
}
if (GunEnabled)
{
DisableFlashlight();
var aimAxis = Input.GetAxis("Aim");
if (aimAxis > 0.5f)
pistol.aimMode = PistolComponent.AimMode.CAMERA;
else
pistol.aimMode = PistolComponent.AimMode.MODIFIED;
}
shift.SetCenter(!GunEnabled);
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.GetComponent<InteractableItem>() != null)
{
var item = other.gameObject.GetComponent<InteractableItem>();
if (item is InteractableItem && item is not HeavyInteractableItem)
{
item.Enable();
itemsInRange.Add(item);
}
else if (item is HeavyInteractableItem)
{
((HeavyInteractableItem)item).Enable();
heavyItemsInRange.Add((HeavyInteractableItem)item);
}
}
}
private void OnTriggerExit(Collider other)
{
if (other.gameObject.GetComponent<InteractableItem>() != null)
{
var item = other.gameObject.GetComponent<InteractableItem>();
if (item is InteractableItem && item is not HeavyInteractableItem)
{
item.Disable();
itemsInRange.Remove(item);
}
else if (item is HeavyInteractableItem)
{
((HeavyInteractableItem)item).Disable();
//itemsInRange.Remove((HeavyInteractableItem)(item));
heavyItemsInRange.Remove((HeavyInteractableItem)item);
}
}
}
private bool receiverInRange(out int index)
{
int i = 0;
foreach(InteractableItem item in this.itemsInRange)
var i = 0;
foreach (var item in itemsInRange)
{
if(item is HeavyItemReceiver)
if (item is HeavyItemReceiver)
{
index = i;
return true;
}
i++;
}
index = -1;
return false;
}
@ -91,276 +260,57 @@ public class PlayerInteractionHandler : MonoBehaviour
heavyInvent.EnableAll();
heavyInvent = null;
}
}
// Update is called once per frame
void Update()
{
fireDown.Check();
if (this.isDead)
{
DropHeavy();
return;
}
if (manager.IsPaused||isDead)
{
return;
}
if(Input.GetButtonDown("Fire1")||fireDown.IsDown())
{
if (this.GunEnabled)
{
if (tempInvent.GetQuantityOf(this.pistol.projectileName) > 0)
{
this.pistol.Fire();
this.noiseManager.ShotFired();
tempInvent.Remove(this.pistol.projectileName);
}
}
else
{
if (!IsCarrying)
{
int t_index = 0;
bool pickupFound = false;
if (itemsInRange.Count > 0)
{
while (t_index < itemsInRange.Count && !itemsInRange[t_index].CanPickup)
{
t_index++;
}
if (t_index != itemsInRange.Count)
{
pickupFound = true;
invent.AddItem(itemsInRange[t_index]);
itemsInRange[0].transform.gameObject.SetActive(false);
itemsInRange.Remove(itemsInRange[t_index]);
}
}
else if (heavyItemsInRange.Count > 0)
{
pickupFound = true;
heavyInvent = heavyItemsInRange[0];
heavyInvent.transform.parent = carryingPos;
heavyInvent.transform.localPosition = Vector3.zero;
heavyInvent.GetComponent<Rigidbody>().isKinematic = true;
heavyItemsInRange.Remove(heavyItemsInRange[0]);
heavyInvent.Disable();
heavyInvent.DisableAll();
}
if (!pickupFound)
{
foreach (InteractableItem item in itemsInRange)
{
if (!item.CanPickup)
{
if (!item.Interact(ref invent, ref heavyInvent))
{
item.Interact();
}else if(item is HeavyItemReceiver)
{
if(heavyInvent != null)
{
heavyInvent.transform.parent = carryingPos;
heavyInvent.transform.localPosition = Vector3.zero;
heavyInvent.transform.localEulerAngles = Vector3.zero;
heavyItemsInRange.Remove(heavyInvent);
heavyInvent.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation;
heavyInvent.GetComponent<Rigidbody>().isKinematic = true;
heavyInvent.Disable();
heavyInvent.DisableAll();
}
}
}
}
}
}
else
{
int refIndex;
if (itemsInRange.Count > 0&&receiverInRange(out refIndex)) {
((HeavyItemReceiver)itemsInRange[refIndex]).Interact(ref this.invent, ref heavyInvent);
heavyInvent = null;
}
else
{
this.DropHeavy();
}
}
}
}
if (Input.GetButtonDown("Fire2"))
{
//print(this.GunEnabled);
if (!this.GunEnabled)
{
if (!flashlight.gameObject.activeSelf)
{
EnableFlashlight();
}
else
{
DisableFlashlight();
}
}
else
{
this.pistol.LightToggle();
}
}
if (Input.GetButtonDown("Fire3"))
{
if (!this.IsCarrying)
{
this.gunEnabled = !this.gunEnabled;
if(!this.gunEnabled)
pistol.Disable();
pistol.gameObject.SetActive(this.gunEnabled);
if (this.gunEnabled)
pistol.Enable();
}
}
if (this.GunEnabled)
{
this.DisableFlashlight();
float aimAxis = Input.GetAxis("Aim");
if (aimAxis > 0.5f)
{
pistol.aimMode = PistolComponent.AimMode.CAMERA;
}
else
{
pistol.aimMode = PistolComponent.AimMode.MODIFIED;
}
}
else
{
}
shift.SetCenter(!this.GunEnabled);
}
public void EnableFlashlight()
{
flashlight.gameObject.SetActive(true);
flashlight3D.GetComponent<MeshRenderer>().materials[materialIndex].SetColor("_BaseColor", initColor);
selMaterial.SetColor("_EmissionColor", new Color(255, 255, 255, 255));
flashlight3D.gameObject.SetActive(true);
this.flashlightEnabled = true;
flashlightEnabled = true;
}
public void DisableFlashlight()
{
flashlight.gameObject.SetActive(false);
flashlight3D.GetComponent<MeshRenderer>().materials[materialIndex].SetColor("_BaseColor", new Color(0, 0, 0));
selMaterial.SetColor("_EmissionColor", new Color(0, 0, 0, 0));
flashlight3D.gameObject.SetActive(false);
this.flashlightEnabled = false;
}
private void OnTriggerEnter(Collider other)
{
if(other.gameObject.GetComponent<InteractableItem>() != null)
{
InteractableItem item = other.gameObject.GetComponent<InteractableItem>();
if(item is InteractableItem && item is not HeavyInteractableItem)
{
((InteractableItem)item).Enable();
itemsInRange.Add(item);
}else if(item is HeavyInteractableItem)
{
((HeavyInteractableItem)item).Enable();
heavyItemsInRange.Add((HeavyInteractableItem)item);
}
}
}
private void OnTriggerExit(Collider other)
{
if (other.gameObject.GetComponent<InteractableItem>() != null)
{
InteractableItem item = other.gameObject.GetComponent<InteractableItem>();
if (item is InteractableItem && item is not HeavyInteractableItem)
{
((InteractableItem)item).Disable();
itemsInRange.Remove(item);
}
else if (item is HeavyInteractableItem)
{
((HeavyInteractableItem)item).Disable();
//itemsInRange.Remove((HeavyInteractableItem)(item));
heavyItemsInRange.Remove((HeavyInteractableItem)item);
}
}
flashlightEnabled = false;
}
}
class AxisIsDown
internal class AxisIsDown
{
private string axisName;
private bool isDown = false;
private bool pIsDown = false;
private float axis;
private bool down = false;
public void Check()
{
axis = Input.GetAxis(axisName);
isDown = axis > 0.5f;
if (isDown != pIsDown&&isDown)
{
down = true;
}
else
{
down = false;
}
pIsDown = isDown;
}
private readonly string axisName;
private bool down;
private bool isDown;
private bool pIsDown;
public bool IsDown()
{
return this.down;
}
public AxisIsDown(string axisName)
{
this.axisName = axisName;
}
public void Check()
{
axis = Input.GetAxis(axisName);
isDown = axis > 0.5f;
if (isDown != pIsDown && isDown)
down = true;
else
down = false;
pIsDown = isDown;
}
public bool IsDown()
{
return down;
}
}

View File

@ -1,85 +1,116 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
using UnityEngine;
public class PlayerMovementController : MonoBehaviour
{
[SerializeField]
private PlayerAnimationController animcontroller;
[SerializeField] private PlayerAnimationController animcontroller;
private float x = 0;
private float y = 0;
[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 isRunning = false;
private bool isSneaking = false;
public bool IsRunning { get { return isRunning; } }
[SerializeField]
private CharacterController ccontroller;
private CharacterControllerForce ccForceAddon;
[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 = false;
[HideInInspector]
public bool IsAiming = false;
[SerializeField]
private NoiseVisibilitySettingsManager noiseSettings;
private InGameManager manager;
public float NoiseDistance { get { return this.noiseSettings.NoiseDistance; } }
private Vector3 lookingDirectionVector;
private bool movementLocked = false;
[SerializeField]
private CinemachineFreeLook freelook;
private float initXSensitivity = 250f;
private float initYSensitivity = 10f;
[SerializeField]
private string mouseXAxis = "Mouse X";
[SerializeField]
private string mouseYAxis = "Mouse Y";
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()
{
ccForceAddon = ccontroller.gameObject.GetComponent<CharacterControllerForce>();
manager = FindObjectOfType<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 : "";
}
public bool isDead = false;
private void GetMovementOld()
{
x = Input.GetAxis("Horizontal");
y = Input.GetAxis("Vertical");
if (movementLocked||manager.IsPaused)
if (movementLocked || manager.IsPaused)
{
x = 0;
y = 0;
}
isRunning = (Mathf.Abs(y) > 0.1f || Mathf.Abs(x) > 0.1f);
IsRunning = Mathf.Abs(y) > 0.1f || Mathf.Abs(x) > 0.1f;
}
public void SetSensitivity(float sensitivity)
{
this.freelook.m_XAxis.m_MaxSpeed = initXSensitivity * sensitivity;
this.freelook.m_YAxis.m_MaxSpeed= initYSensitivity * sensitivity;
freelook.m_XAxis.m_MaxSpeed = initXSensitivity * sensitivity;
freelook.m_YAxis.m_MaxSpeed = initYSensitivity * sensitivity;
}
private void MovePlayer()
{
Vector3 movement = Vector3.zero;
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 += cam.transform.forward * y * Time.deltaTime * speed;
//movement += transform.forward * Mathf.Abs(x) * Time.deltaTime * speed;
@ -88,9 +119,8 @@ public class PlayerMovementController : MonoBehaviour
else
movement += cam.transform.right * x * Time.deltaTime * sideSpeed;
movement += Vector3.down*Time.deltaTime*9.8f;
movement += Vector3.down * Time.deltaTime * 9.8f;
ccontroller.Move(movement);
}
@ -101,77 +131,33 @@ public class PlayerMovementController : MonoBehaviour
private void GetJumpOld()
{
}
// Start is called before the first frame update
void Start()
private void SlowLookAt(Vector3 targetVector)
{
ccForceAddon = ccontroller.gameObject.GetComponent<CharacterControllerForce>();
manager = GameObject.FindObjectOfType<InGameManager>();
initXSensitivity =freelook.m_XAxis.m_MaxSpeed;
initYSensitivity= freelook.m_YAxis.m_MaxSpeed;
}
var relativePos = targetVector;
var toRotation = Quaternion.LookRotation(relativePos);
// Update is called once per frame
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);
this.lookingDirectionVector = ((cameraController.Forward * y) + cameraController.Right * x).normalized;
if (isRunning && !Input.GetMouseButtonDown(1) || AllowRotation)
{
if (AllowRotation && x == 0 && y == 0 || IsAiming && PlayerInteractionHandler.instance.GunEnabled)
{
this.lookingDirectionVector = cameraController.Forward.normalized;
}
SlowLookAt(this.lookingDirectionVector);
}
freelook.m_XAxis.m_InputAxisName = !manager.IsPaused ? this.mouseXAxis : "";
freelook.m_YAxis.m_InputAxisName = !manager.IsPaused ? this.mouseYAxis : "";
}
void SlowLookAt(Vector3 targetVector)
{
Vector3 relativePos = targetVector;
Quaternion toRotation = Quaternion.LookRotation(relativePos);
transform.rotation = Quaternion.Lerp(transform.rotation, toRotation, animatedRotationSpeed * Time.deltaTime);
}
public void PhysicalForceMove(Vector3 vector)
{
this.ccontroller.Move(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;
}
}
}

View File

@ -1,60 +1,49 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine;
public class StatsOutputScreen : MonoBehaviour
{
[SerializeField]
private TMP_Text healthText;
[SerializeField]
private TMP_Text staminaText;
[SerializeField]
private TMP_Text oxygenText;
[HideInInspector]
public float health = 0;
[HideInInspector]
public float stamina = 0;
[HideInInspector]
public float oxygen = 0;
[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
void Start()
private void Start()
{
initColor = healthText.color;
InvokeRepeating("ToggleColor", 0.5f, 0.5f);
}
// Update is called once per frame
void Update()
private void Update()
{
healthText.text = "Health:" + health.ToString();
healthText.text = "Health:" + health;
if (health <= 1)
{
//Dark Red
healthText.color = new Color(50,0,0);
}
else if (health <=3)
{
healthText.color = new Color(50, 0, 0);
else if (health <= 3)
healthText.color = Color.red;
}
else
{
healthText.color = initColor;
}
staminaText.text = "Stamina:" + stamina.ToString();
oxygenText.text = "Oxygen:"+oxygen.ToString();
staminaText.text = "Stamina:" + stamina;
oxygenText.text = "Oxygen:" + oxygen;
}
private void ToggleColor()
{
if(health<=1)
if (health <= 1)
healthText.gameObject.SetActive(!healthText.gameObject.activeSelf);
}
}
}