Merge remote-tracking branch 'origin/Syntriax' into Over
# Conflicts: # UserSettings/EditorUserSettings.asset # UserSettings/Layouts/default-2021.dwlt
This commit is contained in:
8
Assets/Scripts/Interactable.meta
Normal file
8
Assets/Scripts/Interactable.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 15ad75cf57fa64a4f9d63b84cad20918
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Interactable/IInteractable.cs
Normal file
8
Assets/Scripts/Interactable/IInteractable.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Interactable
|
||||
{
|
||||
public interface IInteractable
|
||||
{
|
||||
void Interact();
|
||||
void ResetInteraction();
|
||||
}
|
||||
}
|
11
Assets/Scripts/Interactable/IInteractable.cs.meta
Normal file
11
Assets/Scripts/Interactable/IInteractable.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e5772f733b6ad4458a78277d3d383e1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
29
Assets/Scripts/Interactable/InteractableBase.cs
Normal file
29
Assets/Scripts/Interactable/InteractableBase.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Interactable
|
||||
{
|
||||
public abstract class InteractableBase : MonoBehaviour, IInteractable
|
||||
{
|
||||
protected bool hasBeenInteracted = false;
|
||||
public void Interact()
|
||||
{
|
||||
if (hasBeenInteracted)
|
||||
return;
|
||||
|
||||
OnInteract();
|
||||
hasBeenInteracted = true;
|
||||
}
|
||||
|
||||
public void ResetInteraction()
|
||||
{
|
||||
if (!hasBeenInteracted)
|
||||
return;
|
||||
|
||||
OnResetInteraction();
|
||||
hasBeenInteracted = false;
|
||||
}
|
||||
|
||||
protected abstract void OnInteract();
|
||||
protected abstract void OnResetInteraction();
|
||||
}
|
||||
}
|
11
Assets/Scripts/Interactable/InteractableBase.cs.meta
Normal file
11
Assets/Scripts/Interactable/InteractableBase.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a736473a3063be4e96007c3cb46e73c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Interactable/Interactor.meta
Normal file
8
Assets/Scripts/Interactable/Interactor.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 977bd97ca45d4a1479f8f78e46297bef
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -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();
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c53f90e7ee31f3d45b696e5a54b098b5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
35
Assets/Scripts/Interactable/Interactor/KeyPressInteractor.cs
Normal file
35
Assets/Scripts/Interactable/Interactor/KeyPressInteractor.cs
Normal 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;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43ee1645cb5332c4b86608159117c837
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
14
Assets/Scripts/Interactable/UnityEventInteractable.cs
Normal file
14
Assets/Scripts/Interactable/UnityEventInteractable.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Interactable
|
||||
{
|
||||
public class UnityEventInteractable : InteractableBase
|
||||
{
|
||||
[SerializeField] protected UnityEvent onInteractEvent = new UnityEvent();
|
||||
[SerializeField] protected UnityEvent onResetInteractionEvent = new UnityEvent();
|
||||
|
||||
protected override void OnInteract() => onInteractEvent?.Invoke();
|
||||
protected override void OnResetInteraction() => onResetInteractionEvent?.Invoke();
|
||||
}
|
||||
}
|
11
Assets/Scripts/Interactable/UnityEventInteractable.cs.meta
Normal file
11
Assets/Scripts/Interactable/UnityEventInteractable.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 91f70c4da2fbf6e45995a8aa8153dded
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user