// Pass trail name and user location to start getting directions for the trail
 void getTrailByName(string trailName, Location userLoc)
 {
     if (directionHandler == null)
     {
         directionHandler = (DirectionsHandler)directionsObject.GetComponent(typeof(DirectionsHandler));
     }
     if (wwwScript == null && wwwHandler != null)
     {
         wwwScript = (WWWHandler)wwwHandler.GetComponent(typeof(WWWHandler));
     }
     directionHandler.StartCoroutine(directionHandler.getDirectionsFromTrailName(wwwScript, trailName, userLoc));
 }
 void Start()
 {
     if (wwwHandler != null)
     {
         wwwScript = (WWWHandler)wwwHandler.gameObject.GetComponent(typeof(WWWHandler));
     }
     if (loadingObject != null)
     {
         loadingManager = (LoadingScript)loadingObject.gameObject.GetComponent(typeof(LoadingScript));
     }
     signUpButton.onClick.AddListener(onSignUp);
     loginButton.onClick.AddListener(onSignIn);
 }
예제 #3
0
    //Simply returns the superficial trailhead data
    public IEnumerator getTrailData(WWWHandler www, string trailName)
    {
        CoroutineWithData trailData = new CoroutineWithData(this, www.GetTrail(trailName));

        yield return(trailData.coroutine);

        JSONNode parsedTrail = JSON.Parse(trailData.result.ToString());
        //TODO: get a trailhead lat/lon
        double lat = parsedTrail["geometry"]["coordinates"][0][1].AsDouble;
        double lon = parsedTrail["geometry"]["coordinates"][0][0].AsDouble;

        Mapbox.Utils.Vector2d searchLoc = new Mapbox.Utils.Vector2d(lat, lon);
        searchForLocation(searchLoc, false);
    }
    void Start()
    {
        //object that updates camera position based on player position

        StartCoroutine(setPositionOnVuforiaEnabled());

        //get reference to WWWHandler and get server data and parse it
        if (wwwHandler != null)
        {
            wwwScript = (WWWHandler)wwwHandler.gameObject.GetComponent(typeof(WWWHandler));
        }

        //get reference to map handler script
        if (mapObject != null)
        {
            map = (Mapbox.Unity.Map.AbstractMap)mapObject.GetComponent((typeof(Mapbox.Unity.Map.AbstractMap)));
        }

        if (directionsObject != null)
        {
            directionHandler = (DirectionsHandler)directionsObject.GetComponent(typeof(DirectionsHandler));
        }

        if (annotationObject != null)
        {
            annotationHandler = (AnnotationHandler)annotationObject.GetComponent(typeof(AnnotationHandler));
        }

        if (uiObject != null)
        {
            uiHandler = (UIManager)uiObject.GetComponent(typeof(UIManager));
        }

        if (playerObject == null)
        {
            playerObject = GameObject.FindGameObjectWithTag("Player");
        }

        if (playerLocation == null)
        {
            playerLocation = GameObject.FindGameObjectWithTag("playerLocation");
        }

        if (cameraPosition == null)
        {
            cameraPosition = GameObject.FindGameObjectWithTag("cameraPosition");
        }
        StartCoroutine(directionHandler.waitForMapLoad());
        nextPlayerPosition = playerObject.transform.localPosition;
    }
 void Start()
 {
     billboards = new ArrayList();
     if (wwwHandler != null)
     {
         wwwScript = (WWWHandler)wwwHandler.gameObject.GetComponent(typeof(WWWHandler));
     }
     if (directionsObject != null)
     {
         directionsHandler = (DirectionsHandler)directionsObject.GetComponent(typeof(DirectionsHandler));
     }
     if (sceneObject != null)
     {
         sceneHandler = (SceneManager)sceneObject.GetComponent(typeof(SceneManager));
     }
 }
예제 #6
0
        internal static void DoUpdate(string newerVersion)
        {
            string depPath    = Path.GetDirectoryName(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)),
                   editorPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            string[] deps = new string[] {
                Path.Combine(depPath, "Lerp2API.dll"),
                Path.Combine(depPath, "Lerp2API.pdb"),
                Path.Combine(depPath, "Lerp2API.xml"),
                Path.Combine(editorPath, "Lerp2APIEditor.dll"),
                Path.Combine(editorPath, "Lerp2APIEditor.pdb"),
                Path.Combine(editorPath, "Lerp2APIEditor.xml"),
                Path.Combine(editorPath, "Lerp2API.version")
            };
            WWW[] wwws = updateUrls.GetWWW();
            if (!deps.All(x => File.Exists(x)))
            {
                Debug.LogErrorFormat("Some Library files doesn't exist, aborting update mission!\nDownload them manually from {0}, and put them in '{1}' folder.",
                                     @"<a href=""https://github.com/Lerp2Dev/Lerp2API/tree/master/Build"">here</a>",
                                     depPath);
            }
            else
            {
                wh = new WWWHandler();
                wh.Add(wwws);
                wh.Start <WWW[]>(false, (x) =>
                {
                    int v = 0;
                    try
                    {
                        for (int i = 0; i < x.Length; ++i)
                        {
                            File.Delete(deps[i]);
                            v = i;
                            File.WriteAllBytes(deps[i], x[i].bytes);
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.LogFormat("Oh guy! You are so fast, {0} has not been downloaded!\n{1}\n{2}", x[v].url, ex.Message, ex.StackTrace);
                    }
                    Debug.LogFormat("Update to '{0}' successfully done!", newerVersion);
                    AssetDatabase.Refresh();
                });
            }
        }
예제 #7
0
        internal static void GetMissingAssets()
        {
            string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "MissingAssets.cs");

            if (File.Exists(path))
            {
                return;
            }
            WWW www = new WWW("http://lerp2dev.x10host.com/unityassets/"); //We have to keep this url and the proper hosting (to give support to the upcoming users of the API) until we don't launch the new web design with all this data updated...

            wh = new WWWHandler();
            wh.Add(www);
            wh.Start <WWW>(false, (x) => {
                File.WriteAllText(path, x.text);
                AssetDatabase.Refresh();
            });
        }
예제 #8
0
    //**THIS FUNCTION QUERIES FOR THE TRAIL NAME AND CREATES THE ACTUAL TRAIL RENDERER LINE**//

    public IEnumerator getDirectionsFromTrailName(WWWHandler www, string trailName, Mapbox.Unity.Location.Location location)
    {
        Debug.Log("Getting trail: " + trailName);

        wwwScript    = www;
        waypointList = new List <Vector2d>();

        //set initialLocation (probably as trail head node) as vec2

        //initialLocation
        Vector3 initLoc = UnityVectorFromVec2d(location.LatitudeLongitude);

        initialLocation = new Vector3(initLoc.x, initLoc.z);

        //store all waypoints as Vec2ds
        CoroutineWithData nodeData = new CoroutineWithData(this, wwwScript.GetTrail(trailName));

        yield return(nodeData.coroutine);

        try{
            JSONNode parsedNode = SimpleJSON.JSON.Parse(nodeData.result.ToString());

            Debug.Log("trail node count: " + parsedNode["geometry"]["coordinates"].Count);

            Debug.Log(parsedNode.ToString());

            for (int i = 0; i < parsedNode["geometry"]["coordinates"].Count; i++)
            {
                double lat = parsedNode["geometry"]["coordinates"][i][1].AsDouble;
                double lon = parsedNode["geometry"]["coordinates"][i][0].AsDouble;

                Vector2d vec2d = new Vector2d(lat, lon);

                waypointList.Add(vec2d);
            }

            //waypoints = new Mapbox.Utils.Vector2d[(waypointList.Count * 2) - 1]; //minus one because you can't calculate midpoint at end
            waypoints = new Vector2d[waypointList.Count];             //1:1 trail
            heights   = new float[waypointList.Count];
            waypoints = waypointList.ToArray();

            //wait for map to load before directions
            StartCoroutine(this.waitForTime(loadTime));
        } catch {}
    }
예제 #9
0
    public static void Download()
    {
        string location = Path.Combine(Application.dataPath, "Lerp2API/Lerp2API.dll"),
               path     = location.Replace(".dll", ".pdb"),
               path1    = location.Replace(".dll", ".xml");
        WWWHandler wh   = new WWWHandler();

        wh.Add(new WWW(updateUrl[0]));
        wh.Add(new WWW(updateUrl[1]));
        wh.Add(new WWW(updateUrl[2]));
        wh.Start <WWW[]>(false, (x) => {
            File.WriteAllBytes(location, x[0].bytes);
            File.WriteAllBytes(path, x[1].bytes);
            File.WriteAllBytes(path1, x[2].bytes);
        });
        Debug.LogFormat("API downloaded successfully!");
        AssetDatabase.Refresh();
    }
    public IEnumerator getTrailsForLocation(Location location, int rad)
    {
        Debug.Log("getting trails at location: " + location.LatitudeLongitude.ToString());
        if (wwwScript == null && wwwHandler != null)
        {
            wwwScript = (WWWHandler)wwwHandler.GetComponent(typeof(WWWHandler));
        }
        CoroutineWithData nearbyData = new CoroutineWithData(this, wwwScript.GetTrails(location.LatitudeLongitude.x, location.LatitudeLongitude.y, rad));

        yield return(nearbyData.coroutine);

        JSONNode parsedNearby = SimpleJSON.JSON.Parse(nearbyData.result.ToString());

        Debug.Log("parsedNearby count: " + parsedNearby.Count);
        uiHandler.clearNearby();
        for (int i = 0; i < parsedNearby.Count; i++)
        {
            uiHandler.populateNearby(parsedNearby[i][0].ToString(), parsedNearby[i][1].ToString());
        }
        uiHandler.clearDuplicateTrails();
    }
    void getTestDirectionsFromLocation(Location location)
    {
        if (true)
        {
            if (directionsObject == null)
            {
                directionsObject = GameObject.FindGameObjectWithTag("DirectionsObject");
            }

            if (directionHandler == null)
            {
                directionHandler = (DirectionsHandler)directionsObject.GetComponent(typeof(DirectionsHandler));
            }
            if (wwwScript == null && wwwHandler != null)
            {
                wwwScript = (WWWHandler)wwwHandler.GetComponent(typeof(WWWHandler));
            }

            directionHandler.StartCoroutine(directionHandler.getTestDirectionsFromJSON(wwwScript, location));
        }
    }
예제 #12
0
 internal static void UpdateCheck(bool successEnabled = false)
 {
     if (!File.Exists(localVersionFilepath))
     {
         JSONHelpers.SerializeToFile(localVersionFilepath, new LerpedUpdater(), true);
     }
     if (!noConnection)
     {
         try
         {
             WWW www = new WWW("https://raw.githubusercontent.com/Lerp2Dev/Lerp2API/master/Lerp2API.version");
             wh = new WWWHandler();
             wh.Add(www);
             wh.Start <WWW>(false, (x) =>
             {
                 var updater = x.text.Deserialize <LerpedUpdater>();
                 if (updater.versionStr != curVersion)
                 {
                     WarnOutdated(updater.versionStr);
                 }
                 else
                 {
                     if (successEnabled)
                     {
                         Debug.Log("Lerp2API is up-to-date!");
                     }
                 }
             });
         }
         catch (Exception e)
         {
             Debug.LogError("Internet connection couldn't be detected, Updates are disabled!\nMaybe it can be another problem, check the log by clicking this message.\n" + e.Message + "\n" + e.StackTrace);
             noConnection = true;
         }
     }
     else
     {
         CheckForConnection();
     }
 }
예제 #13
0
    //** THIS IS FOR THE TEST TRAIL **//
    public IEnumerator getTestDirectionsFromJSON(WWWHandler www, Mapbox.Unity.Location.Location location)
    {
        Debug.Log("Converting JSON to vec2d");

        wwwScript = www;

        waypointList = new List <Vector2d>();


        //initialLocation
        Vector3 initLoc = UnityVectorFromVec2d(location.LatitudeLongitude);

        initialLocation = new Vector3(initLoc.x, initLoc.z);


        CoroutineWithData nodeData = new CoroutineWithData(this, wwwScript.GetTestTrail());

        yield return(nodeData.coroutine);

        JSONNode parsedNode = SimpleJSON.JSON.Parse(nodeData.result.ToString());

        for (int i = 0; i < parsedNode.Count; i++)
        {
            double lat = parsedNode[i] ["Latitude"].AsDouble;
            double lon = parsedNode[i] ["Longitude"].AsDouble;

            Vector2d vec2d = new Vector2d(lat, lon);

            waypointList.Add(vec2d);
        }

        //waypoints = new Mapbox.Utils.Vector2d[(waypointList.Count * 2) - 1]; //minus one because you can't calculate midpoint at end
        waypoints = new Vector2d[waypointList.Count];         //1:1 trail
        heights   = new float[waypointList.Count];
        waypoints = waypointList.ToArray();
        startDirections();
    }
예제 #14
0
        private static void DownloadEditorFiles()
        {
            if (resourceFiles.Length != repFiles.Length)
            {
                Debug.LogError("Internal error ocurred, Resource Files and Repository Files Array have to had the same length!");
                return;
            }
            bool ae = resourceFiles.All(x => File.Exists(x));

            if (ae)
            {
                return;
            }
            if (!ae && LerpedUpdater.noConnection)
            {
                Debug.LogError("No conection available to download!");
                return;
            }
            for (int i = 0; i < resourceFiles.Length; ++i)
            {
                if (!File.Exists(resourceFiles[i]))
                {
                    string fp = Path.GetDirectoryName(resourceFiles[i]);
                    if (!Directory.Exists(fp))
                    {
                        Directory.CreateDirectory(fp);
                    }
                    WWW www = new WWW(repFiles[i]);
                    wh = new WWWHandler();
                    wh.Add(www);
                    wh.Start <WWW>(false, (x) => {
                        File.WriteAllBytes(resourceFiles[i], x.bytes);
                    });
                }
            }
        }
예제 #15
0
    // This instantiates the map for the trail location for search camera
    public IEnumerator getTrailForLocation(WWWHandler www, string trailName)
    {
        //store all waypoints as Vec2ds
        waypointList = new List <Mapbox.Utils.Vector2d>();

        //parse data
        CoroutineWithData trailData = new CoroutineWithData(this, www.GetTrail(trailName));

        yield return(trailData.coroutine);

        JSONNode parsedTrail = SimpleJSON.JSON.Parse(trailData.result.ToString());

        //used to calculate the bounds for the trail
        double south = double.MaxValue;
        double north = double.MinValue;
        double west  = double.MaxValue;
        double east  = double.MinValue;

        bool   isTrailHead = true;
        double latHead     = 0;
        double lonHead     = 0;

        for (int i = 0; i < parsedTrail["geometry"]["coordinates"].Count; i++)
        {
            if (i == 0)
            {
                latHead = parsedTrail["geometry"]["coordinates"][0][1].AsDouble;
                lonHead = parsedTrail["geometry"]["coordinates"][0][0].AsDouble;
            }

            double lat = parsedTrail["geometry"]["coordinates"][i][1].AsDouble;
            double lon = parsedTrail["geometry"]["coordinates"][i][0].AsDouble;

            Mapbox.Utils.Vector2d vec2d = new Mapbox.Utils.Vector2d(lat, lon);

            waypointList.Add(vec2d);

            //find the ne,sw bounds
            if (lat < south)
            {
                south = lat;
            }
            if (lat > north)
            {
                north = lat;
            }
            if (lon < west)
            {
                west = lon;
            }
            if (lon > east)
            {
                east = lon;
            }

            if (isTrailHead == true)
            {
                trailhead   = vec2d;
                isTrailHead = false;
            }
        }

        Mapbox.Utils.Vector2d       ne     = new Mapbox.Utils.Vector2d(north, east);
        Mapbox.Utils.Vector2d       sw     = new Mapbox.Utils.Vector2d(south, west);
        Mapbox.Utils.Vector2dBounds bounds = new Mapbox.Utils.Vector2dBounds(sw, ne);
        loadMapWithBounds(bounds);

//		if (latHead != 0 || lonHead != 0) {
//			Mapbox.Utils.Vector2d searchLoc = new Mapbox.Utils.Vector2d (latHead, lonHead);
//			searchForLocation (searchLoc, false);
//		}
    }
예제 #16
0
    void Start()
    {
        resultList   = new List <GameObject> ();
        nearbyTrails = new List <string[]> ();
        trailNames   = new List <string> ();
        searchScrollView.gameObject.SetActive(false);
        annotationInput.gameObject.SetActive(false);
        if (cameraObject != null)
        {
            cameraHandler = (CameraHandler)cameraObject.gameObject.GetComponent(typeof(CameraHandler));
        }
        if (camera2D != null)
        {
            quadTreeCameraMovement         = (Mapbox.Examples.QuadTreeCameraMovement)camera2D.GetComponent(typeof(Mapbox.Examples.QuadTreeCameraMovement));
            quadTreeCameraMovement.enabled = false;
        }

        if (menuObject != null)
        {
            menuHandler = (MenuScript)menuObject.gameObject.GetComponent(typeof(MenuScript));
        }
        if (wwwHandler != null)
        {
            wwwScript = (WWWHandler)wwwHandler.gameObject.GetComponent(typeof(WWWHandler));
        }
        else
        {
            wwwHandler = GameObject.FindGameObjectWithTag("WWWObject");
            wwwScript  = (WWWHandler)wwwHandler.GetComponent <WWWHandler>();
        }
        if (annotationObject != null)
        {
            annotationHandler = (AnnotationHandler)annotationObject.gameObject.GetComponent(typeof(AnnotationHandler));
        }
        if (annotationObject != null)
        {
            annotationHandler = (AnnotationHandler)annotationObject.gameObject.GetComponent(typeof(AnnotationHandler));
        }
        if (sceneObject != null)
        {
            sceneManager = (SceneManager)sceneObject.gameObject.GetComponent(typeof(SceneManager));
        }
        if (directionsObjects != null)
        {
            directionsHandler = (DirectionsHandler)directionsObjects.gameObject.GetComponent(typeof(DirectionsHandler));
        }
        if (searchDirectionsObject != null)
        {
            searchDirectionsHandler = (DirectionsHandler)searchDirectionsObject.gameObject.GetComponent(typeof(DirectionsHandler));
        }
        isHiking = false;
        StartCoroutine(initUser());
        createAnnotationButton.onClick.AddListener(onClickAnnotation);
        submitAnnotationButton.onClick.AddListener(onAnnotationSubmit);
        exitSelectionButton.onClick.AddListener(disable2D);
        hikeButton.onClick.AddListener(onHike);
        mapButton.onClick.AddListener(() => enable2D(true));
        exploreButton.onClick.AddListener(enableExplore);
        placesButton.onClick.AddListener(enablePlaces);
        settingsButton.onClick.AddListener(enableSettings);
        toggleARButton.onClick.AddListener(disable2D);
        exitHikeButton.onClick.AddListener(exitHike);
        recenterButton.onClick.AddListener(recenter);
        inAR = true;
        usernameText.text = GlobalUserManager.Instance.username;
    }