コード例 #1
0
        /// <summary>
        /// Handle <see cref="ExtrudedStructureEvents.DidCreate"/> event to edit created segments game objects
        /// </summary>
        public void OnDidCreateExtrudedCallback(DidCreateExtrudedStructureArgs arguments)
        {
            // Load the dependencies for specifying building style
            var buildingRenderer = arguments.GameObject.GetComponent <Renderer>();
            var isGutBuilding    = GutBuildingData.CheckIsGutBuilding(arguments.MapFeature.Metadata.PlaceId);
            var styleType        = isGutBuilding ? MapStyleData.Type.Gut : MapStyleData.Type.Default;
            var materials        =
                MapStyleProvider.Instance.GetBuildingMaterials((int)(Random.value * int.MaxValue), styleType);

            // Set the building style
            buildingRenderer.sharedMaterials = materials;

            // Add extrusion modifications
            ExtrusionModifier.Instance.AddBuildingBorder(arguments.GameObject, arguments.MapFeature.Shape,
                                                         MapStyleProvider.Instance.BuildingBorderMaterial, yOffset: 0.5f);
            ExtrusionModifier.Instance.AddBuildingParapet(arguments.GameObject, arguments.MapFeature.Shape,
                                                          MapStyleProvider.Instance.GetBuildingParapetMaterial(styleType));

            if (!isGutBuilding)
            {
                return;
            }

            // Move GUT building to its controlling parent
            var gutBuildingsParent = GutBuildingsParent.Instance.transform;

            arguments.GameObject.transform.SetParent(gutBuildingsParent);
        }
コード例 #2
0
        /// <summary>
        /// When an extruded structure has been loaded, monitor its destroy phase by adding a custom
        /// <see cref="ListenToDestroy"/> component.
        /// This will be used to keep the dictionary of loaded place ids up-to-date.
        /// </summary>
        void OnExtrudedStructureCreated(DidCreateExtrudedStructureArgs args)
        {
            if (!PlaceIdToGameObjectDict.ContainsKey(args.MapFeature.Metadata.PlaceId))
            {
                PlaceIdToGameObjectDict.Add(args.MapFeature.Metadata.PlaceId, args.GameObject);

                // We are interested in the lifecycle of this GameObject
                // Let's attach a component listening to its OnDestroy event
                // When destroyed the object will notify our local cache for cleanup
                if (args.GameObject.GetComponent <ListenToDestroy>() == null)
                {
                    ListenToDestroy ltd = args.GameObject.AddComponent <ListenToDestroy>();

                    if (ltd != null)
                    {
                        ltd.PlaceId = args.MapFeature.Metadata.PlaceId;

                        if (ltd.MapFeatureDestroyed == null)
                        {
                            ltd.MapFeatureDestroyed = new MapFeatureDestroyedEvent();
                        }
                        else
                        {
                            ltd.MapFeatureDestroyed.AddListener(OnMapFeatureDestroyed);
                        }
                    }
                }
            }
            else
            {
                PlaceIdToGameObjectDict[args.MapFeature.Metadata.PlaceId] = args.GameObject;
            }
        }
コード例 #3
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 OnExtrudedStructureCreated(DidCreateExtrudedStructureArgs args)
 {
     if (ExtrudedStructuresContainer != null)
     {
         // Note: Care should be taken when reparenting SDK created object.
         // See note above in ClearContainer()
         args.GameObject.transform.SetParent(ExtrudedStructuresContainer.transform, true);
     }
 }
コード例 #4
0
    /// <summary>
    /// Check building just made by the <see cref="MapsService"/>, and if its PlaceID matches the one
    /// searched for, adjust building's height to desired level.
    /// </summary>
    private void CheckGeometry(DidCreateExtrudedStructureArgs eventArgs)
    {
        if (PlaceId.Equals(eventArgs.MapFeature.Metadata.PlaceId))
        {
            // Get current height of matching building.
            var   building       = eventArgs.GameObject;
            float buildingHeight = building.GetComponent <MeshFilter>().sharedMesh.bounds.size.y;

            // Confirm height is not zero. Due to floating point rounding errors this is best done by
            // checking a small range around zero (instead of checking exact equality to zero).
            if (Mathf.Abs(buildingHeight) < 0.0001f)
            {
                Debug.LogErrorFormat("{0}.{1} received a building with no height, specifically building on "
                                     + "GameObject named {2}.\nEven though {2} matched searched for PlaceID {3}, cannot "
                                     + "scale up the height of {2} to the desired {4} meters because, as said, {2}'s height "
                                     + "is zero meters.",
                                     name, GetType(), building.name, PlaceId, NewHeight);
                return;
            }

            // Determine the amount by which we need to scale the building vertically to achieve the
            // desired height.
            float heightMultiplier = NewHeight / buildingHeight;
            building.transform.localScale = new Vector3(
                building.transform.localScale.x,
                heightMultiplier,
                building.transform.localScale.z);

            // Set new material if given (ignored if not defined).
            if (NewMaterial != null)
            {
                // Note: extruded buildings have two materials, one for the walls and one for the roof, so a
                // 2-value array must be used to replace its materials.
                building.GetComponent <MeshRenderer>().sharedMaterials =
                    new [] { NewMaterial, NewMaterial };
            }
        }
        // Note: this building may have multiple parts, so keep searching by Place Id until find them
        // all.
    }
コード例 #5
0
 void OnExtrudedStructureCreated(DidCreateExtrudedStructureArgs args)
 {
     CreateLabel(args.GameObject, args.MapFeature.Metadata.PlaceId, args.MapFeature.Metadata.Name);
 }
コード例 #6
0
 public void OnDidCreateExtrudedStructure(DidCreateExtrudedStructureArgs args)
 {
     AddSquasher(args.GameObject);
 }
コード例 #7
0
ファイル: MapManager.cs プロジェクト: carlenlund/air
 void OnExtrudedStructureCreated(DidCreateExtrudedStructureArgs args)
 {
     UpdateBuilding(args.GameObject);
 }