예제 #1
0
        void SetLaneMarkers()
        {
            m_hoveredLaneMarkers.Clear();
            if (m_segments.Count == 0)
            {
                return;
            }

            NetSegment segment    = NetManager.instance.m_segments.m_buffer[m_segments.Values.First().m_segmentId];
            NetInfo    info       = segment.Info;
            int        laneCount  = info.m_lanes.Length;
            bool       bothWays   = info.m_hasBackwardVehicleLanes && info.m_hasForwardVehicleLanes;
            bool       isInverted = false;

            for (ushort i = 0; i < laneCount; i++)
            {
                m_hoveredLaneMarkers[i] = new FastList <SegmentLaneMarker>();
            }

            foreach (Segment seg in m_segments.Values)
            {
                segment = NetManager.instance.m_segments.m_buffer[seg.m_segmentId];
                uint laneId = segment.m_lanes;

                if (bothWays)
                {
                    isInverted = seg.m_targetNode == segment.m_startNode;
                    if ((segment.m_flags & NetSegment.Flags.Invert) == NetSegment.Flags.Invert)
                    {
                        isInverted = !isInverted;
                    }
                }

                for (int j = 0; j < laneCount && laneId != 0; j++)
                {
                    NetLane lane = NetManager.instance.m_lanes.m_buffer[laneId];

                    if ((info.m_lanes[j].m_laneType & NetInfo.LaneType.Vehicle) == NetInfo.LaneType.Vehicle)
                    {
                        Bezier3 bezier = lane.m_bezier;
                        bezier.GetBounds().Expand(1f);

                        int index = j;
                        if (bothWays && isInverted)
                        {
                            index += (j % 2 == 0) ? 1 : -1;
                        }

                        m_hoveredLaneMarkers[index].Add(new SegmentLaneMarker()
                        {
                            m_bezier    = bezier,
                            m_lane      = laneId,
                            m_laneIndex = index
                        });
                    }

                    laneId = lane.m_nextLane;
                }
            }
        }
        /// <summary>
        /// Initializes/recalculates bezier bounds.
        /// </summary>
        /// <param name="hitH">vertical raycast hit position.</param>
        private void CalculateBounds()
        {
            Bezier3 bezier0 = Bezier;

            // split bezier in 10 parts to correctly raycast curves
            int n = 10;

            bounds = new Bounds[n];
            float size = 1f / n;

            for (int i = 0; i < n; i++)
            {
                Bezier3 bezier = bezier0.Cut(i * size, (i + 1) * size);
                Bounds  bounds = bezier.GetBounds();
                bounds.Expand(1f);
                this.bounds[i] = bounds;
            }
        }
            void CalculateBounds()
            {
                float angle = Vector3.Angle(m_bezier.a, m_bezier.b);

                if (Mathf.Approximately(angle, 0f) || Mathf.Approximately(angle, 180f))
                {
                    angle = Vector3.Angle(m_bezier.b, m_bezier.c);
                    if (Mathf.Approximately(angle, 0f) || Mathf.Approximately(angle, 180f))
                    {
                        angle = Vector3.Angle(m_bezier.c, m_bezier.d);
                        if (Mathf.Approximately(angle, 0f) || Mathf.Approximately(angle, 180f))
                        {
                            // linear bezier
                            Bounds bounds = m_bezier.GetBounds();
                            bounds.Expand(1f);
                            m_bounds = new Bounds[] { bounds };
                            return;
                        }
                    }
                }

                // split bezier in 10 parts to correctly raycast curves
                Bezier3 bezier;
                int     amount = 10;

                m_bounds = new Bounds[amount];
                float size = 1f / amount;

                for (int i = 0; i < amount; i++)
                {
                    bezier = m_bezier.Cut(i * size, (i + 1) * size);

                    Bounds bounds = bezier.GetBounds();
                    bounds.Expand(1f);
                    m_bounds[i] = bounds;
                }
            }
            /// <summary>
            /// Initializes/recalculates bezier bounds.
            /// </summary>
            /// <param name="hitH">vertical raycast hit position.</param>
            private void CalculateBounds(float hitH)
            {
                // maximum vertical postion of the bezier.
                float maxH = Mathf.Max(raycastBezier.a.y, raycastBezier.d.y);

                float mouseH = UIBase.GetTrafficManagerTool(false).MousePosition.y;

                if ((hitH == prev_H || hitH == maxH || prev_H == mouseH) && bounds != null)
                {
                    // use cached results if mouse has not moved or hitH is ignored.
                    return;
                }

                Bezier3 bezier0 = raycastBezier;

                if (hitH < mouseH - MAX_HIT_ERROR)
                {
                    // For Metros use projection on the terrain.
                    bezier0.a.y = bezier0.b.y = bezier0.c.y = bezier0.d.y = mouseH;
                    prev_H      = mouseH;
                }
                else if (hitH > maxH + MAX_HIT_ERROR)
                {
                    // if marker is projected on another road plane then modify its height
                    bezier0.a.y = bezier0.b.y = bezier0.c.y = bezier0.d.y = hitH;
                    prev_H      = hitH;
                }
                else
                {
                    // ignore hitH
                    prev_H = maxH;
                }

                float angle = Vector3.Angle(bezier0.a, bezier0.b);

                if (Mathf.Approximately(angle, 0f) || Mathf.Approximately(angle, 180f))
                {
                    angle = Vector3.Angle(bezier0.b, bezier0.c);
                    if (Mathf.Approximately(angle, 0f) || Mathf.Approximately(angle, 180f))
                    {
                        angle = Vector3.Angle(bezier0.c, bezier0.d);
                        if (Mathf.Approximately(angle, 0f) || Mathf.Approximately(angle, 180f))
                        {
                            // linear bezier
                            Bounds bounds = bezier0.GetBounds();
                            bounds.Expand(0.4f);
                            this.bounds = new Bounds[] { bounds };
                            return;
                        }
                    }
                }

                // split bezier in 10 parts to correctly raycast curves
                int n = 10;

                bounds = new Bounds[n];
                float size = 1f / n;

                for (int i = 0; i < n; i++)
                {
                    Bezier3 bezier = bezier0.Cut(i * size, (i + 1) * size);
                    Bounds  bounds = bezier.GetBounds();
                    bounds.Expand(1f);
                    this.bounds[i] = bounds;
                }
            }