此类中包含所有触发器共有的信息,比如触发器的作用半径、触发器是否已经使用完成要被移除等
public class BaseTrigger : MonoBehaviour {
protected TriggerSystemManager manager;
//触发器位置
protected Vector3 position;
public int radius;
//是否需要被移除
public bool toBeRemoved;
/// <summary>
/// 检查感知器是否在触发器作用范围内,在范围内进行相关行为
/// 此方法在派生类中实现
/// </summary>
/// <param name="s"></param>
public virtual void Try(BaseSensor s) { }
/// <summary>
/// 更新触发器内部的状态
/// </summary>
public virtual void Updateme() { }
/// <summary>
/// 判断触发器是否在感知器范围内,在感知器范围返回true,不在返回false
/// </summary>
/// <param name="sensor"></param>
/// <returns></returns>
public virtual bool isTouchingTrigger(BaseSensor sensor)
{
return false;
}
private void Awake()
{
manager = FindObjectOfType<TriggerSystemManager>();
}
protected void Start()
{
toBeRemoved = false;
}
}
包括对感知器类型的枚举定义和变量,保存了事件管理器
public class BaseSensor : MonoBehaviour {
protected TriggerSystemManager manager;
public enum SensorType
{
sight,
sound,
health
}
public SensorType sensorType;
private void Awake()
{
manager = FindObjectOfType<TriggerSystemManager>();
}
public virtual void Notify (BaseTrigger t)
{
}
}