# CollisionBase

### Members

**Type Parameters:**

* `TCollider`: The type of collider component.
* `TPhysicScene`: The type representing the physics scene.

**Inherited From:**

* `MonoBehaviour`: Unity's base class for scripting behavior in Unity.
* `IEditableForEditor`: An interface for indicating whether the object is editable in the Unity editor.

**Events:**

* `public void SetEditable(bool state)`
  * Event triggered when a collider enters collision.
* `public event Action<TCollider> OnCollisionStay`
  * Event triggered when a collider stays in collision.
* `public event Action<TCollider> OnCollisionExit`
  * Event triggered when a collider exits collision.

**Fields:**

* `[HideInInspector] public bool Editable`
  * Indicates whether the object is editable in the Unity editor.
* `[SerializeField] protected LayerMask m_layer = ~0`
  * Serialized field to specify the layer mask for collision.
* `[SerializeField] public int GarbageColliderSize = 3`
  * Serialized field to specify the size of the garbage collider array.
* `[SerializeField] public Vector3 Center`
  * Serialized field to specify the center of collision calculations.

**Protected Fields:**

* `protected TPhysicScene m_physicsScene`
  * Reference to the physics scene.
* `protected TCollider[] m_garbageColliders`
  * Array to store unused colliders.

**Private Fields:**

* `private List<TCollider> _colliders`
  * List to store active colliders.

### Methods

1. `public void SetEditable(bool state)`
   * Sets the editable state of the object.
2. `public void ChangeEditable()`
   1. Toggles the editable state of the object.
3. `public void UpdatePhysicScene(TPhysicScene physicsScene)`
   1. Updates the reference to the physics scene.
4. `public void SetLayer(LayerMask layerMask)`
   1. Sets the layer mask for collision.
5. `protected abstract void CalculateCollision()`
   1. Abstract method to calculate collisions. Implementation is left to subclasses.
6. `protected abstract void GetPhysicScene()`
   * Abstract method to get the physics scene. Implementation is left to subclasses.
7. `private void SetCollidersCapacity()`
   * nitializes the collider arrays with the specified size.
8. `private void HandleColliderCleaner()`
   * Cleans up null entries in the collider list and resets the garbage collider array.
9. `private void HandleNewCollisions(TCollider[] colliders)`
   * Handles new collisions by adding colliders to the list and triggering OnCollisionEnter event.
10. `private void HandleContinuedCollisions(TCollider[] colliders)`
    * Handles continued collisions by triggering OnCollisionStay event for colliders in the list.
11. `private void HandleCollisionsExit(TCollider[] colliders)`
    * Handles collision exits by removing colliders from the list and triggering OnCollisionExit event.
12. `private void HandleCollisionEnter(TCollider coll)`
    * Invokes the OnCollisionEnter event for the specified collider.
13. `private void HandleCollisionStay(TCollider coll)`
    * Invokes the OnCollisionStay event for the specified collider.
14. `private void HandleCollisionExit(TCollider coll)`
    * Invokes the OnCollisionExit event for the specified collider
