Interactable Triggers Added

This commit is contained in:
2022-02-22 21:57:18 +03:00
parent b9a7996f44
commit 25d021a1b2
11 changed files with 361 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
using UnityEngine;
namespace Interactable.Interactor
{
[RequireComponent(typeof(Collider2D), typeof(Rigidbody2D))]
public class ColliderTriggerInteractor : MonoBehaviour
{
protected IInteractable interactable = null;
protected virtual void Start()
{
interactable = GetComponent<IInteractable>();
GetComponent<Collider2D>().isTrigger = true;
GetComponent<Rigidbody2D>().isKinematic = true;
}
protected virtual void OnTriggerEnter2D(Collider2D other) => interactable.Interact();
}
}

View File

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

View File

@@ -0,0 +1,35 @@
using Pausable;
using UnityEngine;
namespace Interactable.Interactor
{
public class KeyPressInteractor : ColliderTriggerInteractor, IPausable
{
protected bool isPlayerInside = false;
protected Input.PlayerInput playerInput = null;
protected override void Start()
{
base.Start();
playerInput = new Input.PlayerInput();
playerInput.Enable();
playerInput.PlayerControl.Interact.performed += (context) => Interact();
}
protected virtual void Interact()
{
if (IsPaused && isPlayerInside)
interactable.Interact();
}
protected override void OnTriggerEnter2D(Collider2D other)
=> isPlayerInside = true;
protected virtual void OnTriggerExit2D(Collider2D other)
=> isPlayerInside = false;
public bool IsPaused { get; protected set; } = false;
public void Pause() => IsPaused = true;
public void Resume() => IsPaused = false;
}
}

View File

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