Merge branch 'base-world' into Inventory

This commit is contained in:
janis
2022-02-15 17:51:16 +01:00
344 changed files with 27514 additions and 9148 deletions
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 07d6479e8a097a442b09bd078512c8e3
guid: 80e82d2274387fd4da6a9680e81c9e06
PrefabImporter:
externalObjects: {}
userData:
+23267 -2813
View File
File diff suppressed because it is too large Load Diff
+44
View File
@@ -0,0 +1,44 @@
using UnityEngine;
/// <summary>
/// <c>Harvestable</c> represents the base class of all harvestable objects in the scene and inherits of "Interactable.cs"
/// </summary>
public abstract class Harvestable : Interactable
{
[Header("Harvestable Properties")]
[Tooltip("The time for how long the object needs to be harvested.")]
[Range(0.1f, 99.9f)]
[SerializeField]
float harvestDuration = 3f;
float harvestTime = 0f;// time for how long the player already "harvested" the object
/// <summary>
/// <c>IncreaseHarvestTime</c> increases the harvestTime by Time.deltaTime.
/// <code>harvestTime += Time.deltaTime;</code>
/// </summary>
public void IncreaseHarvestTime() => harvestTime += Time.deltaTime;
/// <summary>
/// <c>ResetHarvestTime</c><strong> resets the harvestTime to 0f.</strong>
/// </summary>
public void ResetHarvestTime() => harvestTime = 0f;
/// <summary>
/// <c>GetHarvestTime</c> gets the time for how long the player has already "harvested".
/// </summary>
/// <returns><strong>A float of the time for how long the player has already "harvested"</strong></returns>
public float GetHarvestTime() => harvestTime;
/// <summary>
/// <c>GetHarvestTimeLeft</c> gets the time for how long a player still has to "harvest".
/// </summary>
/// <returns>A float containig the result of <strong>harvestDuration - harvestTime</strong></returns>
public float GetHarvestTimeLeft() => harvestDuration - harvestTime;
/// <summary>
/// <c>GetHarvestDuration</c> gets the time for how long the object needs to be harvested until the interact method triggers.
/// </summary>
/// <returns><strong>A float of the time for how long the object needs to be harvested until the interact method triggers</strong></returns>
public float GetHarvestDuration() => harvestDuration;
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 05a54d359a6f37f4096b2163dcfeaaea
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+94 -9
View File
@@ -1,29 +1,112 @@
using UnityEngine;
// Represents the base class for all interactable objects in the scene
/// <summary>
/// <c>Interactable</c> represents the base class of all interactable objects in the scene
/// </summary>
public abstract class Interactable : MonoBehaviour
{
/// <summary>
/// <c>InteractinType</c> is the type of an interaction. So the "PlayerInteractin.cs" can handle the interaction input.
///
/// <list type="bullet">
/// <item>Click: A single click which triggers the Interact Method</item>
/// <item>Hold: Holding a until time is reached an then triggers the Interact Method(Time resets if the Player stops holding)</item>
/// <item>Harvest: Same as Hold but time does not reset. So the time progress gets saved. Used for class "Harvastable.cs"</item>
/// </list>
/// </summary>
public enum InteractionType {
Click,
Hold
Hold,
Harvest
}
float holdTime;
[Header("Interactable Properties")]
public InteractionType interactionType;
[Tooltip("The time the player has to hold until the Interact method triggers.")]
[Range(0.1f, 99.9f)]
[SerializeField]
float holdDuration = 1f; // The time the player has to hold until the Interact method triggers
float holdTime; // The time for how long the player has already pressed
// Used to measure the distance between the player and the object
Transform playerTransform;
Transform interactableTransform;
public InteractionType interactionType;
public float radius = 3f;
[Tooltip("The range in which the player can interact with an object")]
[Range(1f, 50f)]
[SerializeField]
float radius = 3f;
#region GETTER
/// <summary>
/// <c>GetDescription</c> gets the description of an interactable object.
/// <list type="bullet">
/// <item>The description is usally used to display a help text for the player (e.g. "Turn Lights On")</item>
/// </list>
/// </summary>
/// <returns><strong>A string containing the description of the interactable object</strong></returns>
public abstract string GetDescription();
/// <summary>
/// <c>GetHoldTime</c> gets the time for how long the player has already pressed.
/// </summary>
/// <returns><strong>A float of the time for how long the player has already pressed</strong></returns>
public float GetHoldTime() => holdTime;
/// <summary>
/// <c>GetHoldDuration</c> gets the time the player has to hold until the Interact method triggers.
/// </summary>
/// <returns><strong>A float of the time the player has to hold until the Interact method triggers</strong></returns>
public float GetHoldDuration() => holdDuration;
/// <summary>
/// <c>GetHoldTimeLeft</c> gets the time for how long a player still has to hold.
/// </summary>
/// <returns>A float containig the result of <strong>holdDuration - holdTime</strong></returns>
public float GetHoldTimeLeft() => holdDuration - holdTime;
/// <summary>
/// <c>GetRadius</c> gets the maximum distance of a player is allowed to have in order to interact with an object.
/// </summary>
/// <returns><strong>A float containing the interaction distance</strong></returns>
public float GetRadius() => radius;
#endregion
/// <summary>
/// <c>Interact</c> is the method which gets called when a player start the interaction with an object.
///
/// <list type="bullet">
/// <item>If the player clicks on an object</item>
/// <item>If the holdTime is greater or equals the holdDuration</item>
/// <item>If the harvestTime is greater or equals the harvestDuration</item>
/// </list>
///
/// It usually gets called in the "PlayerInteraction.cs"
/// </summary>
public abstract void Interact();
/// <summary>
/// <c>IncreaseHoldTime</c> increases the holdTime by Time.deltaTime.
/// <code>holdTime += Time.deltaTime;</code>
/// </summary>
public void IncreaseHoldTime() => holdTime += Time.deltaTime;
/// <summary>
/// <c>ResetHoldTime</c><strong> resets the holdTime to 0f.</strong>
/// </summary>
public void ResetHoldTime() => holdTime = 0f;
public float GetHoldTime() => holdTime;
/// <summary>
/// <c>isInRange</c> checks if the player is in the interaction range of an interactable object.
///
/// <list type="bullet">
/// <item><strong>True</strong>: Player is in range</item>
/// <item><strong>False</strong>: Player is NOT in range</item>
/// </list>
/// </summary>
/// <returns>A bool which says if the player is in the interaction range of an interactable object</returns>
public bool isInRange()
{
playerTransform = GameObject.FindGameObjectWithTag("Player").gameObject.transform; // Maybe singleton later?
@@ -41,6 +124,8 @@ public abstract class Interactable : MonoBehaviour
}
// Show interactable range in editor but NOT IN-GAME
private void OnDrawGizmosSelected()
{
// Gizmos are only visible in the scene view -> NOT visible IN-GAME (DEBUG Reasons)
+36 -6
View File
@@ -1,10 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
public class PlayerInteraction : MonoBehaviour
{
public TMPro.TextMeshProUGUI interactionText;
[SerializeField]
TextMeshProUGUI interactionText;
[SerializeField]
Image interactionProgressImg;
void Update()
{
@@ -21,37 +26,49 @@ public class PlayerInteraction : MonoBehaviour
HandleInteraction(interactable);
successfulHit = true;
HandleInteractionText(interactable);
HandleInteractionProgress(interactable);
}
}
if (!successfulHit)
{
interactionText.text = "";
interactionProgressImg.fillAmount = 0;
}
}
void HandleInteractionProgress(Interactable interactable)
{
interactionProgressImg.fillAmount = interactable.GetHoldTime() / interactable.GetHoldDuration();
}
void HandleInteractionText(Interactable interactable)
{
interactionText.text = interactable.GetDescription();
interactionText.transform.position = new Vector3(Input.mousePosition.x + interactionText.rectTransform.sizeDelta.x / 2 + 20, Input.mousePosition.y - 5, Input.mousePosition.z);
}
/// <summary>
/// <c>HandleInteraction</c> <strong>handles the player interaction based on the Interactable.InteractionType.</strong>
/// </summary>
/// <param name="interactable"></param>
void HandleInteraction(Interactable interactable)
{
switch (interactable.interactionType)
{
case Interactable.InteractionType.Click:
if (Input.GetButtonDown("Interact"))
if (Input.GetButtonDown("Interact") && interactable.isInRange())
{
interactable.Interact();
}
break;
case Interactable.InteractionType.Hold:
if (Input.GetButton("Interact"))
if (Input.GetButton("Interact") && interactable.isInRange())
{
interactable.IncreaseHoldTime();
if(interactable.GetHoldTime() > 1f)
if(interactable.GetHoldTime() > interactable.GetHoldDuration())
{
interactable.Interact();
interactable.ResetHoldTime();
@@ -62,6 +79,19 @@ public class PlayerInteraction : MonoBehaviour
interactable.ResetHoldTime();
}
break;
case Interactable.InteractionType.Harvest:
Harvestable harvestable = interactable.GetComponent<Harvestable>();
if (Input.GetButton("Interact") && interactable.isInRange())
{
harvestable.IncreaseHarvestTime();
if (harvestable.GetHarvestTime() >= harvestable.GetHarvestDuration())
{
harvestable.Interact();
}
}
break;
default:
throw new System.Exception("Unsupported type of interactable");
}
+22
View File
@@ -0,0 +1,22 @@
using UnityEngine;
using UnityEngine.Rendering.Universal;
public class TestLight : Interactable
{
[Header("Test Light Properties")]
[SerializeField] Color color;
[SerializeField] Light2D globalLight;
public override string GetDescription()
{
if (isInRange())
return "Turn Light " + gameObject.name;
else
return "Light switch not in range";
}
public override void Interact()
{
globalLight.color = color;
Debug.Log("Color set to " + gameObject.name);
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9cfe123230b3a464da8006f1a53a48e8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+4 -8
View File
@@ -1,21 +1,17 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TreeInteraction : Interactable
public class TreeInteraction : Harvestable
{
public override string GetDescription()
{
if (isInRange())
return "Baum muss schreien";
return "Baum muss weg";
else
return "Tree is not in range";
}
public override void Interact()
{
if (isInRange())
Debug.Log("AaaaaaaaaaAaAAaAaAAaAaAaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
else
Debug.Log("Tree is not in range");
Debug.Log("Harvest BAUM");
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b205d63b9ee71664f9c7fa23f1d96b95
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 797173bae0ed1654fa07465013c23f18
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Before

Width:  |  Height:  |  Size: 53 KiB

After

Width:  |  Height:  |  Size: 53 KiB

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: a43babfa671545f4bb61621b601e432a
guid: c32f559dee2aeb14bb94c92c61d0bf64
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: b92046585647d014faf600e7d38497c1
guid: ae0acf9e445d14c428759c735520d056
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 68f15854e61bd9447b5ba2cb425d6c23
guid: 673a565780fe78f46a9bc0c4cd3ad3c0
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: fcf7bd12379077440aafc48c2539d663
guid: 44edbf911474b1e4bb0808f1af1f0adc
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 7a9682a34ebdce2438e9f1b7d63ce170
guid: 6f6575482ae612245adcf529780271e1
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: d7a3d8f1fe77bc545b42987c53542517
guid: ee8de28e9e4180d43be1b2c1a8ef70a4
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 0776811934888ee48831feafc2576d28
guid: 6599532f572237a43b4e2b684fcf2173
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 54ac8928a79e63f4a84b03bec274eb2b
guid: 2a9d125bff71e4c469750b11bd89bc71
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: d1693b374daf42d4290fc498e1778560
guid: cd3ddf508fa2f7c4095701c501ae23d4
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 0f9f55daa389d6e42b55e12c3bbd9a6b
guid: ed997a4fad66dfe4592f5bbdfad37b5f
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 2b28bf81299dff5418f0ff5dc8dd6179
guid: ec2c755ae5186954b8a8e5ee806ac500
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 94dd5914409ab984eb976565a9f5dfa4
guid: 15431675a57720a498bf5357b7a5db8f
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 702626df44892a146b8edf548095ce9e
guid: 8522f70463c7a3243ab0e4d6444c654b
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: dc65b4a1640acb74a980056f61667765
guid: f9fb6dc831a9bcc4599344f64768f84d
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 5e46a432eeeabfd41b979706a6017e4d
guid: 838b03c97a2c290429023862f5b975e8
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 946f49718f6d258409dba7c18af9c197
guid: 17d14c9555b791146b1faf9cc28a75a1
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 31861159d62e3fe46bb312ef180fe0bb
guid: 7436960c2535b6b438b8e4909e650104
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 096a5bf2283399048891084c0db28fea
guid: 610ad40380804cd49b15558513364f75
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 7e30ae3f8bb2ff74cb9bf6f3a6ff260a
guid: b0ca305ec51fe944ca40a608098bd851
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 615616418cc23904aa74b82628b3c569
guid: 6427364c9843610469730c1392735017
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 4e0458f56828b0f4da1371e66a9f1253
guid: 482206ef6aff47c4db97c0d4425ca2a5
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 3a80fdbf7f341d449aebb6f0ebfc5690
guid: 6d7e1c47af4bb124991ce88430d85272
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 8ae945bfb97749b479ab773f6350f41d
guid: 2052f8df8a5d5064aa18cb47a8da52dc
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 3dc65952dfa57b046970795b7fd60e1f
guid: beba8d595c7ff9f47b6d2694bbb92fe5
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 25b67cf1de3e68e41b7e90cb5d798969
guid: c8ca051a10980594fa29b20bce33ef4d
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 4cb867a87bd34474f9f9e22b5182b68b
guid: 62eea0d3967128f45a9e3267f271e975
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 800a764dfe398694db58be3d23a3c1c9
guid: f33929fb135b01a44ba3021aa06f49c2
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 213e57d3f3081d243a3a3f5c8cb26b01
guid: 9e662398cfab4a44d8baa135972a8209
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 68282f241cd33f4449c3d67f99f9dd9a
guid: 1ebbac566f88f474dbf69d9e82ce8c73
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: e49ffe19c897d344bbf710276acc07d5
guid: 94baf8668295666499c0b92aad0d837c
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 5ccbe297c60dedc438faa22c6c6544ca
guid: e78be86adc2735247aa8241a16b588d3
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: c5835aa351e99bf419ea98160bc95696
guid: 5db3a81a19f6a5c4d9d9f4909aed24a5
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 2cf3694c76d5fc84dbe2a825e1f60943
guid: 1e1fe2d530ea25543a25417bdd74985e
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 40a796a4521988d4ab88011715d23fe7
guid: 8b5abe9306914d0468219227583abdbb
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: f0deaf0cd1eb9584da6d65be95c1f009
guid: fbc4641853e0dc149babe80d0fc7132e
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 02772c0b85bd9a342932c359cc0d70c9
guid: de7e51505aff3a64a88fb1c5c5f063bd
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: c9e846f30aff45e4b980ae976717e8af
guid: 6d1cb65f0c3f6b94c9632113c269df0e
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: cfaf8ca6623675c4bbe42333023604de
guid: 4476d499be94a3340b78874eb8b7ff5f
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: daff85c918602054eb5a0697c52fd5ef
guid: 2e6ed6d0c1db77e4a865ecbffbe91233
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 5091deb3f8ad00d46a9676d898707f5e
guid: 644a3d40d8ce18348b2a7e0faa956446
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: efc580a720cb0254db459df78f76e52e
guid: 7dd0cfb4e9b930e45bfa0cb8a2eb20e2
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 5695f1c7a56eccb4e8d2c079711feaf8
guid: dcad1c0126f22114fa6bcd6875fbe6c4
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000

Some files were not shown because too many files have changed in this diff Show More