first push 2

This commit is contained in:
2023-03-13 19:59:59 -04:00
commit bb3e31030b
744 changed files with 123827 additions and 0 deletions

View File

@ -0,0 +1,57 @@
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 Transform target;
private Vector3 offset;
private Vector3 forward= Vector3.zero;
private Vector3 right = Vector3.zero;
public Vector3 Forward { get { return this.forward; } }
public Vector3 Right { get { return this.right; } }
private float originalDist = 0;
private float newDist = 0;
[SerializeField]
private bool isChild = false;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
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;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3847c9aa2dda4d64f84842c3cc880d7e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,60 @@
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;
private float runningSpeed;
private float sideStepSpeed;
private bool isRunning;
private bool movementInterrupt = false;
[SerializeField]
private PlayerInteractionHandler interactionHandler;
public void Animate(Vector2 movement,bool jump,bool isMoving)
{
animController.SetFloat(runningSpeedParameter, movement.magnitude);
animController.SetBool(runningParameter,isMoving);
//animController.SetFloat(sideStepSpeedParameter, movement.x);
}
public void Animate(PlayerQuickAnimationType animation)
{
switch(animation)
{
case PlayerQuickAnimationType.Grab:
print("grabbing...");
break;
case PlayerQuickAnimationType.Shoot:
print("shooting...");
break;
}
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
animController.SetBool("IsCarrying", interactionHandler.IsCarrying);
}
}
public enum PlayerAnimationType {Movement,Action}
public enum PlayerQuickAnimationType { Grab,Shoot}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cabfb8d71f6bc7041830b669859f203a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,117 @@
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Unity.VisualScripting;
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;
[SerializeField]
private Light flashlight;
[SerializeField]
private GameObject flashlight3D;
[SerializeField]
private int materialIndex = 1;
private Material selMaterial;
private Color initColor;
private HeavyInteractableItem heavyInvent;
public bool IsCarrying { get { return heavyInvent !=null; } }
[SerializeField]
private Transform carryingPos;
// Start is called before the first frame update
void Start()
{
invent = this.transform.parent.GetComponent<Inventory>();
initColor = flashlight3D.GetComponent<MeshRenderer>().materials[materialIndex].GetColor("_BaseColor");
selMaterial = flashlight3D.GetComponent<MeshRenderer>().materials[materialIndex];
}
// Update is called once per frame
void Update()
{
//
if(Input.GetButtonDown("Fire1"))
{
if(itemsInRange.Count > 0)
{
invent.AddItem(itemsInRange[0]);
itemsInRange[0].transform.gameObject.SetActive(false);
itemsInRange.Remove(itemsInRange[0]);
}
else if(heavyItemsInRange.Count > 0)
{
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 (Input.GetButtonDown("Fire2"))
{
flashlight.gameObject.SetActive(!flashlight.gameObject.activeSelf);
if (flashlight.gameObject.activeSelf)
{
flashlight3D.GetComponent<MeshRenderer>().materials[materialIndex].SetColor("_BaseColor", initColor);
selMaterial.SetColor("_EmissionColor", new Color(0, 0, 0, 0));
flashlight3D.gameObject.SetActive(true);
}
else
{
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);
}
}
}
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);
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cc1d606aab4ac0841954339b67bc1fb4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,88 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovementController : MonoBehaviour
{
[SerializeField]
private PlayerAnimationController animcontroller;
private float x = 0;
private float y = 0;
private float mouseX = 0;
private bool isRunning = false;
[SerializeField]
private CharacterController ccontroller;
[SerializeField]
private CameraController cameraController;
[SerializeField]
private float speed = 1f;
[SerializeField]
private float sideSpeed = 0.5f;
[SerializeField]
private float animatedRotationSpeed = 5f;
private Vector3 lookingDirectionVector;
private void GetMovementOld()
{
x = Input.GetAxis("Horizontal");
y = Input.GetAxis("Vertical");
isRunning = (Mathf.Abs(y) > 0.1f || Mathf.Abs(x) > 0.1f);
}
private void MovePlayer()
{
Vector3 movement = Vector3.zero;
movement += transform.forward * Mathf.Abs(y) * Time.deltaTime * speed;//+(transform.right*x*Time.deltaTime*speed);
//movement += transform.right * Mathf.Abs(x) * Time.deltaTime * sideSpeed;
movement += transform.forward * Mathf.Abs(x) * Time.deltaTime * speed;
ccontroller.Move(movement);
}
public void SetSpeed(float speed)
{
this.speed = speed;
}
private void GetJumpOld()
{
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
GetMovementOld();
MovePlayer();
animcontroller.Animate(new Vector2(x, y), false,isRunning);
this.lookingDirectionVector = ((cameraController.Forward * y) + cameraController.Right * x).normalized;
if (isRunning && !Input.GetMouseButton(1))
{
SlowLookAt(this.lookingDirectionVector);
}
}
void SlowLookAt(Vector3 targetVector)
{
Vector3 relativePos = targetVector;
Quaternion toRotation = Quaternion.LookRotation(relativePos);
transform.rotation = Quaternion.Lerp(transform.rotation, toRotation, animatedRotationSpeed * Time.deltaTime);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 04d9fbdb37200704a9166659474a658a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: