Exemplo n.º 1
0
    /// <summary>
    /// Verify that all required parameters have been correctly defined, showing a specific error and
    /// returning false if not.
    /// </summary>
    private bool VerifyParameters()
    {
        // Verify this scene has a main Camera.
        if (Camera.main == null)
        {
            Debug.LogError(ExampleErrors.NullMainCamera(this, "to keep the AR Compass Map in front of"));
            return(false);
        }

        // Verify a Background UI element has been given, and that it has a default texture (to use as
        // a backup if augmented reality mode is not available).
        if (Background == null)
        {
            Debug.LogError(ExampleErrors.MissingParameter(this, Background, "Background",
                                                          "to show the real world background on device"));
            return(false);
        }
        if (Background.texture == null)
        {
            Debug.LogErrorFormat("No default texture applied to {0}, defined as {1}.{2}.Background.\n"
                                 + "This UI element must have a default texture to use if AR mode is not available on "
                                 + "device.",
                                 Background.name, name, GetType());
            return(false);
        }

        // If we have reached this point then we have verified that all required parts are present and
        // properly setup.
        return(true);
    }
Exemplo n.º 2
0
        /// <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());
        }
Exemplo n.º 3
0
    /// <summary>
    /// Use <see cref="DynamicMapsService"/> to load geometry, replacing any buildings as needed.
    /// </summary>
    private void Awake()
    {
        // Make sure a prefab has been specified.
        if (Prefab == null)
        {
            Debug.LogError(ExampleErrors.MissingParameter(this, Prefab, "Prefab",
                                                          "to replace specific buildings with"));
            return;
        }

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

        // See if any options have been set indicating which types of buildings to replace, signing up
        // to WillCreate events if so.
        if (ReplaceBars || ReplaceBanks || ReplaceLodgings || ReplaceCafes || ReplaceRestaurants ||
            ReplaceEventVenues || ReplaceTouristDestinations || ReplaceShops || ReplaceSchools ||
            ReplaceUnspecifieds)
        {
            // Create styles for ExtrudedStructure and ModeledStructure type buildings that are to be
            // replaced with a prefab.
            ExtrudedStructureStyle extrudedPrefabStyle = new ExtrudedStructureStyle.Builder {
                Prefab = Prefab
            }.Build();
            ModeledStructureStyle modeledPrefabStyle = new ModeledStructureStyle.Builder {
                Prefab = Prefab
            }.Build();

            // Sign up to events called just before any new building is loaded, so we can check each
            // building's usage type and replace it with prefab if needed. Note that:
            // - DynamicMapsService.MapsService is auto-found on first access (so will not be null).
            // - These events must be set now during Awake, so that when DynamicMapsService starts
            //   loading the map during Start, these event will be triggered for all ExtrudedStructures
            //   and ModeledStructures.
            dynamicMapsService.MapsService.Events.ExtrudedStructureEvents.WillCreate.AddListener(args => {
                if (ShouldReplaceBuilding(args.MapFeature.Metadata.Usage))
                {
                    args.Style = extrudedPrefabStyle;
                }
            });
            dynamicMapsService.MapsService.Events.ModeledStructureEvents.WillCreate.AddListener(args => {
                if (ShouldReplaceBuilding(args.MapFeature.Metadata.Usage))
                {
                    args.Style = modeledPrefabStyle;
                }
            });
        }

        // See if we should be replacing any suppressed buildings with prefab, signing up to DidCreate
        // event if so.
        if (ReplaceSuppressed)
        {
            // Sign up to event called just after any new building is loaded, so we can check if the
            // building's mesh has been suppressed and should be replaced with a prefab.
            dynamicMapsService.MapsService.Events.ExtrudedStructureEvents.DidCreate.AddListener(
                args => TryReplaceSuppressedBuilding(args.GameObject));
            dynamicMapsService.MapsService.Events.ModeledStructureEvents.DidCreate.AddListener(
                args => TryReplaceSuppressedBuilding(args.GameObject));
        }
    }
Exemplo n.º 4
0
        /// <summary>
        /// Check that we have a <see cref="BaseMapLoader"/> so that we can register appropriate
        /// listeners in OnEnable.
        /// </summary>
        protected override void Awake()
        {
            if (BaseMapLoader == null)
            {
                Debug.LogError(ExampleErrors.MissingParameter(
                                   this, BaseMapLoader, "Base Map Loader", "is required for this script to work."));
            }

            base.Awake();
        }
    /// <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);
        });
    }
Exemplo n.º 6
0
        private void Awake()
        {
            // Verify that we have a base map loader available

            // Get the required base map loader
            if (BaseMapLoader == null)
            {
                Debug.LogError(ExampleErrors.MissingParameter(
                                   this, BaseMapLoader, "Base Map Loader", "is required for this script to work."));
            }
        }
Exemplo n.º 7
0
    /// <summary>
    /// Setup <see cref="Slider"/>.
    /// </summary>
    private void Awake()
    {
        // Make sure we have a UI Slider to work with, printing an error if not.
        if (Slider == null)
        {
            Debug.LogError(ExampleErrors.MissingParameter(this, Slider, "Slider"));
            return;
        }

        // Connect changes in Slider's value to given action.
        Slider.onValueChanged.AddListener(TryOnChange);
    }
Exemplo n.º 8
0
        /// <summary>
        /// Make sure all required parameters are given, and connect to <see cref="MapsService"/>'s
        /// <see cref="Google.Maps.Event.MapEvents.Progress"/> event so we can display loading progress
        /// on screen.
        /// </summary>
        void Awake()
        {
            if (BaseMapLoader == null)
            {
                Debug.LogError(ExampleErrors.MissingParameter(
                                   this, BaseMapLoader, "Base Map Loader", "is required for this script to work."));

                return;
            }

            HideProgressBar();
        }
Exemplo n.º 9
0
    /// <summary>
    /// Verify that all required parameters have been correctly defined, returning false if not.
    /// </summary>
    private bool VerifyParameters()
    {
        // Verify that all required Materials have been given.
        if (Buildings == null)
        {
            Debug.LogError(ExampleErrors.MissingParameter(
                               this, Buildings, "Buildings", "to assign to buildings"));
            return(false);
        }
        if (Roads == null)
        {
            Debug.LogError(ExampleErrors.MissingParameter(
                               this, Roads, "Roads", "to assign to road segments"));
            return(false);
        }
        if (Borders == null)
        {
            Debug.LogError(ExampleErrors.MissingParameter(
                               this, Borders, "Borders", "to assign to the borders of road segments and buildings"));
            return(false);
        }
        if (Ground == null)
        {
            Debug.LogError(ExampleErrors.MissingParameter(
                               this, Ground, "Ground", "to assign to ground regions"));
            return(false);
        }
        if (Water == null)
        {
            Debug.LogError(ExampleErrors.MissingParameter(this, Water, "Water", "to assign to water"));
            return(false);
        }

        // Verify at least one of the given Materials' Shader has a Vector that can be used for
        // providing the world's Floating Origin.
        if (!Buildings.HasProperty(MaterialOffsetProperty) &&
            !Roads.HasProperty(MaterialOffsetProperty) &&
            !Borders.HasProperty(MaterialOffsetProperty) &&
            !Ground.HasProperty(MaterialOffsetProperty) &&
            !Water.HasProperty(MaterialOffsetProperty))
        {
            Debug.LogErrorFormat("No '{0}' property found on any of the Shaders of any of the Materials "
                                 + "given to {1}.{2}.\n{2} is used to adjust the offset of this Material's world space "
                                 + "texture coordinates, but given none of the given Materials had a '{0}' property to "
                                 + "use for this purpose, {1}.{2} will be disabled.",
                                 MaterialOffsetProperty, name, GetType());
        }

        // If have reached this point then have verified that all required parts are present and
        // properly setup.
        return(true);
    }
Exemplo n.º 10
0
    /// <summary>Make sure all required parameters are given.</summary>
    private void Awake()
    {
        // Make sure a canvas has been specified.
        if (Canvas == null)
        {
            Debug.LogError(ExampleErrors.MissingParameter(this, Canvas, "Canvas", "to show road names"));
            return;
        }

        // Make sure a prefab has been specified.
        if (LabelPrefab == null)
        {
            Debug.LogError(ExampleErrors.MissingParameter(this, LabelPrefab, "LabelPrefab",
                                                          "to use to display names above roads in scene"));
        }
    }
Exemplo n.º 11
0
        /// <summary>
        /// Use <see cref="MapsService"/> to load geometry, labelling all created roads with their
        /// names.
        /// </summary>
        void Awake()
        {
            // Get the required base map loader.
            if (BaseMapLoader == null)
            {
                Debug.LogError(ExampleErrors.MissingParameter(
                                   this, BaseMapLoader, "Base Map Loader", "is required for this script to work."));
            }

            // Register listeners prior to loading the map.
            BaseMapLoader.MapsService.Events.ExtrudedStructureEvents.DidCreate.AddListener(
                OnExtrudedStructureCreated);
            BaseMapLoader.MapsService.Events.ModeledStructureEvents.DidCreate.AddListener(
                OnModeledStructureCreated);
            BaseMapLoader.MapsService.Events.MapEvents.Loaded.AddListener(OnMapLoaded);
        }
Exemplo n.º 12
0
    /// <summary>
    /// Verify that all required parameters have been correctly defined, returning false if not.
    /// </summary>
    private bool VerifyParameters()
    {
        // Verify that an Emission Controller has been defined.
        if (EmissionController == null)
        {
            Debug.LogError(ExampleErrors.MissingParameter(this, EmissionController, "Emission Controller",
                                                          "to control the emission values of in-scene lights/windows"));
            return(false);
        }

        // Get required light on this gameObject and make sure it is a directional light.
        Light = GetComponent <Light>();
        if (Light.type != LightType.Directional)
        {
            Debug.LogWarningFormat("{0}.{1} found a {2}-light attached to {0}, when a Directional Light "
                                   + "was expected.\n Changing type from {2} to Directional.",
                                   name, GetType(), Light.type);
            Light.type = LightType.Directional;
        }

        // Verify given Fog Distances.
        if (FogStart < 0f)
        {
            Debug.LogError(ExampleErrors.NotGreaterThanZero(this, FogStart, "Fog Start distance",
                                                            ", as this represents the Linear Fog Start Distance for the scene"));
            return(false);
        }
        if (FogEnd < FogStart)
        {
            Debug.LogError(ExampleErrors.NotGreaterThan(this, FogEnd, "Fog End distance", FogStart,
                                                        "Fog Start distance"));
            return(false);
        }

        // Verify given Render Distance is positive.
        if (RenderDistance < 0f)
        {
            Debug.LogError(ExampleErrors.NotGreaterThanZero(this, RenderDistance, "Render Distance",
                                                            ", as this represents the Camera's far Clipping Plane"));
            return(false);
        }

        // If have reached this point then have verified that all required parts are present and
        // properly setup.
        return(true);
    }
Exemplo n.º 13
0
        /// <summary>Make sure all required parameters are given.</summary>
        protected virtual void Awake()
        {
            // Make sure a canvas has been specified.
            if (Canvas == null)
            {
                Debug.LogError(ExampleErrors.MissingParameter(this, Canvas, "Canvas", "to show labels"));

                return;
            }

            // Make sure a prefab has been specified.
            if (LabelPrefab == null)
            {
                Debug.LogError(ExampleErrors.MissingParameter(
                                   this, LabelPrefab, "Label", "to use to display labels for objects in scene"));
            }
        }
Exemplo n.º 14
0
        // Start is called before the first frame update
        void Start()
        {
            IsReady = true;

            if (BaseMapLoader == null)
            {
                Debug.LogError(ExampleErrors.MissingParameter(
                                   this, BaseMapLoader, "Base Map Loader", "is required for this script to work."));
                IsReady = false;
            }

            if (PathFindingExample == null)
            {
                Debug.LogError(ExampleErrors.MissingParameter(
                                   this,
                                   PathFindingExample,
                                   "Path Finding Example",
                                   "is required for this script to work."));
                IsReady = false;
            }

            if (RoadLatticeNodesVisualizer == null)
            {
                Debug.LogError(ExampleErrors.MissingParameter(
                                   this,
                                   RoadLatticeNodesVisualizer,
                                   "Road Lattice Nodes Visualizer",
                                   "is required for this script to work."));
                IsReady = false;
            }

            if (ShowRoadLatticeToggle != null)
            {
                ShowRoadLatticeToggle.isOn = RoadLatticeNodesVisualizer.RoadLattice.activeSelf;
            }

            if (ShowAIPathsToggle != null)
            {
                ShowAIPathsToggle.isOn = PathFindingExample.IsDebugPathOn;
            }

            if (ActivateAIBotsToggle != null)
            {
                ActivateAIBotsToggle.isOn = PathFindingExample.IsAISearchActive;
            }
        }
Exemplo n.º 15
0
        void Awake()
        {
            // Verify all required parameters are defined and correctly setup, skipping any further setup
            // if any parameter is missing or invalid.
            if (!VerifyParameters())
            {
                // Disable this script to prevent error spamming (where Update will producing one or more
                // errors every frame because one or more parameters are undefined).
                enabled = false;
            }

            // Get the required base map loader
            if (BaseMapLoader == null)
            {
                Debug.LogError(ExampleErrors.MissingParameter(
                                   this, BaseMapLoader, "Base Map Loader", "is required for this script to work."));
            }
        }
Exemplo n.º 16
0
    /// <summary>
    /// Verify that all required parameters have been correctly defined, returning false if not.
    /// </summary>
    private bool VerifyParameters()
    {
        // Verify that a Ground plane has been given.
        if (Ground == null)
        {
            Debug.LogError(ExampleErrors.MissingParameter(this, Ground, "Ground"));
            return(false);
        }

        // Verify that there is a Camera.main in the scene (i.e. a Camera that is tagged: "MainCamera").
        if (Camera.main == null)
        {
            Debug.LogError(ExampleErrors.NullMainCamera(this));
            return(false);
        }

        // If have reached this point then we have verified all required parameters.
        return(true);
    }
Exemplo n.º 17
0
    /// <summary>
    /// Use <see cref="CameraController"/>'s OnMove event to detect when the <see cref="Camera"/> has
    /// moved far enough that the Floating Origin needs to be recentered.
    /// </summary>
    private void Awake()
    {
        // Verify a Camera Controller has been given.
        if (CameraController == null)
        {
            Debug.LogError(ExampleErrors.MissingParameter(this, CameraController, "Camera Controller",
                                                          "to tell when the Camera has moved"));
            return;
        }

        // Verify that a valid Floating Origin range was given, i.e. that given distance was not
        // negative nor zero. Comparison is made to float.Epsilon instead of zero to account for float
        // rounding errors.
        if (FloatingOriginRange <= float.Epsilon)
        {
            Debug.LogError(ExampleErrors.NotGreaterThanZero(this, FloatingOriginRange,
                                                            "Floating Origin Range", "to tell how far the Camera should move before the Floating "
                                                            + "Origin is reset"));
            return;
        }

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

        // Store the starting position of the Camera.
        CameraOrigin = Camera.main.transform.position;

        // If no additional GameObjects have been set (to be moved when the world's Floating Origin is
        // recentered), set this array to be just Camera.main's GameObject. This is so that, by
        // default, the scene's Camera is moved when the world is recentered, resulting in a seamless
        // recentering of the world that should be invisible to the user.
        if (AdditionalGameObjects == null)
        {
            AdditionalGameObjects = new[] { Camera.main.gameObject };
        }

        // Whenever the Camera moves, check to see if it has moved far enough that the world's Floating
        // Origin needs to be recentered.
        CameraController.OnMove.AddListener(TryMoveFloatingOrigin);
    }
Exemplo n.º 18
0
        /// <summary>
        /// Use <see cref="CameraController"/>'s OnMove event to detect when the <see cref="Camera"/>
        /// has moved far enough that the Floating Origin needs to be recentered.
        /// </summary>
        private void Awake()
        {
            // Verify a Camera Controller has been given.
            if (CameraController == null)
            {
                Debug.LogError(ExampleErrors.MissingParameter(
                                   this, CameraController, "Camera Controller", "to tell when the Camera has moved"));

                return;
            }

            // Verify that a valid Floating Origin range was given, i.e. that given distance was not
            // negative nor zero. Comparison is made to float.Epsilon instead of zero to account for float
            // rounding errors.
            if (FloatingOriginRange <= float.Epsilon)
            {
                Debug.LogError(ExampleErrors.NotGreaterThanZero(
                                   this,
                                   FloatingOriginRange,
                                   "Floating Origin Range",
                                   "to tell how far the Camera should move before the Floating " + "Origin is reset"));

                return;
            }

            // Store the initial position of the Camera on the ground plane.
            FloatingOrigin = GetCameraPositionOnGroundPlane();

            // If no additional GameObjects have been set (to be moved when the world's Floating Origin is
            // recentered), set this array to be just Camera.main's GameObject. This is so that, by
            // default, the scene's Camera is moved when the world is recentered, resulting in a seamless
            // recentering of the world that should be invisible to the user.
            if (AdditionalGameObjects == null)
            {
                AdditionalGameObjects = new[] { Camera.main.gameObject };
            }
        }