/// <summary>
        /// Create a <see cref="MapsService"/> to load geometry.
        /// </summary>
        private void Start()
        {
            // Verify that a Sun and Moon Controller has been defined.
            if (SunAndMoonController == null)
            {
                ExampleErrors.MissingParameter(this, SunAndMoonController, "Sun and Moon Controller");

                return;
            }

            // Get required BuildingTexturer component on this GameObject.
            BuildingTexturer buildingTexturer = GetComponent <BuildingTexturer>();

            // Get required Emission Controller component, and give the Building Wall Materials to it so
            // that the building windows can be lit up at night time.
            GetComponent <EmissionController>().SetMaterials(buildingTexturer.WallMaterials);

            // Get required Dynamic Maps Service component on this GameObject.
            DynamicMapsService dynamicMapsService = GetComponent <DynamicMapsService>();

            // Sign up to event called after each new building is loaded, so can assign Materials to this
            // new building. Note that:
            // - DynamicMapsService.MapsService is auto-found on first access (so will not be null).
            // - This event must be set now during Awake, so that when Dynamic Maps Service starts loading
            //   the map during Start, this event will be triggered for all Extruded Structures.
            dynamicMapsService.MapsService.Events.ExtrudedStructureEvents.DidCreate.AddListener(
                args => buildingTexturer.AssignNineSlicedMaterials(args.GameObject));

            // Sign up to event called after all buildings have been loaded, so can start animating
            // day-night cycle.
            dynamicMapsService.MapsService.Events.MapEvents.Loaded.AddListener(
                args => SunAndMoonController.StartAnimating());
        }
    /// <summary>
    /// Create a <see cref="MapsService"/> to load buildings, then add borders around their bases and
    /// around the edges of roads.
    /// </summary>
    private void Start()
    {
        // Verify a Building Base Material has been given.
        if (BuildingAndRoadBorder == null)
        {
            Debug.LogError(ExampleErrors.MissingParameter(this, BuildingAndRoadBorder,
                                                          "Building And Road Border", "to apply around the bases of buildings"));
            return;
        }

        // Verify a Roads Material has been given.
        if (Roads == null)
        {
            Debug.LogError(ExampleErrors.MissingParameter(this, Roads, "Roads", "to apply to roads"));
            return;
        }

        // Get the required Dynamic Maps Service on this GameObject.
        DynamicMapsService dynamicMapsService = GetComponent <DynamicMapsService>();

        // Create a roads style that defines a material for roads and for borders of roads. The specific
        // border material used is chosen to look just a little darker than the material of the ground
        // plane (helping the roads to visually blend into the surrounding ground).
        SegmentStyle roadsStyle = new SegmentStyle.Builder {
            Material       = Roads,
            BorderMaterial = BuildingAndRoadBorder,
            Width          = 7.0f,
            BorderWidth    = 1.0f
        }.Build();

        // Get default style options.
        GameObjectOptions renderingStyles = ExampleDefaults.DefaultGameObjectOptions;

        // Replace default roads style with new, just created roads style.
        renderingStyles.SegmentStyle = roadsStyle;

        // Get required BuildingTexturer component on this GameObject.
        BuildingTexturer buildingTexturer = GetComponent <BuildingTexturer>();

        // Sign up to event called after each new building is loaded, so can assign Materials to this
        // new building, and add an extruded base around the building to fake an Ambient Occlusion
        // contact shadow. Note that:
        // - DynamicMapsService.MapsService is auto-found on first access (so will not be null).
        // - This event must be set now during Awake, so that when Dynamic Maps Service starts loading
        //   the map during Start, this event will be triggered for all Extruded Structures.
        dynamicMapsService.MapsService.Events.ExtrudedStructureEvents.DidCreate.AddListener(args => {
            // Apply nine sliced wall and roof materials to this building.
            //  buildingTexturer.AssignNineSlicedMaterials(args.GameObject);

            // Add a border around base to building using Building Border Builder class, coloring it using
            // the given border Material.
            Extruder.AddBuildingBorder(args.GameObject, args.MapFeature.Shape, BuildingAndRoadBorder);
        });
    }
Beispiel #3
0
    /// <summary>
    /// Use events to connect <see cref="DynamicMapsService"/> to <see cref="BuildingTexturer"/> so
    /// that all extruded buildings can receive a Nine-Sliced <see cref="Material"/>.
    /// </summary>
    private void Awake()
    {
        // Get required Building Texturer component on this GameObject.
        BuildingTexturer buildingTexturer = GetComponent <BuildingTexturer>();

        // Get the required Dynamic Maps Service on this GameObject.
        DynamicMapsService dynamicMapsService = GetComponent <DynamicMapsService>();

        // Sign up to event called after each new building is loaded, so can assign Materials to this
        // new building. Note that:
        // - DynamicMapsService.MapsService is auto-found on first access (so will not be null).
        // - This event must be set now during Awake, so that when Dynamic Maps Service starts loading
        //   the map during Start, this event will be triggered for all Extruded Structures.
        dynamicMapsService.MapsService.Events.ExtrudedStructureEvents.DidCreate.AddListener(
            args => buildingTexturer.AssignNineSlicedMaterials(args.GameObject));
    }
Beispiel #4
0
    /// <summary>
    /// Create a <see cref="MapsService"/> to load buildings, then add parapets to them.
    /// </summary>
    private void Start()
    {
        // Get the required Dynamic Maps Service on this GameObject.
        DynamicMapsService dynamicMapsService = GetComponent <DynamicMapsService>();

        // Get required BuildingTexturer component on this GameObject.
        BuildingTexturer buildingTexturer = GetComponent <BuildingTexturer>();

        // Sign up to event called after each new building is loaded, so can assign Materials to this
        // new building, and add an lofted parapet around the top of each building. Note that:
        // - DynamicMapsService.MapsService is auto-found on first access (so will not be null).
        // - This event must be set now during Awake, so that when Dynamic Maps Service starts loading
        //   the map during Start, this event will be triggered for all Extruded Structures.
        dynamicMapsService.MapsService.Events.ExtrudedStructureEvents.DidCreate.AddListener(args => {
            // Apply nine sliced wall and roof materials to this building.
            buildingTexturer.AssignNineSlicedMaterials(args.GameObject);

            // Add a parapet to this building, making sure it shares the building's roof Material. This
            // should have just been added as the building's second SharedMaterial.
            Material roofMaterial = args.GameObject.GetComponent <MeshRenderer>().sharedMaterials[1];
            Extruder.AddRandomBuildingParapet(args.GameObject, args.MapFeature.Shape, roofMaterial);
        });
    }
    /// <summary>
    /// Use events to make sure all desired geometry is in the correct layer to be seen by, and shown
    /// in, the on-screen Minimap.
    /// </summary>
    private void Awake()
    {
        // Verify that the given Minimap layer is valid (positive and within the range of all available
        // physics layers).
        if (MinimapLayer < 0 || MinimapLayer > 31)
        {
            // Note: 'name' and 'GetType()' just give the name of the GameObject this script is on, and
            // the name of this script respectively.
            Debug.LogErrorFormat("Invalid Segment Physics Layer defined for {0}.{1}, which needs a valid "
                                 + "Physics Layer index (i.e. within the range 0 to 31).",
                                 name, GetType());
            return;
        }

        // Make sure the Minimap Camera is properly setup to render Minimap-layer geometry.
        if (MinimapCamera != null)
        {
            // Convert Minimap Layer index into a Layer Mask, and apply to the Minimap Camera.
            LayerMask minimapLayerMask = 1 << MinimapLayer;
            MinimapCamera.cullingMask = minimapLayerMask;
        }

        // If we've been given a Ground Quad to include in the Minimap, set it's physics layer to the
        // Minimap Layer now (so it can be seen by the Minimap Camera).
        if (Ground == null)
        {
            if (ShowGround)
            {
                Debug.LogErrorFormat("{0}.{1} was unable to show ground in Minimap as no Ground "
                                     + "MeshRenderer was defined.",
                                     name, GetType());
            }
        }
        else
        {
            // Set ground's layer to be either the Minimap layer (if it is to be shown in the Minimap), or
            // the default layer (if it is not to be shown in the Minimap).
            Ground.gameObject.layer = ShowGround ? MinimapLayer : 1 << 0;
        }

        // Get required Building Texturer component on this GameObject.
        BuildingTexturer buildingTexturer = GetComponent <BuildingTexturer>();

        // Get the required Dynamic Maps Service on this GameObject.
        DynamicMapsService dynamicMapsService = GetComponent <DynamicMapsService>();

        // Make sure any desired geometry is put into the Minimap Layer as it is created. Note that:
        // - DynamicMapsService.MapsService is auto-found on first access (so will not be null).
        // - This event must be set now during Awake, so that when Dynamic Maps Service starts loading
        //   the map during Start, these event will be triggered for all relevant geometry.
        if (ShowRegions)
        {
            dynamicMapsService.MapsService.Events.RegionEvents.DidCreate.AddListener(args =>
                                                                                     args.GameObject.layer = MinimapLayer);
        }
        if (ShowSegments)
        {
            dynamicMapsService.MapsService.Events.SegmentEvents.DidCreate.AddListener(args =>
                                                                                      args.GameObject.layer = MinimapLayer);
        }
        if (ShowWater)
        {
            dynamicMapsService.MapsService.Events.AreaWaterEvents.DidCreate.AddListener(args =>
                                                                                        args.GameObject.layer = MinimapLayer);
            dynamicMapsService.MapsService.Events.LineWaterEvents.DidCreate.AddListener(args =>
                                                                                        args.GameObject.layer = MinimapLayer);
        }
        if (ShowExtruded)
        {
            dynamicMapsService.MapsService.Events.ExtrudedStructureEvents.DidCreate.AddListener(args =>
                                                                                                args.GameObject.layer = MinimapLayer);
        }
        if (ShowModeled)
        {
            dynamicMapsService.MapsService.Events.ModeledStructureEvents.DidCreate.AddListener(args =>
                                                                                               args.GameObject.layer = MinimapLayer);
        }

        // Additionally, when extruded structures (buildings) are made, make sure they receive a
        // Nine-Sliced texture. We can connect to this event as many times as we want, with every
        // connected function/code block being called for each created extruded structure.
        dynamicMapsService.MapsService.Events.ExtrudedStructureEvents.DidCreate.AddListener(args =>
                                                                                            buildingTexturer.AssignNineSlicedMaterials(args.GameObject));
    }
Beispiel #6
0
    /// <summary>
    /// Use events to connect <see cref="DynamicMapsService"/> to <see cref="BuildingTexturer"/> so
    /// that all extruded buildings can receive a Nine-Sliced <see cref="Material"/>.
    /// </summary>
    private void Awake()
    {
        // Verify that the given Segment Physics layer is valid (positive and within the range of all
        // available physics layers).
        if (SegmentPhysicsLayer < 0 || SegmentPhysicsLayer > 31)
        {
            Debug.LogError(ExampleErrors.OutsideRange(this, SegmentPhysicsLayer, "Segment Physics Layer",
                                                      0, 31));
            return;
        }

        // Convert Segment Physics Layer index into a Layer Mask for ray-casting into this layer only
        // (i.e. for seeing if any segments are hit by a ray-cast).
        SegmentPhysicsLayerMask = 1 << SegmentPhysicsLayer;

        // Get required Building Texturer component on this GameObject.
        BuildingTexturer buildingTexturer = GetComponent <BuildingTexturer>();

        // Get the required Dynamic Maps Service on this GameObject.
        DynamicMapsService dynamicMapsService = GetComponent <DynamicMapsService>();

        // See if any segment types have been given as types to remove buildings over. We check this so
        // that, if no segments types have been given, unnecessary setup can be avoided.
        bool removeAny = RemoveOverRoads || RemoveOverRailways || RemoveOverFerryLanes;

        // If any segment types have been given as types to remove buildings over, then sign up to event
        // called after each new segment is loaded, so can assign a Collider to it and place it in the
        // Segment Physics Layer. Note that:
        // - DynamicMapsService.MapsService is auto-found on first access (so will not be null).
        // - This event must be set now during Awake, so that when Dynamic Maps Service starts loading
        //   the map during Start, this event will be triggered for all Extruded Structures.
        if (removeAny)
        {
            dynamicMapsService.MapsService.Events.SegmentEvents.DidCreate.AddListener(args => {
                args.GameObject.AddComponent <MeshCollider>();
                args.GameObject.layer = SegmentPhysicsLayer;
            });
        }

        // Sign up to event called after each new building is loaded, so can store it for checking
        // against segments and apply a Nine sliced texture.
        dynamicMapsService.MapsService.Events.ExtrudedStructureEvents.DidCreate.AddListener(args => {
            // Store building so it can be check to be over a segment (after all segments are loaded). We
            // skip this if no segment types have been given as types to remove buildings over.
            if (removeAny)
            {
                StoreBuilding(args.GameObject, args.MapFeature);
            }

            // Assign Nine sliced texture to this building.
            buildingTexturer.AssignNineSlicedMaterials(args.GameObject);
        });

        // When all geometry is loaded, check if any buildings are over any segments, and remove them if
        // so. We skip this if no segment types have been given as types to remove buildings over.
        if (removeAny)
        {
            dynamicMapsService.MapsService.Events.MapEvents.Loaded.AddListener(args =>
                                                                               TryRemoveBuildings());
        }
    }