The fucking 3rd time i had to upload this project to git
This commit is contained in:
53
Assets/Scripts/Player/Interactions/ConstructMenuItem.cs
Normal file
53
Assets/Scripts/Player/Interactions/ConstructMenuItem.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Player.Interactions
|
||||
{
|
||||
public class ConstructMenuItem
|
||||
{
|
||||
private readonly string desc;
|
||||
private readonly Sprite image;
|
||||
private readonly string name;
|
||||
private readonly GameObject target;
|
||||
|
||||
public ConstructMenuItem(string name, Sprite image, string desc)
|
||||
{
|
||||
this.name = name;
|
||||
this.image = image;
|
||||
this.desc = desc;
|
||||
target = null;
|
||||
}
|
||||
|
||||
public ConstructMenuItem(string name, Sprite image, string desc, GameObject target)
|
||||
{
|
||||
this.name = name;
|
||||
this.image = image;
|
||||
int cost = target.GetComponent<ConstructBase>().GetCost();
|
||||
if (cost == 1)
|
||||
this.desc = desc + "\nCosts " + cost + " Nanite.";
|
||||
else
|
||||
this.desc = desc + "\nCosts " + cost + " Nanites.";
|
||||
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public string GetName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public Sprite GetImage()
|
||||
{
|
||||
return image;
|
||||
}
|
||||
|
||||
public string GetDesc()
|
||||
{
|
||||
return desc;
|
||||
}
|
||||
|
||||
public GameObject GetTarget()
|
||||
{
|
||||
return target;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/Interactions/ConstructMenuItem.cs.meta
Normal file
11
Assets/Scripts/Player/Interactions/ConstructMenuItem.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c019fe381690348c59444c8294aa15d7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
100
Assets/Scripts/Player/Interactions/ConstructSelector.cs
Normal file
100
Assets/Scripts/Player/Interactions/ConstructSelector.cs
Normal file
@ -0,0 +1,100 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using Player.Information;
|
||||
|
||||
namespace Player.Interactions
|
||||
{
|
||||
public class ConstructSelector : MonoBehaviour
|
||||
{
|
||||
public GameObject foodMakerPrefab;
|
||||
public GameObject player;
|
||||
public Sprite foodMakerImage;
|
||||
public GameObject waterMakerPrefab;
|
||||
public Sprite waterMakerImage;
|
||||
public GameObject healthAreaPrefab;
|
||||
public Sprite healthAreaImage;
|
||||
public Image constructImage;
|
||||
public GameObject selectedImage;
|
||||
public GameObject unselectedArrow;
|
||||
|
||||
private readonly List<ConstructMenuItem> choices = new();
|
||||
public TMP_Text constructDesc;
|
||||
|
||||
public TMP_Text constructName;
|
||||
|
||||
private int currentIndex;
|
||||
private int selectedIndex;
|
||||
private PlayerStats playerStats;
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
player = GameObject.FindGameObjectWithTag("Player");
|
||||
playerStats = player.GetComponent<PlayerStats>();
|
||||
choices.Add(new ConstructMenuItem("Nutrient Consolidator", foodMakerImage,
|
||||
"Scrapes nutrients from the ground to make food.\n\nRelies on local biodensity.", foodMakerPrefab));
|
||||
choices.Add(new ConstructMenuItem("Water Condenser", waterMakerImage,
|
||||
"Condenses vapor from the atmosphere to make water.\n\nRelies on local humidity.", waterMakerPrefab));
|
||||
choices.Add(new ConstructMenuItem("Regeneration Field", healthAreaImage,
|
||||
"Distributes nanites onto organisms to repair tissue.\n\nRequires proximity.", healthAreaPrefab));
|
||||
|
||||
currentIndex = 0;
|
||||
selectedIndex = 0;
|
||||
|
||||
RenderPanel();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.LeftArrow) )
|
||||
{
|
||||
currentIndex--;
|
||||
if (currentIndex < 0) currentIndex = choices.Count - 1;
|
||||
|
||||
RenderPanel();
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.RightArrow))
|
||||
{
|
||||
currentIndex++;
|
||||
if (currentIndex >= choices.Count) currentIndex = 0;
|
||||
|
||||
RenderPanel();
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.UpArrow) )
|
||||
{
|
||||
selectedIndex = currentIndex;
|
||||
RenderPanel();
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.DownArrow))
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void RenderPanel()
|
||||
{
|
||||
constructName.SetText(choices[currentIndex].GetName());
|
||||
constructImage.sprite = choices[currentIndex].GetImage();
|
||||
constructDesc.SetText(choices[currentIndex].GetDesc());
|
||||
if (selectedIndex == currentIndex)
|
||||
{
|
||||
selectedImage.SetActive(true);
|
||||
unselectedArrow.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedImage.SetActive(false);
|
||||
unselectedArrow.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
public GameObject GetSelected()
|
||||
{
|
||||
return choices[selectedIndex].GetTarget();
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/Interactions/ConstructSelector.cs.meta
Normal file
11
Assets/Scripts/Player/Interactions/ConstructSelector.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 21a3bcb112beb4f3f8aa38fc58a2c67d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
119
Assets/Scripts/Player/Interactions/GrappleHook.cs
Normal file
119
Assets/Scripts/Player/Interactions/GrappleHook.cs
Normal file
@ -0,0 +1,119 @@
|
||||
using UnityEngine;
|
||||
using Player.Information;
|
||||
namespace Player.Interactions
|
||||
{
|
||||
public class GrappleHook : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float maxGrappleThrow;
|
||||
|
||||
[SerializeField] private float grappleStrength;
|
||||
|
||||
[SerializeField] public float grappledAirControl;
|
||||
|
||||
[SerializeField] private GameObject grapplePointPrefab;
|
||||
|
||||
public bool grappled;
|
||||
|
||||
[SerializeField] private LineRenderer lineRender;
|
||||
public GameObject reticleMaster;
|
||||
private GameObject curPointObj;
|
||||
private Vector3 grapplePos;
|
||||
|
||||
private PlayerStats playerStats;
|
||||
private GameObject reticleClose;
|
||||
|
||||
private GameObject reticleOpen;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
grappled = false;
|
||||
grapplePos = Vector3.zero;
|
||||
lineRender.enabled = false;
|
||||
|
||||
reticleOpen = reticleMaster.transform.Find("Reticle Open").gameObject;
|
||||
reticleClose = reticleMaster.transform.Find("Reticle Close").gameObject;
|
||||
reticleClose.SetActive(false);
|
||||
|
||||
playerStats = gameObject.GetComponent<PlayerStats>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
if (playerStats.grappleEnabled)
|
||||
{
|
||||
if (WouldGrapple())
|
||||
{
|
||||
reticleOpen.SetActive(false);
|
||||
reticleClose.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
reticleOpen.SetActive(true);
|
||||
reticleClose.SetActive(false);
|
||||
}
|
||||
|
||||
if ((Input.GetKeyDown(KeyCode.L) || Input.GetMouseButtonDown(0)) ) ShootGrapple();
|
||||
|
||||
if ((Input.GetKeyDown(KeyCode.K) || Input.GetMouseButtonUp(0)) ) ReleaseGrapple();
|
||||
|
||||
if (grappled)
|
||||
{
|
||||
lineRender.SetPosition(0, gameObject.transform.position);
|
||||
lineRender.SetPosition(1, grapplePos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool WouldGrapple()
|
||||
{
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit,
|
||||
maxGrappleThrow))
|
||||
{
|
||||
TraversalProperties tp = hit.collider.gameObject.GetComponent<TraversalProperties>();
|
||||
if (tp == null || tp.canGrappleOnto) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void ShootGrapple()
|
||||
{
|
||||
// perform a raycast from the player's reticle
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit,
|
||||
maxGrappleThrow))
|
||||
{
|
||||
//Debug.DrawRay(Camera.main.transform.position, hit.point, Color.green, 5f);
|
||||
TraversalProperties tp = hit.collider.gameObject.GetComponent<TraversalProperties>();
|
||||
if (tp == null || tp.canGrappleOnto)
|
||||
{
|
||||
grappled = true;
|
||||
grapplePos = hit.point;
|
||||
if (curPointObj != null) Destroy(curPointObj);
|
||||
|
||||
curPointObj = Instantiate(grapplePointPrefab, hit.point, Quaternion.identity);
|
||||
lineRender.enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ReleaseGrapple()
|
||||
{
|
||||
grappled = false;
|
||||
grapplePos = Vector3.zero;
|
||||
if (curPointObj != null) Destroy(curPointObj);
|
||||
|
||||
lineRender.enabled = false;
|
||||
}
|
||||
|
||||
public Vector3 PullForce(Vector3 playerPos)
|
||||
{
|
||||
if (!grappled)
|
||||
return Vector3.zero;
|
||||
return (grapplePos - playerPos).normalized * grappleStrength;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/Interactions/GrappleHook.cs.meta
Normal file
11
Assets/Scripts/Player/Interactions/GrappleHook.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e7f9353d2ac547538de04c5e5988dd0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
92
Assets/Scripts/Player/Interactions/JetPack.cs
Normal file
92
Assets/Scripts/Player/Interactions/JetPack.cs
Normal file
@ -0,0 +1,92 @@
|
||||
using UnityEngine;
|
||||
using Player.Movement;
|
||||
using Player.Information;
|
||||
|
||||
namespace Player.Interactions
|
||||
{
|
||||
public class JetPack : MonoBehaviour
|
||||
{
|
||||
// in Newtons
|
||||
[SerializeField] private float thrustStrength;
|
||||
|
||||
// in seconds
|
||||
[SerializeField] private float maxLoftTime;
|
||||
|
||||
// in seconds per seconds
|
||||
[SerializeField] private float loftReclaimRate;
|
||||
[SerializeField] private float airLoftReclaimRate;
|
||||
|
||||
// particle system for jetpack
|
||||
[SerializeField] private ParticleSystem flames;
|
||||
|
||||
private bool active;
|
||||
private float loftTime;
|
||||
|
||||
private PlayerPhysics playerPhysics;
|
||||
private PlayerStats playerStats;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
SetActiveThrust(false);
|
||||
loftTime = maxLoftTime;
|
||||
playerPhysics = gameObject.GetComponent<PlayerPhysics>();
|
||||
playerStats = gameObject.GetComponent<PlayerStats>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (playerStats.jetpackEnabled)
|
||||
{
|
||||
if (Input.GetKey(KeyCode.Q) )
|
||||
{
|
||||
if (loftTime > 0f)
|
||||
{
|
||||
SetActiveThrust(true);
|
||||
loftTime = Mathf.Max(0f, loftTime - Time.deltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetActiveThrust(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SetActiveThrust(false);
|
||||
if (loftTime < maxLoftTime)
|
||||
{
|
||||
if (playerPhysics.isGrounded())
|
||||
loftTime = Mathf.Min(maxLoftTime, loftTime + loftReclaimRate * Time.deltaTime);
|
||||
else
|
||||
loftTime = Mathf.Min(maxLoftTime, loftTime + airLoftReclaimRate * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
playerStats.SetThrust(loftTime / maxLoftTime);
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 ThrustForce()
|
||||
{
|
||||
if (active)
|
||||
return new Vector3(0f, thrustStrength, 0f);
|
||||
return Vector3.zero;
|
||||
}
|
||||
|
||||
private void SetActiveThrust(bool state)
|
||||
{
|
||||
active = state;
|
||||
SetEmission(state);
|
||||
}
|
||||
|
||||
private void SetEmission(bool state)
|
||||
{
|
||||
var emission = flames.emission;
|
||||
emission.enabled = state;
|
||||
}
|
||||
|
||||
public void ResetThrust()
|
||||
{
|
||||
loftTime = maxLoftTime;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/Interactions/JetPack.cs.meta
Normal file
11
Assets/Scripts/Player/Interactions/JetPack.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d8d226b0302f94fd38153b488954c2b0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
117
Assets/Scripts/Player/Interactions/PlayerInteractions.cs
Normal file
117
Assets/Scripts/Player/Interactions/PlayerInteractions.cs
Normal file
@ -0,0 +1,117 @@
|
||||
using UnityEngine;
|
||||
using Player.Information;
|
||||
using Player.Interactions;
|
||||
|
||||
public class PlayerInteractions : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float maxInteractDistance = 1f;
|
||||
|
||||
public GameObject selectionMaster;
|
||||
|
||||
public GameObject multiToolModel;
|
||||
|
||||
private ConstructSelector cs;
|
||||
|
||||
private PlayerStats playerStats;
|
||||
private GameObject selectionHolder;
|
||||
private GameObject selectionPrompt;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
playerStats = gameObject.GetComponent<PlayerStats>();
|
||||
//cs.gameObject.SetActive(false);
|
||||
|
||||
selectionHolder = selectionMaster.transform.Find("Selection Holder").gameObject;
|
||||
selectionPrompt = selectionMaster.transform.Find("Selection Prompt").gameObject;
|
||||
cs = selectionHolder.GetComponent<ConstructSelector>();
|
||||
selectionHolder.SetActive(false);
|
||||
multiToolModel.SetActive(false);
|
||||
|
||||
//Screen.fullScreenMode = FullScreenMode.ExclusiveFullScreen;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.R) )
|
||||
{
|
||||
Debug.Log("R Pressed");
|
||||
InteractWithObject();
|
||||
}
|
||||
|
||||
/*
|
||||
if (Input.GetKeyDown(KeyCode.Q))
|
||||
{
|
||||
DisassembleObject();
|
||||
}
|
||||
*/
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.E) )
|
||||
{
|
||||
DisassembleObject();
|
||||
PlaceObject();
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Tab) )
|
||||
{
|
||||
selectionHolder.SetActive(!selectionHolder.activeSelf);
|
||||
selectionPrompt.SetActive(!selectionPrompt.activeSelf);
|
||||
multiToolModel.SetActive(!multiToolModel.activeSelf);
|
||||
}
|
||||
}
|
||||
|
||||
public void InteractWithObject()
|
||||
{
|
||||
RaycastHit hit;
|
||||
Debug.Log("interact");
|
||||
//Debug.DrawRay(Camera.main.transform.position, Camera.main.transform.forward, Color.green, 3f);
|
||||
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit,
|
||||
maxInteractDistance))
|
||||
{
|
||||
Debug.Log(hit.collider.gameObject);
|
||||
//Debug.DrawRay(Camera.main.transform.position, hit.point, Color.green, 5f);
|
||||
if (hit.collider.gameObject.tag == "Construct")
|
||||
{
|
||||
ConstructMaker maker = hit.collider.gameObject.GetComponent<ConstructMaker>();
|
||||
if (maker != null)
|
||||
{
|
||||
float change = maker.Interact();
|
||||
playerStats.ConsumeResource(change, maker.GetResource());
|
||||
}
|
||||
}
|
||||
|
||||
if (hit.collider.gameObject.tag == "Key") hit.collider.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void DisassembleObject()
|
||||
{
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit,
|
||||
maxInteractDistance))
|
||||
if (hit.collider.gameObject.tag == "Construct")
|
||||
{
|
||||
int reward = hit.collider.gameObject.GetComponent<ConstructBase>().Disassemble();
|
||||
playerStats.ChangeNanites(reward);
|
||||
}
|
||||
}
|
||||
|
||||
public void PlaceObject()
|
||||
{
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit,
|
||||
maxInteractDistance))
|
||||
if (Vector3.Normalize(hit.normal) == Vector3.up && hit.collider.gameObject.tag != "Construct")
|
||||
{
|
||||
GameObject selectedConstruct = cs.GetSelected();
|
||||
int cost = selectedConstruct.GetComponent<ConstructBase>().GetCost();
|
||||
if (cost <= playerStats.GetNanites())
|
||||
{
|
||||
var construct = Instantiate(selectedConstruct, hit.point + Vector3.up * 0.3f, Quaternion.identity);
|
||||
playerStats.ChangeNanites(-cost);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c8444a0389c8844a89130facf25837a9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user