Example #1
0
        protected override bool IsTraigger(BaseSensor sensor)
        {
            RaycastHit hit;
            Vector3    rayDirection = transform.position - sensor.transform.position;

            rayDirection.y = 0;
            float       angle     = Vector3.Angle(rayDirection, sensor.transform.forward);
            SightSensor sight     = sensor as SightSensor;
            float       fieldView = sight.fieldView;

            //检查是否在视域内
            if (angle < fieldView)
            {
                //检查是否存在障碍物
                if (Physics.Raycast(sensor.transform.position + Vector3.up,
                                    rayDirection, out hit, sight.viewDistance))
                {
                    if (hit.collider.gameObject == gameObject)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
 public void Try(BaseSensor sensor)
 {
     if (PerceptualTyep == sensor.PerceptualTyep && IsTraigger(sensor))
     {
         sensor.Notify(this);
     }
 }
 public static void RegisterSensor(BaseSensor sensor)
 {
     if (!Sensors.Contains(sensor))
     {
         Sensors.Add(sensor);
     }
 }
 protected override bool IsTraigger(BaseSensor sensor)
 {
     if (Vector3.Distance(sensor.transform.position, transform.position)
         < radius)
     {
         return(true);
     }
     return(false);
 }
 protected virtual bool IsTraigger(BaseSensor sensor)
 {
     return(false);
 }