コード例 #1
0
 // Computes and adds the Unity (Vector3) coordinates to the venues via  the lat/long values of the venue locations
 private List <FoursquareAPI.Venue> AddUnityCoord(List <FoursquareAPI.Venue> venues)
 {
     for (int i = 0; i < venues.Count; i++)
     {
         var gpsPos = new Sturfee.Unity.XR.Core.Models.Location.GpsPosition();
         gpsPos.Latitude      = venues[i].location.lat;
         gpsPos.Longitude     = venues[i].location.lng;
         gpsPos.Height        = 0;
         venues[i].unityCoord = XRSessionManager.GetSession().GpsToLocalPosition(gpsPos);
     }
     return(venues);
 }
コード例 #2
0
    // Sturfee event called when 'DetectSurfaceAtPoint' completes
    public void OnDetectSurfacePointComplete(Sturfee.Unity.XR.Core.Models.Location.GpsPosition gpsPos, UnityEngine.Vector3 normal)
    {
        ScreenMessageController.Instance.SetText("Target Placed", 2.5f);

        _activeHitscan             = false;
        _targetButton.interactable = true;

        GpsStruct targetGpsPos = new GpsStruct
        {
            Latitude  = gpsPos.Latitude,
            Longitude = gpsPos.Longitude,
            Height    = gpsPos.Height
        };

        CmdSpawnTarget(targetGpsPos, Quaternion.LookRotation(normal));
    }
コード例 #3
0
    private IEnumerator GetMapboxPath()
    {
        var fromGps = XRSessionManager.GetSession().LocalPositionToGps(PlayerController.Instance.transform.position);
        var toGps   = XRSessionManager.GetSession().LocalPositionToGps(DestinationMarker.position);

        print("START GPS POS: " + fromGps.Longitude + ", " + fromGps.Latitude);
        print("END GPS POS: " + toGps.Longitude + ", " + toGps.Latitude);

        //string url = "https://api.mapbox.com/directions/v5/mapbox/cycling/" + gps.Latitude + "," + gps.Longitude

        //print("!! Getting Mapbox path");

        string url = "https://api.mapbox.com/directions/v5/mapbox/walking/" +
                     fromGps.Longitude.ToString() + "," + fromGps.Latitude.ToString() + ";" + toGps.Longitude.ToString() + "," + toGps.Latitude.ToString() +
                     "?steps=true&geometries=geojson&overview=full&access_token=pk.eyJ1IjoibmV3bWFudyIsImEiOiJjamxvZWoydm0wNHllM3BxaDh6c3h0d2F0In0.d1oJAx_nKtHSX32lyv9mBg";

        //alternatives=true&

        //print("URL: " + url);

        using (UnityWebRequest www = UnityWebRequest.Get(url))
        {
            yield return(www.SendWebRequest());

            if (www.isNetworkError)
            {
                //print("!! Error getting Mapbox pathing data");
                Debug.Log(www.error);
            }
            else
            {
                //print("!! Got Mapbox pathing data");
                //var d = JsonUtility.FromJson<MapboxAPI.Response>(www.downloadHandler.text);

                print("JSON STRING RESPONSE: " + www.downloadHandler.text);

                var b = JSON.Parse(www.downloadHandler.text);

                //print("Simple JSON string: " + b.ToString());

                //var test = b["routes"][0]["geometry"]["coordinates"].Count;//[0][0].AsFloat;
                //string code = b["code"].Value;  // works
                //print("SIMPLE JSON Value:" + code + ", " + test);

                //int pathPoints = //d.routes[routeNum].legs[0].steps.Length /*+ 1*/ /*+ finalPoint*/;
                int pathPoints = b["routes"][0]["geometry"]["coordinates"].Count;


                VisualMapPath.positionCount = pathPoints;

                print("*** PATH POINTS " + pathPoints);

                int count = 1;
                for (int i = 0; i < pathPoints; i++)
                {
                    //for(int j = 0; j < 2; j++)
                    //{
                    var wpGps = new Sturfee.Unity.XR.Core.Models.Location.GpsPosition();
                    wpGps.Latitude  = b["routes"][0]["geometry"]["coordinates"][i][1].AsFloat; //d.routes[routeNum].legs[i].steps[j].maneuver.location[1];
                    wpGps.Longitude = b["routes"][0]["geometry"]["coordinates"][i][0].AsFloat;

                    Vector3 worldPos = XRSessionManager.GetSession().GpsToLocalPosition(wpGps);

                    VisualMapPath.SetPosition(pathPoints - count, worldPos);

                    count++;
                }

                _pathPointIndex = pathPoints - 1;

                AttachPathToTerrain();

                _lastArrowPos = PlayerController.Instance.transform.position;
                //_lastArrowDir = new Vector3(-90, 0, 90);    // Set angle looking up so it will definitely be different than initial arrow angle


                // OFFSET SETUP
                _lastArrowDir = VisualMapPath.GetPosition(_pathPointIndex - 1) - VisualMapPath.GetPosition(_pathPointIndex);
                _pathPointIndex--;
                SetNextArrow();


                // PRE OFFSET SETUP
                //float dist = Vector3.Distance(_lastArrowPos, VisualMapPath.GetPosition(_pathPointIndex));

                //if(dist > 8)
                //{
                //    // create an arrow pointing to the first position

                //    Vector3 dir = (VisualMapPath.GetPosition(_pathPointIndex) - _lastArrowPos);
                //    dir.Normalize();
                //    Vector3 forwardPos = _lastArrowPos + (dir * 4);
                //    _curWorldPathArrow = Instantiate(PathArrowPrefab, forwardPos /*arrowPos*/, Quaternion.identity);
                //    _curWorldPathArrow.GetComponent<WorldPathArrow>().Initialize(
                //        VisualMapPath.GetPosition(_pathPointIndex), true/*, false*/);

                //}
                //else
                //{
                //    SetNextArrow();
                //}



                //if (dist <= 6)
                //{
                //    // Place forward along path of first arrow, INSTEAD of first arrow (Replace)
                //    _lastArrowPos = VisualMapPath.GetPosition(_pathPointIndex);
                //    Vector3 dir = (VisualMapPath.GetPosition(_pathPointIndex - 1) - _lastArrowPos);//.normalized;
                //    dir.Normalize();
                //    Vector3 forwardPos = _lastArrowPos + (dir * 5);

                //    _curWorldPathArrow = Instantiate(PathArrowPrefab, forwardPos /*arrowPos*/, Quaternion.identity);
                //    _curWorldPathArrow.GetComponent<WorldPathArrow>().Initialize(
                //        VisualMapPath.GetPosition(_pathPointIndex - 1), true/*, false*/);
                //}
                //else if (dist > 12)
                //{
                //    // Place forward arrow pointing to first point on the path
                //    Vector3 dir = (VisualMapPath.GetPosition(_pathPointIndex) - _lastArrowPos);//.normalized;
                //    dir.Normalize();
                //    Vector3 forwardPos = _lastArrowPos + (dir * 5);

                //    _curWorldPathArrow = Instantiate(PathArrowPrefab, forwardPos /*arrowPos*/, Quaternion.identity);
                //    _curWorldPathArrow.GetComponent<WorldPathArrow>().Initialize(
                //        VisualMapPath.GetPosition(_pathPointIndex), true/*, false*/);
                //}
                //else
                //{
                //    SetNextArrow();
                //}
            }
        }
    }