Merge branch 'main' of ssh://gitfrieds.nackenbox.xyz:3011/MeigoFried/GameVsJam
This commit is contained in:
@ -2,6 +2,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Data;
|
||||
using Interaction;
|
||||
using TMPro.Examples;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
@ -182,11 +183,32 @@ public class Character : MonoBehaviour
|
||||
{
|
||||
Debug.Log($"Gebe {_carriedInteractible.Name} an {developer.Name}");
|
||||
|
||||
Interactible item = _carriedInteractible;
|
||||
PickupInteractible item = _carriedInteractible;
|
||||
|
||||
if (item == null)
|
||||
return;
|
||||
|
||||
PickupItem(null);
|
||||
switch (item.ItemType)
|
||||
{
|
||||
case ItemType.Coffee:
|
||||
developer.GiveDrink(0.4, WantedConsumable.Drink);
|
||||
break;
|
||||
case ItemType.Mate:
|
||||
developer.GiveDrink(0.4, WantedConsumable.Mate);
|
||||
break;
|
||||
case ItemType.Pizza:
|
||||
developer.GiveFood(0.25, WantedConsumable.Pizza);
|
||||
break;
|
||||
}
|
||||
|
||||
item.UsesLeft--;
|
||||
|
||||
if (item.UsesLeft <= 0)
|
||||
{
|
||||
PickupItem(null);
|
||||
|
||||
Destroy(item.gameObject);
|
||||
Destroy(item.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void SayItsImpossible()
|
||||
|
||||
16
3d Prototyp/Assets/Scripts/Interaction/Fridge.cs
Normal file
16
3d Prototyp/Assets/Scripts/Interaction/Fridge.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Interaction;
|
||||
using UnityEngine;
|
||||
|
||||
public class Fridge : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private PickupInteractible _matePrefab;
|
||||
|
||||
public void GetMateFromFridge()
|
||||
{
|
||||
PickupInteractible mate = Instantiate(_matePrefab);
|
||||
GameManager.Instance.Player.PickupItem(mate);
|
||||
}
|
||||
}
|
||||
11
3d Prototyp/Assets/Scripts/Interaction/Fridge.cs.meta
Normal file
11
3d Prototyp/Assets/Scripts/Interaction/Fridge.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2a871a66f73c5ad41835fb81866b6cb4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
181
3d Prototyp/Assets/Scripts/Interaction/InteractionHandler.cs
Normal file
181
3d Prototyp/Assets/Scripts/Interaction/InteractionHandler.cs
Normal file
@ -0,0 +1,181 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Interaction;
|
||||
using JetBrains.Annotations;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.Serialization;
|
||||
using Utility;
|
||||
|
||||
public class InteractionHandler : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Character _character;
|
||||
|
||||
[FormerlySerializedAs("_pickupRadius")] [SerializeField, Tooltip("Der Radius in dem Gottfried Gegenstände aufheben kann."), Min(0.0f)]
|
||||
private float interactionRadius = 1.5f;
|
||||
|
||||
/// <summary>
|
||||
/// Der Radius in dem Gottfried Gegenstände aufheben kann.
|
||||
/// </summary>
|
||||
public float InteractionRadius => interactionRadius;
|
||||
|
||||
[FormerlySerializedAs("_pickupCollider")] [SerializeField]
|
||||
private CapsuleCollider _interactionCollider;
|
||||
|
||||
[FormerlySerializedAs("_pickupablesInRange")] [SerializeField]
|
||||
private List<Interactible> _interactionsInRange = new();
|
||||
|
||||
public IReadOnlyList<Interactible> InteractionsInRange => _interactionsInRange;
|
||||
|
||||
private int _selectedActionIndex = 0;
|
||||
|
||||
public Interactible SelectedAction
|
||||
{
|
||||
get
|
||||
{
|
||||
FixSelection();
|
||||
|
||||
return _selectedActionIndex == -1 ? null : InteractionsInRange[_selectedActionIndex];
|
||||
}
|
||||
}
|
||||
|
||||
public void DoSelectPreviousAction(InputAction.CallbackContext context)
|
||||
{
|
||||
if (!context.performed)
|
||||
return;
|
||||
|
||||
SelectPreviousAction();
|
||||
}
|
||||
|
||||
public void DoSelectNextAction(InputAction.CallbackContext context)
|
||||
{
|
||||
if (!context.performed)
|
||||
return;
|
||||
|
||||
SelectNextAction();
|
||||
}
|
||||
|
||||
public void DoInteract(InputAction.CallbackContext context)
|
||||
{
|
||||
if (!context.performed)
|
||||
return;
|
||||
|
||||
DoInteraction();
|
||||
}
|
||||
|
||||
private void DoInteraction()
|
||||
{
|
||||
if (InteractionsInRange.Count == 0)
|
||||
return;
|
||||
|
||||
Interactible interactible = SelectedAction;
|
||||
|
||||
if (interactible.IsBlocked())
|
||||
{
|
||||
_character.SayItsImpossible();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (interactible)
|
||||
{
|
||||
case PickupInteractible pickup:
|
||||
UnhighlightPickupable(interactible);
|
||||
_character.PickupItem(pickup);
|
||||
break;
|
||||
case UseInteractible usable:
|
||||
usable.OnUse?.Invoke();
|
||||
break;
|
||||
case GiveItemInteractible giveItemAction:
|
||||
_character.GiveItemTo(giveItemAction.Developer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void SelectPreviousAction()
|
||||
{
|
||||
_selectedActionIndex--;
|
||||
UpdateSelection();
|
||||
}
|
||||
|
||||
public void SelectNextAction()
|
||||
{
|
||||
_selectedActionIndex++;
|
||||
UpdateSelection();
|
||||
}
|
||||
|
||||
private void FixSelection()
|
||||
{
|
||||
if (_interactionsInRange.Count == 0)
|
||||
{
|
||||
_selectedActionIndex = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_selectedActionIndex < 0)
|
||||
_selectedActionIndex = InteractionsInRange.Count - 1;
|
||||
else if (_selectedActionIndex >= InteractionsInRange.Count)
|
||||
_selectedActionIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateSelection()
|
||||
{
|
||||
FixSelection();
|
||||
|
||||
int index = 0;
|
||||
foreach (Interactible pickupable in _interactionsInRange)
|
||||
{
|
||||
pickupable.SetSelected(index == _selectedActionIndex);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
Interactible interactible = other.gameObject.GetComponent<Interactible>();
|
||||
|
||||
if (interactible)
|
||||
{
|
||||
HighlightPickupable(interactible);
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerExit(Collider other)
|
||||
{
|
||||
Interactible interactible = other.gameObject.GetComponent<Interactible>();
|
||||
|
||||
if (interactible)
|
||||
{
|
||||
UnhighlightPickupable(interactible);
|
||||
}
|
||||
}
|
||||
|
||||
private void HighlightPickupable(Interactible interactible)
|
||||
{
|
||||
if (!_interactionsInRange.Contains(interactible))
|
||||
_interactionsInRange.Add(interactible);
|
||||
|
||||
interactible.Highlight(true);
|
||||
|
||||
UpdateSelection();
|
||||
}
|
||||
|
||||
private void UnhighlightPickupable(Interactible interactible)
|
||||
{
|
||||
interactible.Highlight(false);
|
||||
_interactionsInRange.Remove(interactible);
|
||||
|
||||
UpdateSelection();
|
||||
}
|
||||
|
||||
// Wird aufgerufen, wenn ein Wert im Editor geändert wird
|
||||
void OnValidate()
|
||||
{
|
||||
if (_interactionCollider)
|
||||
{
|
||||
_interactionCollider.radius = interactionRadius;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba80be7ffa6083b4ba706b603a9b812e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -2,6 +2,13 @@
|
||||
|
||||
namespace Interaction
|
||||
{
|
||||
public enum ItemType
|
||||
{
|
||||
Mate,
|
||||
Coffee,
|
||||
Pizza
|
||||
}
|
||||
|
||||
public class PickupInteractible : Interactible
|
||||
{
|
||||
[SerializeField]
|
||||
@ -9,10 +16,17 @@ namespace Interaction
|
||||
|
||||
[SerializeField]
|
||||
private string _name;
|
||||
|
||||
[SerializeField]
|
||||
private ItemType _itemType;
|
||||
|
||||
public int UsesLeft = 1;
|
||||
|
||||
public GameObject Model => _model;
|
||||
|
||||
public string Name => _name;
|
||||
|
||||
public ItemType ItemType => _itemType;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user