Example #1
0
    public void Refresh()
    {
        if (m_ignoreChildren)
        {
            return;
        }

        if (!m_renderer)
        {
            GameObject obj = TrafficSystemGameUtils.FindItem(gameObject, TrafficSystemGameUtils.GameObjectItem.RENDERER);
            if (obj && obj.GetComponent <Renderer>())
            {
                m_renderer = obj.GetComponent <Renderer>();
            }
        }

        //		FindAllAttachmentPoints();
    }
    void Awake()
    {
        // HACK - START
        ///       for some reason sometimes m_connectedNodes end up with null values ... have checked every inch of the code and found nothing! ... this removed them on Play so should clean any issues up.
        for (int cIndex = m_connectedNodes.Count - 1; cIndex >= 0; cIndex--)
        {
            if (m_connectedNodes[cIndex] == null)
            {
                m_connectedNodes.RemoveAt(cIndex);
            }
        }
        // HACK - END

        GameObject obj = TrafficSystemGameUtils.FindParentItem(gameObject, TrafficSystemGameUtils.GameObjectItem.TRAFFIC_SYSTEM_PIECE);

        if (obj && obj.GetComponent <TrafficSystemPiece>())
        {
            Parent = obj.GetComponent <TrafficSystemPiece>();
        }

        if (transform.childCount > 0)
        {
            m_linkedIndicator = transform.GetChild(0).gameObject;
        }

        if (Application.isPlaying)
        {
#if UNITY_EDITOR
            ShowRenderers(true);
#else
            ShowRenderers(false);
#endif
        }

//		if(TrafficSystem.Instance && TrafficSystem.Instance.ShouldSpawnVehicle())
//		{
//			TrafficSystemVehicle prefab  = TrafficSystem.Instance.GetVehiclePrefabToSpawn();
//			TrafficSystemVehicle vehicle = Instantiate( prefab, transform.position, transform.rotation ) as TrafficSystemVehicle;
//			vehicle.m_nextNode           = this;
//			vehicle.m_velocityMax        = Random.Range(TrafficSystem.Instance.m_randVelocityMin, TrafficSystem.Instance.m_randVelocityMax);
//		}
    }
    public bool m_turnLeftAnytime                   = false;                         // if this is enabled, whenever a vehicle gets to this traffic light it will turn left straight away. It doesn't wait for a green arrow. The default should be false but there are a few special cases like the ends of T-Intersections that need it true!
//	public  bool               m_enableTurnChecks                 = false;
//	public  float              m_timeToWaitBetweenCheckes         = 1.0f;        // in seconds, the time we check to see if we can move again.
//	public  float              m_checkRadius                      = 5.0f;        // the size of the spherecast for checking vehicle detection.
//	public  Transform          m_checkPos;                                       // the position of the spherecast for checking vehicle detection.
//	private bool               m_checkStarted                     = false;

//	public  List<TrafficSystemVehicle> m_vehiclesStoppedAtLight = new List<TrafficSystemVehicle>();

    void Awake()
    {
        if (!m_intersection)
        {
            GameObject obj = TrafficSystemGameUtils.FindParentItem(gameObject, TrafficSystemGameUtils.GameObjectItem.TRAFFIC_SYSTEM_INTERSECTION);
            if (obj && obj.GetComponent <TrafficSystemIntersection>())
            {
                m_intersection = obj.GetComponent <TrafficSystemIntersection>();
            }
        }

        if (m_lightRedArrow)
        {
            m_lightRedArrow.gameObject.SetActive(true);
        }
        if (m_lightYellowArrow)
        {
            m_lightYellowArrow.gameObject.SetActive(false);
        }
        if (m_lightGreenArrow)
        {
            m_lightGreenArrow.gameObject.SetActive(false);
        }
    }