implementation of drecon in unity 2022 lts forked from: https://github.com/joanllobera/marathon-envs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

51 lines
1.6 KiB

using UnityEngine;
namespace Unity.MLAgents
{
public class SensorBehavior : MonoBehaviour
{
MarathonAgent _marathonAgent;
IOnSensorCollision _onSensorCollision;
Collider _collider;
void Start()
{
_marathonAgent = GetComponentInParent<MarathonAgent>();
_onSensorCollision = GetComponentInParent<IOnSensorCollision>();
_collider = GetComponent<Collider>();
}
void OnCollisionEnter(Collision other)
{
if (_marathonAgent != null)
_marathonAgent.SensorCollisionEnter(_collider, other);
if (_onSensorCollision != null)
_onSensorCollision.OnSensorCollisionEnter(_collider, other.gameObject);
}
void OnCollisionExit(Collision other)
{
if (_marathonAgent != null)
_marathonAgent.SensorCollisionExit(_collider, other);
if (_onSensorCollision != null)
_onSensorCollision.OnSensorCollisionExit(_collider, other.gameObject);
}
void OnTriggerEnter(Collider other)
{
if (_onSensorCollision != null)
_onSensorCollision.OnSensorCollisionEnter(_collider, other.gameObject);
}
void OnTriggerExit(Collider other)
{
if (_onSensorCollision != null)
_onSensorCollision.OnSensorCollisionExit(_collider, other.gameObject);
}
void OnTriggerStay(Collider other)
{
if (_onSensorCollision != null)
_onSensorCollision.OnSensorCollisionEnter(_collider, other.gameObject);
}
}
}