/// <summary> /// 计算距离 /// </summary> public void OnComputeDistance() { foreach (var receive in Distances) { if (receive.Interaction == null) { continue; } //如果在距离范围内 if (OnDistance(receive, sendData)) { switch (sendData.detectType) { //并且关系 case InteractionDetectType.And: //如果都没有移入,则 if (!InteractionDistanceController.IsEnter(sendData, receive)) { //判断两者的条件是否都可以进行交互。 if (receive.Interaction.IsCanInteraction(sendData.Interaction) && sendData.Interaction.IsCanInteraction(receive.Interaction)) { InteractionDistanceController.OnEnter(sendData, receive); if (!Distanceing.Contains(receive)) { Distanceing.Add(receive); } } } if (InteractionDistanceController.IsEnter(sendData, receive)) { InteractionDistanceController.OnStay(sendData, receive); } break; case InteractionDetectType.Receive: //如果是接收端,那么只需要计算接收端的IsEnter和receiveData看是否可以进行交互。 if (!InteractionDistanceController.IsEnter(sendData, receive) && receive.Interaction.IsCanInteraction(sendData.Interaction)) { InteractionDistanceController.OnEnter(sendData, receive); if (!Distanceing.Contains(receive)) { Distanceing.Add(receive); } } if (InteractionDistanceController.IsEnter(sendData, receive)) { InteractionDistanceController.OnStay(sendData, receive); } break; case InteractionDetectType.Send: //如果是发送端为主,那么只需要计算发射端的IsEnter和sendData看是否可以进行交互 if (!InteractionDistanceController.IsEnter(sendData, receive) && sendData.Interaction.IsCanInteraction(receive.Interaction)) { InteractionDistanceController.OnEnter(sendData, receive); if (!Distanceing.Contains(receive)) { Distanceing.Add(receive); } } if (InteractionDistanceController.IsEnter(sendData, receive)) { InteractionDistanceController.OnStay(sendData, receive); } break; default: break; } } else { //要加一层判断,否则一直执行是不好的 InteractionDistanceController.OnExit(sendData, receive); if (Distanceing.Count == 0) { continue; } if (Distanceing.Contains(receive)) { Distanceing.Remove(receive); } } } }
void OnEnter(DistanceInteraction receive) { switch (sendData.distanceData.detectType) { //并且关系 case InteractionDetectType.And: //如果都没有移入,则 if (!InteractionDistanceController.IsEnter(sendData, receive)) { //判断两者的条件是否都可以进行交互。 if (receive.IsCanInteraction(sendData) && sendData.IsCanInteraction(receive)) { InteractionDistanceController.OnEnter(sendData, receive); if (!Distanceing.Contains(receive)) { Distanceing.Add(receive); } } } if (InteractionDistanceController.IsEnter(sendData, receive)) { if (!Distanceing.Contains(receive)) { Distanceing.Add(receive); } InteractionDistanceController.OnStay(sendData, receive); } break; case InteractionDetectType.Receive: //如果是接收端,那么只需要计算接收端的IsEnter和receiveData看是否可以进行交互。 if (!InteractionDistanceController.IsEnter(sendData, receive) && receive.IsCanInteraction(sendData)) { InteractionDistanceController.OnEnter(sendData, receive); if (!Distanceing.Contains(receive)) { Distanceing.Add(receive); } } if (InteractionDistanceController.IsEnter(sendData, receive)) { if (!Distanceing.Contains(receive)) { Distanceing.Add(receive); } InteractionDistanceController.OnStay(sendData, receive); } break; case InteractionDetectType.Send: //如果是发送端为主,那么只需要计算发射端的IsEnter和sendData看是否可以进行交互 if (!InteractionDistanceController.IsEnter(sendData, receive) && sendData.IsCanInteraction(receive)) { InteractionDistanceController.OnEnter(sendData, receive); if (!Distanceing.Contains(receive)) { Distanceing.Add(receive); } } if (InteractionDistanceController.IsEnter(sendData, receive)) { if (!Distanceing.Contains(receive)) { Distanceing.Add(receive); } InteractionDistanceController.OnStay(sendData, receive); } break; default: break; } }