/// <summary> /// 移入 /// </summary> /// <param name="send"></param> /// <param name="receive"></param> public static void OnEnter(DistanceInteraction send, DistanceInteraction receive) { //if (send.distanceData.IsOnly && send.OnlyDistance != receive) return; //在次之前,还需要判断一次,否则一直执行循环查找,会很费资源,这么处理不恰当 if (send.OnlyDistance != null || !receive.OnInteractionCheck()) { return; } //Debug.Log("进来-发送端:" + send.Interaction.FeaturesObjectController + " 接收端:" + receive.Interaction.FeaturesObjectController); InteractionDistanceInfo distanceInfo; if (IsContains(send, receive, out distanceInfo)) { distanceInfo.SetDistanceStatus(DistanceStatus.Enter); } else { distanceInfo = new InteractionDistanceInfo(send, receive, DistanceStatus.Enter); DistanceInfos.Add(distanceInfo); } receive.OnInteractionEnter(send); send.OnInteractionEnter(receive); }
/// <summary> /// 是否存在 /// </summary> /// <param name="send"></param> /// <param name="receive"></param> /// <returns></returns> static bool IsContains(DistanceData send, DistanceData receive, out InteractionDistanceInfo distanceInfo) { var distance = DistanceInfos.Find(obj => obj.sendKey.Equals(send) && obj.receiveValue.Equals(receive)); distanceInfo = distance; return(distance != null); }