Exemplo n.º 1
0
 int GetListIndex(TSTrafficLight.TSPointReference point, List <TSTrafficLight.TSPointReference> list)
 {
     for (int i = 0; i < list.Count; i++)
     {
         if (point.lane == list[i].lane && point.connector == list[i].connector && point.point == list[i].point)
         {
             return(i);
         }
     }
     return(-1);
 }
Exemplo n.º 2
0
 bool Contains(TSTrafficLight.TSPointReference point, List <TSTrafficLight.TSPointReference> list)
 {
     for (int i = 0; i < list.Count; i++)
     {
         if (point.lane == list[i].lane && point.connector == list[i].connector && point.point == list[i].point)
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 3
0
    void SetRoadBlockAhead(TSTrafficLight.TSPointReference point, bool setRoadBlock)
    {
        float dist         = 0;
        int   currentPoint = point.point;

        while (dist < roadBlockAheadDistance && currentPoint >= 0)
        {
            manager.lanes[point.lane].points[currentPoint].roadBlockAhead = setRoadBlock;
            dist += manager.lanes[point.lane].points[currentPoint].distanceToNextPoint;
            currentPoint--;
        }
    }
Exemplo n.º 4
0
 void SetPointReservationID(TSTrafficLight.TSPointReference point, int reservationID)
 {
     TSTrafficLight.TSPointReference roadBlockPoint = new TSTrafficLight.TSPointReference();
     if (point.connector == -1)
     {
         manager.lanes[point.lane].points[point.point].reservationID  = reservationID;
         manager.lanes[point.lane].points[point.point].carwhoReserved = null;
         roadBlockPoint = point;
     }
     else
     {
         manager.lanes[point.lane].connectors[point.connector].points[point.point].reservationID      = reservationID;
         manager.lanes[point.lane].connectors[point.connector].points[point.point].carwhoReserved     = null;
         manager.lanes[point.lane].points[manager.lanes[point.lane].points.Length - 1].carwhoReserved = null;
         manager.lanes[point.lane].points[manager.lanes[point.lane].points.Length - 1].reservationID  = reservationID;
         roadBlockPoint.connector = -1;
         roadBlockPoint.lane      = point.lane;
         roadBlockPoint.point     = manager.lanes[point.lane].points.Length - 1;
     }
     SetRoadBlockAhead(point, (reservationID != 0));
 }
Exemplo n.º 5
0
    void CheckPoints(TSPoints[] points, bool rayHit, RaycastHit hit, float range, bool isConnector, int lane, int connector)
    {
        int controlID = GUIUtility.GetControlID(FocusType.Passive);


        for (int w = 0; w < points.Length; w++)
        {
            currentPoint.lane      = lane;
            currentPoint.connector = connector;
            currentPoint.point     = w;
            bool selected = false;
            if ((points[w].point - tLight.transform.position).sqrMagnitude < range)
            {
                if (connector != -1 && rayHit && (points[w].point - hit.point).magnitude <= tLight.manager.resolutionConnectors / 2f)
                {
                    if ((Event.current.type == EventType.mouseDown) && Event.current.button == 0 && menuSelection == 1)
                    {
                        TSTrafficLight.TSPointReference point = new TSTrafficLight.TSPointReference();
                        point.connector = connector;
                        point.lane      = lane;
                        point.point     = 0;


                        if (addPoints && !addPointsT)
                        {
                            if (!Contains(point, tLight.pointsNormalLight))
                            {
                                tLight.pointsNormalLight.Add(point);
                            }
                            EditorUtility.SetDirty(tLight);
                        }

                        if (removePoints && !removePointsT)
                        {
                            int index = GetListIndex(point, tLight.pointsNormalLight);
                            if (index != -1)
                            {
                                tLight.pointsNormalLight.Remove(tLight.pointsNormalLight[index]);
                            }
                            EditorUtility.SetDirty(tLight);
                        }
                        selected = true;
                        GUIUtility.hotControl = controlID;
                    }
                    else
                    {
                        Handles.color = Color.red;
                    }
                    Handles.color = Color.blue;
                    HighlightPoints(points);
                }
                else
                {
                    if (w == 0)
                    {
                        if (connector == -1)
                        {
                            Handles.color = Color.green;
                            Handles.Label(points[points.Length / 2].point, "Lane " + lane, EditorStyles.whiteLargeLabel);
                        }
                        else
                        {
                            if (Contains(currentPoint, tLight.pointsNormalLight))
                            {
                                Handles.color = Color.magenta;
                            }
                            else
                            {
                                if (isConnector)
                                {
                                    Handles.color = Color.grey;
                                }
                                else
                                {
                                    Handles.color = Color.blue;
                                }
                            }
                            Handles.Label(points[points.Length / 2].point, "Connector " + connector, EditorStyles.whiteLargeLabel);
                        }
                        HighlightPoints(points);
                    }
                }
            }
            if (selected)
            {
                GUIUtility.hotControl = 0;
            }
        }
    }
Exemplo n.º 6
0
    void CheckPoints(TSPoints[] points, bool rayHit, RaycastHit hit, float range, bool isConnector, int lane, int connector)
    {
        int controlID = GUIUtility.GetControlID(FocusType.Passive);

        for (int w = 0; w < points.Length; w++)
        {
            currentPoint.lane      = lane;
            currentPoint.connector = connector;
            currentPoint.point     = w;
            bool selected = false;
            if ((points[w].point - roadBlock.transform.position).sqrMagnitude < range)
            {
                if (rayHit && (new Vector3(points[w].point.x, hit.point.y, points[w].point.z) - hit.point).magnitude <= 0.5f)
                {
                    if ((Event.current.type == EventType.mouseDown) && Event.current.button == 0)
                    {
                        TSTrafficLight.TSPointReference point = new TSTrafficLight.TSPointReference();
                        point.connector = connector;
                        point.lane      = lane;
                        point.point     = w;
                        if (!Contains(point, roadBlock.blockingPoints))
                        {
                            roadBlock.blockingPoints = roadBlock.blockingPoints.Add(point);
                        }
                        else
                        {
                            int index = GetListIndex(point, roadBlock.blockingPoints);
                            if (index != -1)
                            {
                                roadBlock.blockingPoints = roadBlock.blockingPoints.Remove(roadBlock.blockingPoints[index]);
                            }
                        }
                        selected = true;
                        GUIUtility.hotControl = controlID;
                    }
                    else
                    {
                        Handles.color = Color.red;
                    }
                    Handles.color = Color.yellow;
                    Handles.DrawSolidDisc(points[w].point, Vector3.up, 0.5f);
                }
                else
                {
                    if (Contains(currentPoint, roadBlock.blockingPoints))
                    {
                        Handles.color = Color.magenta;
                    }
                    else
                    {
                        if (isConnector)
                        {
                            Handles.color = Color.grey;
                        }
                        else
                        {
                            Handles.color = Color.blue;
                        }
                    }
                    Handles.DrawSolidDisc(points[w].point, Vector3.up, 0.5f);
                }
            }
            if (selected)
            {
                GUIUtility.hotControl = 0;
            }
        }
    }