private void WebService_OnLocationChanged(string json) { Debug.Log("Location Changed."); useLocationFromInput = false; var location = JsonConvert.DeserializeObject <HoloGuide.Location>(json); m_currentLocation = location; }
private void Start() { // WebServiceの初期化・イベント登録 WebService.Instance.StartService(); WebService.Instance.OnConnected += WebService_OnConnected; WebService.Instance.OnDisconnected += WebService_OnDisconnected; WebService.Instance.OnReceived += WebService_OnReceived; WebService.Instance.OnLocationChanged += WebService_OnLocationChanged; Connected = false; StartCoroutine("GetLocationFromInput"); #if UNITY_EDITOR // Editor用GPS位置情報 (長町駅) m_currentLocation = new HoloGuide.Location(); m_currentLocation.lat = 38.2269767492871; m_currentLocation.lng = 140.8854836887674; #endif }
// 位置情報の取得 (OnLocationChangedが発火されるまでの暫定的使用) private IEnumerable GetLocationFromInput() { while (true) { if (!useLocationFromInput) { yield break; } if (Input.location.isEnabledByUser) { switch (Input.location.status) { case LocationServiceStatus.Stopped: Input.location.Start(); break; case LocationServiceStatus.Running: var loc = Input.location.lastData; m_currentLocation = new HoloGuide.Location(); m_currentLocation.type = "location"; m_currentLocation.lng = loc.longitude; m_currentLocation.lat = loc.latitude; break; default: break; } } else { Debug.Log("location is disabled by user!"); yield break; } yield return(new WaitForSeconds(intervalSeconds)); } }