Add Component to Empty GameObj
End.
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
81
82
83
84
85
86
87
88
89
90
91
|
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System;
public class GPSSystem : MonoBehaviour
{
public static GPSSystem Instance { set; get; }
public double m_latitude;
public double m_longitude;
public Text coordinates;
public Text debugText;
int count = 0;
private void Start()
{
Instance = this;
#if UNITY_EDITOR
#else
StartCoroutine(StartLocationService());
#endif
}
/*
private void Update()
{
coordinates.text = "Current (Lat,Lon): " + GPSSystem.Instance.m_latitude.ToString() + " - " + GPSSystem.Instance.m_longitude.ToString();
}
private double distanceBetweenTwoPoints(double value1, double value2)
{
return Math.Abs(value1 - value2);
}
*/
private IEnumerator StartLocationService()
{
Input.location.Start(0.5f);
if (!Input.location.isEnabledByUser)
{
Debug.Log("User has not enabled GPS");
// debugText.text = "User has not enabled GPS : " + count++.ToString();
StartCoroutine(waitCor());
yield break;
}
// Input.location.Start();
int maxWait = 20;
while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
{
// debugText.text = "Wait : " + count++.ToString();
yield return new WaitForSeconds(0.2f);
maxWait--;
}
if (maxWait <= 0)
{
Debug.Log("Timed out");
// debugText.text = "Timed out : " + count++.ToString();
StartCoroutine(waitCor());
yield break;
}
if (Input.location.status == LocationServiceStatus.Failed)
{
Debug.Log("Unable to determin device location");
// debugText.text = "Unable to determin device location : " + count++.ToString();
StartCoroutine(waitCor());
yield break;
}
m_latitude = Input.location.lastData.latitude;
m_longitude = Input.location.lastData.longitude;
// debugText.text = "ok : " + count++.ToString();
StartCoroutine(waitCor());
yield break;
}
IEnumerator waitCor()
{
yield return new WaitForSeconds(0.2f);
StartCoroutine(StartLocationService());
}
}
| cs |
댓글
댓글 쓰기