Assemblies Made and Refactored Code Folders
Created assemblies for the new design code. Relocated legacy scripts into a legacy folder and made a "new_design" folder for new design.
This commit is contained in:
53
Assets/Scripts/Legacy/Player/CameraController.cs
Normal file
53
Assets/Scripts/Legacy/Player/CameraController.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using UnityEngine;
|
||||
using FishNet.Object;
|
||||
using FishNet.Connection;
|
||||
|
||||
namespace Player
|
||||
{
|
||||
public class CameraController : NetworkBehaviour
|
||||
{
|
||||
//private float mouseX = 0;
|
||||
//private float mouseY;
|
||||
public 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;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Legacy/Player/CameraController.cs.meta
Normal file
11
Assets/Scripts/Legacy/Player/CameraController.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3847c9aa2dda4d64f84842c3cc880d7e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
65
Assets/Scripts/Legacy/Player/CameraShift.cs
Normal file
65
Assets/Scripts/Legacy/Player/CameraShift.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using Cinemachine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Player
|
||||
{
|
||||
public class CameraShift : MonoBehaviour
|
||||
{
|
||||
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()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Legacy/Player/CameraShift.cs.meta
Normal file
11
Assets/Scripts/Legacy/Player/CameraShift.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4d2cf1ca1f9d2e64e98d70fb574f0316
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
32
Assets/Scripts/Legacy/Player/EmoteHandler.cs
Normal file
32
Assets/Scripts/Legacy/Player/EmoteHandler.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Player
|
||||
{
|
||||
public class EmoteHandler : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Animator anim;
|
||||
[SerializeField]
|
||||
private string[] animations;
|
||||
[SerializeField]
|
||||
private int emoteNum = 0;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
PlayEmote();
|
||||
}
|
||||
public void PlayEmote()
|
||||
{
|
||||
anim.Play(animations[emoteNum]);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/Legacy/Player/EmoteHandler.cs.meta
Normal file
11
Assets/Scripts/Legacy/Player/EmoteHandler.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d59be853e517db4f9cb7269206d056f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Legacy/Player/LobbyPlayer.meta
Normal file
8
Assets/Scripts/Legacy/Player/LobbyPlayer.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9b6514adc0f89c7449476a228cc73b3f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,23 @@
|
||||
using UnityEngine;
|
||||
namespace Player
|
||||
{
|
||||
public class LobbyPlayerComponent : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Animator anim;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
anim.SetBool("IsRunning", false);
|
||||
anim.SetFloat("RunningSpeed", 0);
|
||||
anim.Play("CryopodIdle");
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f67362ec8cfc5994da72072fd900eeba
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,67 @@
|
||||
using FishNet.Object;
|
||||
using FishNet.Connection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Player
|
||||
{
|
||||
public class NoiseVisibilitySettingsManager : NetworkBehaviour
|
||||
{
|
||||
[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()
|
||||
{
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
[ServerRpc]
|
||||
public void ShotFired()
|
||||
{
|
||||
timeSinceLastShot = shootNoiseDuration;
|
||||
}
|
||||
|
||||
public void SetRunning(bool isRunning)
|
||||
{
|
||||
this.isRunning = isRunning;
|
||||
}
|
||||
|
||||
public void SetSneaking(bool isSneaking)
|
||||
{
|
||||
this.isSneaking = isSneaking;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1179093e6fa69e045838868718a12c58
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
27
Assets/Scripts/Legacy/Player/PlayerAim.cs
Normal file
27
Assets/Scripts/Legacy/Player/PlayerAim.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Player
|
||||
{
|
||||
public class PlayerAim : MonoBehaviour
|
||||
{
|
||||
public static PlayerAim active;
|
||||
public Vector3 targetPosition;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Legacy/Player/PlayerAim.cs.meta
Normal file
11
Assets/Scripts/Legacy/Player/PlayerAim.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d0634141320a06b4f94b506dbed94499
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
120
Assets/Scripts/Legacy/Player/PlayerAnimationController.cs
Normal file
120
Assets/Scripts/Legacy/Player/PlayerAnimationController.cs
Normal file
@ -0,0 +1,120 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Player
|
||||
{
|
||||
|
||||
public class PlayerAnimationController : MonoBehaviour
|
||||
{
|
||||
[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;
|
||||
public Camera hiddenCam;
|
||||
|
||||
private bool isRunning;
|
||||
|
||||
private float runningSpeed;
|
||||
private float sideStepSpeed;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public void Animate(PlayerQuickAnimationType animation)
|
||||
{
|
||||
switch (animation)
|
||||
{
|
||||
case PlayerQuickAnimationType.Grab:
|
||||
print("grabbing...");
|
||||
break;
|
||||
case PlayerQuickAnimationType.Shoot:
|
||||
print("shooting...");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Hit(bool isDead)
|
||||
{
|
||||
animController.SetTrigger("WasHit");
|
||||
animController.SetBool("IsDead", isDead);
|
||||
}
|
||||
}
|
||||
|
||||
public enum PlayerAnimationType
|
||||
{
|
||||
Movement,
|
||||
Action
|
||||
}
|
||||
|
||||
public enum PlayerQuickAnimationType
|
||||
{
|
||||
Grab,
|
||||
Shoot
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cabfb8d71f6bc7041830b669859f203a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
126
Assets/Scripts/Legacy/Player/PlayerComponent.cs
Normal file
126
Assets/Scripts/Legacy/Player/PlayerComponent.cs
Normal file
@ -0,0 +1,126 @@
|
||||
using Cinemachine;
|
||||
using FishNet.Object;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Player
|
||||
{
|
||||
public class PlayerComponent : NetworkBehaviour
|
||||
{
|
||||
[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 Item.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;
|
||||
[SerializeField]
|
||||
private Scriptable.GameSettings settings;
|
||||
|
||||
[HideInInspector] public bool IsAlive => health > 0;
|
||||
|
||||
public override void OnStartClient()
|
||||
{
|
||||
base.OnStartClient();
|
||||
if (base.IsOwner)
|
||||
{
|
||||
cameraFreeLook = GameObject.Find("CM vcam1").GetComponent<CinemachineFreeLook>();
|
||||
}
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
flareRegister = FindObjectOfType<Item.FlareRegister>();
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
perlin = cameraFreeLook.GetRig(1).GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
||||
settings.OnValueChange.AddListener(OnSettingChange);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
NoiseManager.SetRunning(MovementController.IsRunning);
|
||||
statsOutput.health = health;
|
||||
statsOutput.stamina = 20f;
|
||||
statsOutput.oxygen = 100f;
|
||||
|
||||
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 OnSettingChange(Scriptable.GameSettings.SettingModification mod, float value)
|
||||
{
|
||||
if(mod == Scriptable.GameSettings.SettingModification.Sensitivity)
|
||||
{
|
||||
SetSensitivity(value);
|
||||
}
|
||||
}
|
||||
public void SetSensitivity(float magnitude)
|
||||
{
|
||||
movementController.SetSensitivity(magnitude);
|
||||
}
|
||||
|
||||
public void Damage(float damage, bool applyShake = false)
|
||||
{
|
||||
health -= damage;
|
||||
if (applyShake) ShakeCamera(15, 5);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Legacy/Player/PlayerComponent.cs.meta
Normal file
11
Assets/Scripts/Legacy/Player/PlayerComponent.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 86fd72b889d47804e844e0bc9c04218d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
352
Assets/Scripts/Legacy/Player/PlayerInteractionHandler.cs
Normal file
352
Assets/Scripts/Legacy/Player/PlayerInteractionHandler.cs
Normal file
@ -0,0 +1,352 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using FishNet.Connection;
|
||||
using FishNet.Object;
|
||||
|
||||
namespace Player
|
||||
{
|
||||
|
||||
[RequireComponent(typeof(Collider))]
|
||||
public class PlayerInteractionHandler : NetworkBehaviour
|
||||
{
|
||||
public static PlayerInteractionHandler instance;
|
||||
|
||||
[SerializeField] private Light flashlight;
|
||||
|
||||
[SerializeField] private GameObject flashlight3D;
|
||||
|
||||
[SerializeField] private int materialIndex = 1;
|
||||
|
||||
[SerializeField] private Transform carryingPos;
|
||||
|
||||
[SerializeField] private bool useItemSelector = true;
|
||||
|
||||
[SerializeField] private Item.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;
|
||||
|
||||
private Item.HeavyInteractableItem heavyInvent;
|
||||
private readonly List<Item.HeavyInteractableItem> heavyItemsInRange = new();
|
||||
private Color initColor;
|
||||
private Item.Inventory invent;
|
||||
|
||||
private Item.ItemSelector itemSelector;
|
||||
private readonly List<Item.InteractableItem> itemsInRange = new();
|
||||
[SerializeField]
|
||||
private Scriptable.GameState manager;
|
||||
private Material selMaterial;
|
||||
private Item.TempInventory tempInvent;
|
||||
public Item.Inventory Inventory => invent;
|
||||
public bool IsCarrying => heavyInvent != null;
|
||||
public bool GunEnabled { get; private set; }
|
||||
|
||||
|
||||
public Transform CarryingPos => carryingPos;
|
||||
private bool inputEnbaled = true;
|
||||
|
||||
public override void OnStartClient()
|
||||
{
|
||||
base.OnStartClient();
|
||||
inputEnbaled = IsOwner;
|
||||
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
instance = this;
|
||||
invent = transform.parent.GetComponent<Item.Inventory>();
|
||||
//TEMP FIELD
|
||||
tempInvent = transform.parent.GetComponent<Item.TempInventory>();
|
||||
|
||||
initColor = flashlight3D.GetComponent<MeshRenderer>().materials[materialIndex].GetColor("_BaseColor");
|
||||
selMaterial = flashlight3D.GetComponent<MeshRenderer>().materials[materialIndex];
|
||||
itemSelector = Item.ItemSelector.instance;
|
||||
pistol.gameObject.SetActive(GunEnabled);
|
||||
flashlightEnabled = flashlight.gameObject.activeSelf;
|
||||
shift = GameObject.Find("CameraHidden").GetComponent<CameraShift>();
|
||||
|
||||
}
|
||||
|
||||
[ObserversRpc]
|
||||
public void SwitchWeaponMode()
|
||||
{
|
||||
|
||||
GunEnabled = !GunEnabled;
|
||||
if (!GunEnabled)
|
||||
pistol.Disable();
|
||||
pistol.gameObject.SetActive(GunEnabled);
|
||||
if (GunEnabled)
|
||||
pistol.Enable();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
fireDown.Check();
|
||||
if (isDead)
|
||||
{
|
||||
DropHeavy();
|
||||
return;
|
||||
}
|
||||
|
||||
if ((manager.IsPaused || isDead)&&!inputEnbaled) return;
|
||||
|
||||
if ((Input.GetButtonDown("Fire1") || fireDown.IsDown())&&inputEnbaled)
|
||||
{
|
||||
if (GunEnabled)
|
||||
{
|
||||
if (tempInvent.GetQuantityOf(pistol.projectileName) > 0)
|
||||
{
|
||||
print("Calling RPC:Fire(). Isclient:" + IsClient);
|
||||
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 Item.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))
|
||||
{
|
||||
((Item.HeavyItemReceiver)itemsInRange[refIndex]).Interact(ref invent, ref heavyInvent);
|
||||
heavyInvent = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
DropHeavy();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Input.GetButtonDown("Fire2")&&inputEnbaled)
|
||||
{
|
||||
//print(this.GunEnabled);
|
||||
if (!GunEnabled)
|
||||
{
|
||||
if (!flashlight.gameObject.activeSelf)
|
||||
EnableFlashlight();
|
||||
else
|
||||
DisableFlashlight();
|
||||
}
|
||||
else
|
||||
{
|
||||
pistol.LightToggle();
|
||||
}
|
||||
}
|
||||
|
||||
if (Input.GetButtonDown("Fire3")&&inputEnbaled)
|
||||
if (!IsCarrying)
|
||||
{
|
||||
|
||||
SwitchWeaponMode();
|
||||
if (false) {
|
||||
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 = Item.PistolComponent.AimMode.CAMERA;
|
||||
else
|
||||
pistol.aimMode = Item.PistolComponent.AimMode.MODIFIED;
|
||||
}
|
||||
if(!inputEnbaled)
|
||||
shift.SetCenter(!GunEnabled);
|
||||
}
|
||||
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.gameObject.GetComponent<Item.InteractableItem>() != null)
|
||||
{
|
||||
var item = other.gameObject.GetComponent<Item.InteractableItem>();
|
||||
if (item is Item.InteractableItem && item is not Item.HeavyInteractableItem)
|
||||
{
|
||||
item.Enable();
|
||||
itemsInRange.Add(item);
|
||||
}
|
||||
else if (item is Item.HeavyInteractableItem)
|
||||
{
|
||||
((Item.HeavyInteractableItem)item).Enable();
|
||||
heavyItemsInRange.Add((Item.HeavyInteractableItem)item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
if (other.gameObject.GetComponent<Item.InteractableItem>() != null)
|
||||
{
|
||||
var item = other.gameObject.GetComponent<Item.InteractableItem>();
|
||||
if (item is Item.InteractableItem && item is not Item.HeavyInteractableItem)
|
||||
{
|
||||
item.Disable();
|
||||
itemsInRange.Remove(item);
|
||||
}
|
||||
else if (item is Item.HeavyInteractableItem)
|
||||
{
|
||||
((Item.HeavyInteractableItem)item).Disable();
|
||||
//itemsInRange.Remove((HeavyInteractableItem)(item));
|
||||
heavyItemsInRange.Remove((Item.HeavyInteractableItem)item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool receiverInRange(out int index)
|
||||
{
|
||||
var i = 0;
|
||||
foreach (var item in itemsInRange)
|
||||
{
|
||||
if (item is Item.HeavyItemReceiver)
|
||||
{
|
||||
index = i;
|
||||
return true;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
index = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
private void DropHeavy()
|
||||
{
|
||||
if (heavyInvent != null)
|
||||
{
|
||||
heavyInvent.transform.parent = null;
|
||||
heavyInvent.GetComponent<Rigidbody>().isKinematic = false;
|
||||
heavyInvent.EnableAll();
|
||||
heavyInvent = null;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
flashlightEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal class AxisIsDown
|
||||
{
|
||||
private float axis;
|
||||
|
||||
|
||||
private readonly string axisName;
|
||||
|
||||
private bool down;
|
||||
private bool isDown;
|
||||
private bool pIsDown;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc1d606aab4ac0841954339b67bc1fb4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
196
Assets/Scripts/Legacy/Player/PlayerMovementController.cs
Normal file
196
Assets/Scripts/Legacy/Player/PlayerMovementController.cs
Normal file
@ -0,0 +1,196 @@
|
||||
using System.Collections;
|
||||
using Cinemachine;
|
||||
using UnityEngine;
|
||||
using FishNet.Object;
|
||||
using FishNet.Connection;
|
||||
|
||||
namespace Player
|
||||
{
|
||||
|
||||
public class PlayerMovementController : NetworkBehaviour
|
||||
{
|
||||
[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;
|
||||
|
||||
private GameObject camObject;
|
||||
|
||||
[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;
|
||||
[SerializeField]
|
||||
private Scriptable.GameState manager;
|
||||
|
||||
|
||||
private bool movementLocked;
|
||||
|
||||
private float x;
|
||||
private float y;
|
||||
public bool IsRunning { get; private set; }
|
||||
|
||||
|
||||
public float NoiseDistance => noiseSettings.NoiseDistance;
|
||||
|
||||
public override void OnStartClient()
|
||||
{
|
||||
base.OnStartClient();
|
||||
if (base.IsOwner)
|
||||
{
|
||||
cam = GameObject.Find("CameraHidden").GetComponent<Camera>();
|
||||
camObject = GameObject.Find("CM vcam1");
|
||||
Debug.Log("Setting camera for " + transform.GetChild(0).GetChild(2).name + "with camera " + camObject.name);
|
||||
camObject.GetComponent<CinemachineFreeLook>().Follow = transform;
|
||||
camObject.GetComponent<CinemachineFreeLook>().LookAt = transform.GetChild(0).GetChild(2);
|
||||
transform.GetChild(0).GetComponent<PlayerAnimationController>().hiddenCam = cam;
|
||||
transform.GetChild(0).GetChild(2).GetComponent<CameraController>().cam = cam;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
|
||||
ccForceAddon = ccontroller.gameObject.GetComponent<CharacterControllerForce>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets called by PlayerComponent to change sensitivity.
|
||||
/// </summary>
|
||||
/// <param name="sensitivity"></param>
|
||||
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()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 04d9fbdb37200704a9166659474a658a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
52
Assets/Scripts/Legacy/Player/StatsOutputScreen.cs
Normal file
52
Assets/Scripts/Legacy/Player/StatsOutputScreen.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Player
|
||||
{
|
||||
public class StatsOutputScreen : MonoBehaviour
|
||||
{
|
||||
[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);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Legacy/Player/StatsOutputScreen.cs.meta
Normal file
11
Assets/Scripts/Legacy/Player/StatsOutputScreen.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de7389d71ec7803409f26fc6407bc153
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user