Box2DColliderTriggerWithRotation Added

This commit is contained in:
Syntriax 2022-11-20 18:19:05 +03:00
parent dabe16b529
commit 685460123f
4 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,25 @@
using UnityEngine;
namespace Syntriax.Modules.Trigger
{
public class Box2DColliderTriggerWithRotation : Trigger, IColliderTrigger
{
public LayerMask ColliderMask { get => colliderMask; set => colliderMask = value; }
[SerializeField] private LayerMask colliderMask = 0;
private Collider2D[] results = new Collider2D[8];
protected void FixedUpdate()
=> IsTrigerred = Physics2D.OverlapBoxNonAlloc(transform.position, transform.localScale, transform.rotation.eulerAngles.z, results, ColliderMask) > 0;
#if UNITY_EDITOR
private void OnDrawGizmosSelected()
{
Gizmos.color = IsTrigerred ? Color.green : Color.red;
Gizmos.matrix = transform.localToWorldMatrix;
Gizmos.DrawWireCube(Vector3.zero, Vector3.one);
}
#endif
}
}

View File

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

View File

View File

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