private void Start()
    {
        if (isPoolBuildingsAtStart)
        {
            for (int i = 0; i < prefabsHolder.BuildingPrefabList.Count; i++)
            {
                CoordinateBoundObject buildingModel = prefabsHolder.BuildingPrefabList[i];
                CoordinateBoundObject building      = new CoordinateBoundObject();

                building.gameObject = Instantiate(buildingModel.gameObject);
                prefabsHolder.CorrectPivotAtMeshCenter(building.gameObject);

                if (!string.IsNullOrEmpty(GetBuildingName(buildingModel.gameObject.name)))
                {
                    building.gameObject.AddComponent <InteractibleBuilding>();
                }

                building.gameObject.AddComponent <BoxCollider>();

                //copy the coordinate info
                building.latitude  = buildingModel.latitude;
                building.longitude = buildingModel.longitude;

                building.gameObject.name = buildingModel.gameObject.name;
                GameObjectsInScene[buildingModel.gameObject.name] = building;
                building.gameObject.transform.localScale         *= 99;
                building.gameObject.SetActive(false);
            }
        }
    }
Beispiel #2
0
    /// <summary>
    /// finds a row in CSV aboutthis building, save the building game object as prefab and
    /// then add it to BuildingPrefabList
    /// </summary>
    private void queryCoordinatesAndSavePrefab(GameObject building)
    {
        string name = building.name;
        CoordinateBoundObject buildingWithCoordinate = new CoordinateBoundObject();

        int rowId = getBuildingRowIdFromCSV(name);

        if (rowId == -1)
        {
            return;
        }

        float latitude  = float.Parse(grid[rowId][INDEX_LATITUDE]);
        float longitude = float.Parse(grid[rowId][INDEX_LONGITUDE]);

        buildingWithCoordinate.latitude  = latitude;
        buildingWithCoordinate.longitude = longitude;

        // save as prefab
        GameObject prefab = PrefabUtility.CreatePrefab(prefabFolderPath + "/" + name + prefabExtension, building);

        buildingWithCoordinate.gameObject = prefab;

        // add this to the list
        BuildingPrefabList.Add(buildingWithCoordinate);
    }
    protected override void loadObject(CoordinateBoundObject buildingModel)
    {
        if (buildingModel.gameObject == null)
        {
            return;
        }

        string buildingName = buildingModel.gameObject.name;

        GameObject parentTile = LocationHelper.FindParentTile(buildingModel.coordinates);

        if (parentTile == null)
        {
            Debug.Log("Not instantiating since no parent tile found"); // this should not happen
            return;
        }

        Vector3 position = LocationHelper.geoCoordinateToWorldPosition(buildingModel.coordinates);
        CoordinateBoundObject building;

        if (GameObjectsInScene.TryGetValue(buildingName, out building))
        {
            // if it already has been instantiated but simply active = false

            building.gameObject.SetActive(true);
            building.gameObject.transform.SetParent(parentTile.transform, false);
        }
        else   //instantiate the prefab for the first time
        {
            building.gameObject = Instantiate(buildingModel.gameObject, parentTile.transform);
            prefabsHolder.CorrectPivotAtMeshCenter(building.gameObject);

            if (!string.IsNullOrEmpty(GetBuildingName(buildingModel.gameObject.name)))
            {
                building.gameObject.AddComponent <InteractibleBuilding>();
            }

            building.gameObject.AddComponent <BoxCollider>();

            //copy the coordinate info
            building.latitude  = buildingModel.latitude;
            building.longitude = buildingModel.longitude;

            building.gameObject.name                  = buildingName;
            GameObjectsInScene[buildingName]          = building;
            building.gameObject.transform.localScale *= 99;
        }

        DropDownBuildings.Instance.AddItemToDropdown(buildingName);

        // adjust its vertical position since the pivot position of the building models
        // are at their center.
        float halfHeight = building.gameObject.GetComponent <BoxCollider>().bounds.extents.y;

        position.y += halfHeight;
        building.gameObject.transform.position = position;
        building.gameObject.layer = parentTile.layer;
    }
    private void UnregisterForTranslation()
    {
        setCoordinates();

        // update the coordinate info stored in PolygonManager
        CoordinateBoundObject thisPolygon = PolygonManager.Instance.GameObjectsInScene[gameObject.name];

        thisPolygon.latitude  = (float)Coordinates.x;
        thisPolygon.longitude = (float)Coordinates.y;
    }
    protected override void queryObjectsWithinTileBounds(UnwrappedTileId tileId)
    {
        Vector2dBounds bounds = Conversions.TileIdToBounds(tileId);

        for (int i = 0; i < prefabsHolder.BuildingPrefabList.Count; i++)
        {
            CoordinateBoundObject building = prefabsHolder.BuildingPrefabList[i];
            if (building.coordinates.x.InRange(bounds.North, bounds.South) &&
                building.coordinates.y.InRange(bounds.West, bounds.East))
            {
                ObjectsToLoad.Enqueue(building);
            }
        }
    }
    protected override void loadObject(CoordinateBoundObject pin)
    {
        GameObject pinObject = pin.gameObject;

        if (pinObject == null) // if deleted
        {
            return;
        }
        GameObject parentTile = LocationHelper.FindParentTile(pin.coordinates);

        pinObject.transform.position = LocationHelper.geoCoordinateToWorldPosition(pin.coordinates);
        pinObject.transform.SetParent(parentTile.transform);
        pinObject.SetActive(true);
        HoloToolkit.Unity.Utils.SetLayerRecursively(pinObject, parentTile.layer);
    }
    protected override void loadObject(CoordinateBoundObject polygon)
    {
        GameObject polygonObject = polygon.gameObject;

        if (polygonObject == null)
        {
            return;
        }

        polygonObject.transform.position = LocationHelper.geoCoordinateToWorldPosition(polygon.coordinates);
        GameObject parentTile = LocationHelper.FindParentTile(polygon.coordinates);

        polygonObject.transform.SetParent(parentTile.transform, true);
        polygonObject.SetActive(true);
        polygonObject.layer = parentTile.layer;
    }
    public void InstantiatePin(Vector3 point)
    {
        Vector2d pointLatLong        = LocationHelper.WorldPositionToGeoCoordinate(point);
        CoordinateBoundObject newPin = new CoordinateBoundObject();

        newPin.latitude  = (float)pointLatLong.x;
        newPin.longitude = (float)pointLatLong.y;
        GameObject parentTile = LocationHelper.FindParentTile(pointLatLong);
        GameObject pinObject  = Instantiate(pinPrefab, point, Quaternion.identity);

        pinObject.name    = "pin " + GameObjectsInScene.Count;
        newPin.gameObject = pinObject;
        pinObject.transform.SetParent(parentTile.transform, true);
        GameObjectsInScene[pinObject.name] = newPin;

        // add to the dropdown
        DropDownPinnedLocations.Instance.AddItemToDropdown(pinObject.name);
    }
    public void InstantiatePolygonFromVertices(List <Vector3> polygonVertices)
    {
        Dictionary <int, int> neighbouringVertexMapping;
        GameObject            polygon = PolygonGenerator.GeneratePolygonFromVertices(polygonVertices, 0.1f, polygonMaterial, out neighbouringVertexMapping);

        polygon.name = "polygon " + GameObjectsInScene.Count;
        Vector2d             polygonCoordinates = setPolygonParentToMapTile(polygon);
        UserGeneratedPolygon script             = polygon.AddComponent <UserGeneratedPolygon>();

        script.neighbouringVertexMapping = neighbouringVertexMapping;

        CoordinateBoundObject polygonWithCoordinates = new CoordinateBoundObject();

        polygonWithCoordinates.latitude   = (float)polygonCoordinates.x;
        polygonWithCoordinates.longitude  = (float)polygonCoordinates.y;
        polygonWithCoordinates.gameObject = polygon;
        GameObjectsInScene[polygon.name]  = polygonWithCoordinates;

        // add to the dropdown
        DropDownPolygons.Instance.AddItemToDropdown(polygon.name);
    }
Beispiel #10
0
 /// <summary>
 /// This is to be overriden by the child classes
 /// </summary>
 protected virtual void loadObject(CoordinateBoundObject obj)
 {
 }