Interactable Triggers Added

This commit is contained in:
Syntriax 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,8 @@
fileFormatVersion: 2
guid: 74528440f805bcc4aa9a2c36257c98ba
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,155 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &3107641084688348912
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 1282702290520677836, guid: 3864d3da05213f64788c898032ba32b2, type: 3}
propertyPath: onInteractEvent.m_PersistentCalls.m_Calls.Array.size
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1282702290520677836, guid: 3864d3da05213f64788c898032ba32b2, type: 3}
propertyPath: onInteractEvent.m_PersistentCalls.m_Calls.Array.data[0].m_Mode
value: 6
objectReference: {fileID: 0}
- target: {fileID: 1282702290520677836, guid: 3864d3da05213f64788c898032ba32b2, type: 3}
propertyPath: onInteractEvent.m_PersistentCalls.m_Calls.Array.data[0].m_Target
value:
objectReference: {fileID: 0}
- target: {fileID: 1282702290520677836, guid: 3864d3da05213f64788c898032ba32b2, type: 3}
propertyPath: onInteractEvent.m_PersistentCalls.m_Calls.Array.data[0].m_CallState
value: 2
objectReference: {fileID: 0}
- target: {fileID: 1282702290520677836, guid: 3864d3da05213f64788c898032ba32b2, type: 3}
propertyPath: onInteractEvent.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName
value: SetActive
objectReference: {fileID: 0}
- target: {fileID: 1282702290520677836, guid: 3864d3da05213f64788c898032ba32b2, type: 3}
propertyPath: onInteractEvent.m_PersistentCalls.m_Calls.Array.data[0].m_TargetAssemblyTypeName
value: UnityEngine.GameObject, UnityEngine
objectReference: {fileID: 0}
- target: {fileID: 1282702290520677836, guid: 3864d3da05213f64788c898032ba32b2, type: 3}
propertyPath: onInteractEvent.m_PersistentCalls.m_Calls.Array.data[0].m_Arguments.m_BoolArgument
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1282702290520677836, guid: 3864d3da05213f64788c898032ba32b2, type: 3}
propertyPath: onInteractEvent.m_PersistentCalls.m_Calls.Array.data[0].m_Arguments.m_ObjectArgumentAssemblyTypeName
value: UnityEngine.Object, UnityEngine
objectReference: {fileID: 0}
- target: {fileID: 1282702290520677837, guid: 3864d3da05213f64788c898032ba32b2, type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1282702290520677837, guid: 3864d3da05213f64788c898032ba32b2, type: 3}
propertyPath: m_LocalPosition.x
value: 8
objectReference: {fileID: 0}
- target: {fileID: 1282702290520677837, guid: 3864d3da05213f64788c898032ba32b2, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1282702290520677837, guid: 3864d3da05213f64788c898032ba32b2, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1282702290520677837, guid: 3864d3da05213f64788c898032ba32b2, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1282702290520677837, guid: 3864d3da05213f64788c898032ba32b2, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1282702290520677837, guid: 3864d3da05213f64788c898032ba32b2, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1282702290520677837, guid: 3864d3da05213f64788c898032ba32b2, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1282702290520677837, guid: 3864d3da05213f64788c898032ba32b2, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1282702290520677837, guid: 3864d3da05213f64788c898032ba32b2, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1282702290520677837, guid: 3864d3da05213f64788c898032ba32b2, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1282702290520677839, guid: 3864d3da05213f64788c898032ba32b2, type: 3}
propertyPath: m_Name
value: Collider Trigger Interactable Variant
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 3864d3da05213f64788c898032ba32b2, type: 3}
--- !u!1 &4246223703925500735 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 1282702290520677839, guid: 3864d3da05213f64788c898032ba32b2, type: 3}
m_PrefabInstance: {fileID: 3107641084688348912}
m_PrefabAsset: {fileID: 0}
--- !u!50 &765001272
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4246223703925500735}
m_BodyType: 0
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 1
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 0
--- !u!61 &765001273
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4246223703925500735}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0, y: 0}
oldSize: {x: 0, y: 0}
newSize: {x: 0, y: 0}
adaptiveTilingThreshold: 0
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 2, y: 2}
m_EdgeRadius: 0
--- !u!114 &765001274
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4246223703925500735}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c53f90e7ee31f3d45b696e5a54b098b5, type: 3}
m_Name:
m_EditorClassIdentifier:

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e25dbc4202461e14fa4d45694c6114d2
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,52 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &1282702290520677839
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1282702290520677837}
- component: {fileID: 1282702290520677836}
m_Layer: 8
m_Name: Interactable Base
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1282702290520677837
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1282702290520677839}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1282702290520677836
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1282702290520677839}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 91f70c4da2fbf6e45995a8aa8153dded, type: 3}
m_Name:
m_EditorClassIdentifier:
onInteractEvent:
m_PersistentCalls:
m_Calls: []
onResetInteractionEvent:
m_PersistentCalls:
m_Calls: []

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 3864d3da05213f64788c898032ba32b2
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1171,6 +1171,56 @@ Camera:
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!1 &765001269
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 765001271}
- component: {fileID: 765001270}
m_Layer: 0
m_Name: GameObject
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &765001270
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 765001269}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 91f70c4da2fbf6e45995a8aa8153dded, type: 3}
m_Name:
m_EditorClassIdentifier:
onInteractEvent:
m_PersistentCalls:
m_Calls: []
onResetInteractionEvent:
m_PersistentCalls:
m_Calls: []
--- !u!4 &765001271
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 765001269}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -11.509604, y: 4.389438, z: 0.39030415}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &794505646 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 7008207192594766311, guid: 2ed6bfce9ad3e19428cb9bef743e0fa3, type: 3}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 977bd97ca45d4a1479f8f78e46297bef
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

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: