private void OnWillCreateIntersection(WillCreateIntersectionArgs args)
        {
            // Set reasonable default settings for intersections.
            args.Style = new SegmentStyle.Builder(args.Style)
            {
                IntersectionMaterial       = DefaultMaterial,
                IntersectionArmLength      = RoadWidth,
                IntersectionJoinLength     = RoadWidth * 4,
                MaxIntersectionArmDistance = RoadWidth * 5,
                Width = RoadWidth
            }.Build();

            // Get the intersection arms from the feature shape.
            List <IntersectionArm> arms = new List <IntersectionArm>(args.MapFeature.Shape.Arms);

            // Delete intersection arms along non-road segments (e.g. footpaths). Keep track of how many
            // arms we have after deletion.
            int numArms = 0;

            foreach (IntersectionArm arm in arms)
            {
                if (!Vehicle.IsTraversableRoad(arm.Segment))
                {
                    // Delete arm along non-road segment.
                    arm.Cancel = true;
                    continue;
                }

                numArms++;
            }

            if (numArms > 3)
            {
                // 4-way or larger intersection. Apply some random arm materials and return.
                foreach (IntersectionArm arm in arms)
                {
                    // Don't change the material of two-way arms. These arms are treated as part of the inner
                    // polygon (i.e. the center of the intersection where roads overlap) and should use the
                    // default intersection material.
                    if (arm.IsTwoWay(args.Style.IntersectionJoinLength))
                    {
                        continue;
                    }

                    arm.Material = ArmMaterials[Random.Range(0, ArmMaterials.Length)];
                }
            }
            else
            {
                // Delete intersections with 3 or fewer arms.
                args.Cancel = true;
            }
        }
        void OnWillCreateIntersection(WillCreateIntersectionArgs args)
        {
            // Set reasonable default settings for intersections.
            args.Style = new SegmentStyle.Builder(args.Style)
            {
                IntersectionMaterial       = DefaultMaterial,
                IntersectionArmLength      = RoadWidth,
                IntersectionJoinLength     = RoadWidth * 4,
                MaxIntersectionArmDistance = RoadWidth * 5,
                Width = RoadWidth
            }.Build();

            // Get the intersection arms from the feature shape.
            List <IntersectionArm> arms = new List <IntersectionArm>(args.MapFeature.Shape.Arms);

            if (arms.Count != 3)
            {
                // Not a 3-way intersection. Apply some random arm materials and return.
                foreach (IntersectionArm arm in arms)
                {
                    // Don't change the material of two-way arms. These arms are treated as part of the inner
                    // polygon (i.e. the center of the intersection where roads overlap) and should use the
                    // default intersection material.
                    if (arm.IsTwoWay(args.Style.IntersectionJoinLength))
                    {
                        continue;
                    }

                    arm.Material = ArmMaterials[Random.Range(0, ArmMaterials.Length)];
                }
            }
            else
            {
                // Delete 3-way intersections.
                args.Cancel = true;
            }
        }
 /// <summary>
 /// Handle <see cref="IntersectionEvents.WillCreate"/> event by specifying the intersection
 /// styles.
 /// </summary>
 /// <param name="args">Event arguments.</param>
 public void HandleWillCreateIntersection(WillCreateIntersectionArgs args)
 {
     args.Style = GameObjectOptions.SegmentStyle;
 }
Beispiel #4
0
 /// <summary>
 /// Handle <see cref="IntersectionEvents.WillCreate"/> event by specifying the intersection styles.
 /// </summary>
 public void HandleWillCreateIntersection(WillCreateIntersectionArgs arguments)
 {
     arguments.Style = _mapDefaultStyle.SegmentStyle;
 }