Esempio n. 1
0
    private void HandDraggableComponent_StoppedDragging()
    {
        GuideStatus.ShouldShowGuide = true;
        if (canBePlaced)
        {
            Vector2d   coordinates = LocationHelper.WorldPositionToGeoCoordinate(gameObject.transform.position);
            GameObject parentTile  = LocationHelper.FindParentTile(coordinates);
            transform.SetParent(parentTile.transform, true);
            // set this so that the bottom surface of this object would be directly on the map
            positionBottomOnTheMap();
            gameObject.GetComponent <InteractibleBuilding>().enabled = true;
            gameObject.GetComponent <DeleteOnVoice>().enabled        = true;
            HoloToolkit.Unity.Utils.SetLayerRecursively(gameObject, parentTile.layer);
            // remove this component
            Destroy(this);
            DropDownPrefabs.Instance.AllowNewObjectCreated();
        }
        else
        {
            transform.localPosition = originalPosition;
            revertToOriginalScale();
        }

        boundsAsset.SetActive(false);
    }
    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;
    }
    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);
    }