Esempio n. 1
0
    /// <summary>
    /// Create a new road name label when a <see cref="Google.Maps.Feature.Segment"/> GameObject is
    /// created while loading the map.
    /// </summary>
    void OnSegmentCreated(DidCreateSegmentArgs args)
    {
        if (Random.value > Ratio)
        {
            return;
        }

        if (!Labeller.enabled)
        {
            return;
        }

        Label label = Labeller.NameObject(
            args.GameObject, args.MapFeature.Metadata.PlaceId, args.MapFeature.Metadata.Name);

        if (label != null)
        {
            // Get transformer component for re-positioning the label after road segment updates.
            RoadLabelMover roadLabelMover = label.GetComponent <RoadLabelMover>();
            if (roadLabelMover == null)
            {
                roadLabelMover = label.gameObject.AddComponent <RoadLabelMover>();
            }

            // Add road chunk to transformer.
            roadLabelMover.Add(args.GameObject, args.MapFeature.Shape.Lines[0]);
        }
    }
Esempio n. 2
0
 /// <summary>
 /// Triggered by the Maps SDK during the loading process.
 /// Re-parents the newly created GameObject if a container was provided for this map feature
 /// category.
 /// </summary>
 void OnSegmentCreated(DidCreateSegmentArgs args)
 {
     if (SegmentsContainer != null)
     {
         // Note: Care should be taken when reparenting SDK created object.
         // See note above in ClearContainer()
         args.GameObject.transform.SetParent(SegmentsContainer.transform, true);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Updates the number of vehicles to spawn when a segment is created.
        /// </summary>
        private void OnSegmentCreated(DidCreateSegmentArgs args)
        {
            float segmentLength = 0;

            // Calculate the length of the segment.
            Vector2[] polyline = args.MapFeature.Shape.Lines[0].Vertices;
            for (int i = 1; i < polyline.Length; i++)
            {
                segmentLength += (polyline[i] - polyline[i - 1]).magnitude;
            }

            // The number of vehicles to spawn at random locations is equal to the segment length divided
            // by `SegmentLengthToVehicles`.
            VehiclesToSpawn += Mathf.RoundToInt(segmentLength / SegmentLengthToVehicles);
        }
Esempio n. 4
0
        /// <summary>
        /// Handle <see cref="SegmentEvents.DidCreate"/> event to edit created segments game objects
        /// </summary>
        public void OnDidCreateSegmentCallback(DidCreateSegmentArgs arguments)
        {
            // Obtain parameters necessary for the position set
            var gameObjectPosition = arguments.GameObject.transform.position;

            // Move up the road to avoid z-clipping with regions
            arguments.GameObject.transform.position = gameObjectPosition + Vector3.up * 0.3f;
            arguments.GameObject.transform.GetChild(0).localPosition = Vector3.down * 0.1f;

            // Construct exact road label position in 3D space
            var roadLabelPosition = new Vector3(gameObjectPosition.x, 0, gameObjectPosition.z);

            // Generate road label
            var roadLabel = _roadLabeller.Create(roadLabelPosition, arguments.MapFeature.Metadata.Name);

            if (roadLabel == null)
            {
                return;
            }

            // Set its road lint to position the label
            roadLabel.SetLine(arguments.GameObject.transform.position, arguments.MapFeature.Shape.Lines[0]);
        }
Esempio n. 5
0
 void OnSegmentCreated(DidCreateSegmentArgs args)
 {
     Segments.Add(args.GameObject);
 }