-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateLandmark.cs
80 lines (67 loc) · 2.56 KB
/
CreateLandmark.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System.Collections.Generic;
using UnityEngine;
using ARLocation;
using TMPro;
public class CreateLandmark : MonoBehaviour
{
public Transform canvas;
public GameObject markerPrefab;
private float lat;
private float lon;
private string lab;
private TMP_Dropdown dropdown;
public Dictionary<string, Vector2> locations = new Dictionary<string, Vector2>();
private void Start()
{
dropdown = canvas.Find("Dropdown").GetComponent<TMP_Dropdown>();
}
public void Generate()
{
float.TryParse(canvas.Find("InputLatitude").GetComponent<TMP_InputField>().text, out lat);
float.TryParse(canvas.Find("InputLongitude").GetComponent<TMP_InputField>().text, out lon);
lab = canvas.Find("InputLabel").GetComponent<TMP_InputField>().text;
// TODO: connect pathfinder to menu
AddToMenu();
GameObject newLandmark;
newLandmark = Instantiate(markerPrefab);
newLandmark.GetComponent<PlaceAtLocation>().Location = new Location()
{
Latitude = lat,
Longitude = lon,
Altitude = 0,
AltitudeMode = AltitudeMode.DeviceRelative,
Label = lab,
};
newLandmark.gameObject.name = lab;
newLandmark.GetComponent<PlaceAtLocation>().PlacementOptions = new PlaceAtLocation.PlaceAtOptions()
{
HideObjectUntilItIsPlaced = true,
MaxNumberOfLocationUpdates = 2,
MovementSmoothing = 0.1f,
UseMovingAverage = false
};
}
private void AddToMenu()
{
if (lab != "")
{
// Check if menu item already exists.
for (int i = 0; i < dropdown.options.Count; i++)
{
if (dropdown.options[i].text == lab) { return; }
}
locations.Add(lab, new Vector2(lat, lon)); // Check if label exists in dict. If not, add label:(lat, lon) to dict.
List<string> coords = new List<string> { lab };
dropdown.AddOptions(coords); // Add label to menu, if it's not already added.
dropdown.RefreshShownValue();
}
}
public void ChooseFromMenu(int value)
{
if (value == 0) { return; }
string label = dropdown.options[value].text;
canvas.Find("InputLabel").GetComponent<TMP_InputField>().text = label;
canvas.Find("InputLatitude").GetComponent<TMP_InputField>().text = locations[label][0].ToString();
canvas.Find("InputLongitude").GetComponent<TMP_InputField>().text = locations[label][1].ToString();
}
}