/// <summary>
        /// Remove listeners from floating origin update and unload events.
        /// </summary>
        void OnDisable()
        {
            FloatingOriginUpdater floatingUpdater =
                BaseMapLoader.gameObject.GetComponent <FloatingOriginUpdater>();

            if (floatingUpdater != null)
            {
                floatingUpdater.OnFloatingOriginUpdate.RemoveListener(OnFloatingOriginUpdated);
            }

            DynamicMapsUpdater dynamicUpdater =
                BaseMapLoader.gameObject.GetComponent <DynamicMapsUpdater>();

            if (dynamicUpdater != null)
            {
                dynamicUpdater.UnloadedEvent.RemoveListener(OnRegionUnloaded);
            }

            ClearAndReload();
        }
        /// <summary>
        /// Register listeners for floating origin update and unload events so we can move or remove
        /// labels as appropriate.
        /// </summary>
        void OnEnable()
        {
            FloatingOriginUpdater updater =
                BaseMapLoader.gameObject.GetComponent <FloatingOriginUpdater>();

            if (updater != null)
            {
                updater.OnFloatingOriginUpdate.AddListener(OnFloatingOriginUpdated);
            }

            DynamicMapsUpdater dynamicUpdater =
                BaseMapLoader.gameObject.GetComponent <DynamicMapsUpdater>();

            if (dynamicUpdater != null)
            {
                dynamicUpdater.UnloadedEvent.AddListener(OnRegionUnloaded);
            }

            ClearAndReload();
        }
Beispiel #3
0
    /// <summary>
    /// Connect to <see cref="FloatingOriginUpdater.OnFloatingOriginUpdate"/>, so that whenever the
    /// world's Floating Origin is moved, all controlled world space textured
    /// <see cref="WorldspaceMaterials"/> are realigned to the world's new Floating Origin.
    /// </summary>
    private void Start()
    {
        // Verify all required parameters are defined, skipping further setup if not.
        if (!VerifyParameters())
        {
            enabled = false;
            return;
        }

        // Get the required Floating Origin component on this GameObject.
        FloatingOriginUpdater floatingOriginUpdater = GetComponent <FloatingOriginUpdater>();

        // Make sure that whenever the Floating Origin is updated, Materials are updated in sync.
        floatingOriginUpdater.OnFloatingOriginUpdate.AddListener(UpdateWorldspaceMaterialOffsets);

        // Store all Materials that are to be updated. This function only stores Materials that have an
        // _Offset Vector, which will be used to offset the Material's world space coordinates to align
        // to the world's moved Floating Origin.
        TryAddMaterial(Buildings);
        TryAddMaterial(Roads);
        TryAddMaterial(Ground);
        TryAddMaterial(Water);

        // Because the Floating Origin has not yet been moved, there is no need to apply an _Offset to
        // these Materials yet. Instead we make sure these Material's _Offsets start at (0, 0, 0).
        UpdateWorldspaceMaterialOffsets(Vector3.zero);

        // Create styles to assign world space textured Materials to geometry as it is created.
        ExtrudedStructureStyle extrudedStructureStyle = new ExtrudedStructureStyle.Builder {
            WallMaterial = Buildings,
            RoofMaterial = Buildings
        }.Build();
        ModeledStructureStyle modeledStructureStyle = new ModeledStructureStyle.Builder {
            Material = Buildings
        }.Build();
        SegmentStyle roadsStyle = new SegmentStyle.Builder {
            Material       = Roads,
            BorderMaterial = Borders,
            Width          = 7.0f,
            BorderWidth    = BorderWidth
        }.Build();
        RegionStyle groundStyle = new RegionStyle.Builder {
            FillMaterial = Ground
        }.Build();
        AreaWaterStyle areaWaterStyle = new AreaWaterStyle.Builder {
            FillMaterial = Water
        }.Build();
        LineWaterStyle lineWaterStyle = new LineWaterStyle.Builder {
            Material = Water,
            Width    = 7.0f
        }.Build();

        GameObjectOptions renderingStyles = ExampleDefaults.DefaultGameObjectOptions;

        renderingStyles.ExtrudedStructureStyle = extrudedStructureStyle;
        renderingStyles.ModeledStructureStyle  = modeledStructureStyle;
        renderingStyles.SegmentStyle           = roadsStyle;
        renderingStyles.RegionStyle            = groundStyle;
        renderingStyles.AreaWaterStyle         = areaWaterStyle;
        renderingStyles.LineWaterStyle         = lineWaterStyle;

        DynamicMapsService dynamicMapsService = floatingOriginUpdater.DynamicMapsService;

        dynamicMapsService.RenderingStyles = renderingStyles;

        // Make sure that if any new Materials are cloned by the Maps Service (which can occur to
        // resolve z-fighting issues), that these new cloned materials are added to the list of managed
        // Materials.
        MapsService mapsService = dynamicMapsService.MapsService;

        mapsService.Events.RegionEvents.DidCreate.AddListener(
            args => TryAddMaterialFrom(args.GameObject));
        mapsService.Events.AreaWaterEvents.DidCreate.AddListener(
            args => TryAddMaterialFrom(args.GameObject));
        mapsService.Events.LineWaterEvents.DidCreate.AddListener(
            args => TryAddMaterialFrom(args.GameObject));
        mapsService.Events.SegmentEvents.DidCreate.AddListener(
            args => TryAddMaterialFrom(args.GameObject));
        mapsService.Events.ModeledStructureEvents.DidCreate.AddListener(
            args => TryAddMaterialFrom(args.GameObject));

        // For extruded buildings, also create borders around the edges of these buildings, to match
        // borders around roads.
        mapsService.Events.ExtrudedStructureEvents.DidCreate.AddListener(args => {
            Debug.Log(args.MapFeature.MapFeatureMetadata.PlaceId);
            TryAddMaterialFrom(args.GameObject);
            Extruder.AddBuildingBorder(args.GameObject, args.MapFeature.Shape, Borders, BorderWidth);
        });
    }