示例#1
0
    void showNearestPOI()
    {
        GPSlocation userPosition = new GPSlocation(51.5221, -0.131411);

        if (UnityEngine.Input.location.status == LocationServiceStatus.Running)
        {
            double longitude = Input.location.lastData.longitude;
            double latitude  = Input.location.lastData.latitude;
            userPosition = new GPSlocation(latitude, longitude);
        }
        if (area.POIs != null)
        {
            POI    nearestPoi = area.GetNearestPOI(userPosition); // area.POIs[0];
            string name       = nearestPoi.Name;
            if (name.Contains("."))
            {
                name = name.Split('.')[1];
            }
            string s = "The nearest POI is " + name + "\n " + (int)(nearestPoi.GetDistance(userPosition)) + "m away.";
            DrawText(new Vector2(Screen.width * 0.2f, Screen.height * 0.6f), s);
            string p = Path.Combine(Application.persistentDataPath, SceneTools.AreaNameDefault() + "/" + "StreamingAssets" + "/" + nearestPoi.ImageTarget);
            if (NearestPOIpath != p)
            {
                Debug.Log("different");
                if (System.IO.File.Exists(p))
                {
                    Texture2D texture = new Texture2D(512, 512);
                    texture.LoadImage(System.IO.File.ReadAllBytes(p));
                    NearestPOITexture = texture;
                    NearestPOIpath    = p;
                    //GameObject plane = GameObject.Find("NearPOI");
                    //plane.GetComponent<Renderer>().material.mainTexture = NearestPOITexture;
                }
                else
                {
                    Debug.LogWarning("Texture " + p + " does not exist");
                }
            }
            GUI.DrawTexture(new Rect((float)0.1 * Screen.width, (float)0.1 * Screen.width, (float)0.8 * Screen.width, (float)0.8 * Screen.width), NearestPOITexture, ScaleMode.ScaleToFit, true, 0);
        }
    }