public static Vector3 SphericalMercator(this LatLngPoint value) { if (value is null) { throw new ArgumentNullException(nameof(value)); } var lat = Degrees.Radians(value.Latitude); var lng = Degrees.Radians(value.Longitude); var x = DatumWGS_84.equatorialRadius * lng; var y = DatumWGS_84.equatorialRadius * Math.Log(Math.Tan(Math.PI / 4 + lat / 2)); return(new Vector3((float)x, (float)y)); }
public void OnValidate() { if (!HasCoord) { if (UseFakeCoord) { Coord = new LatLngPoint(38.881621f, -77.072478f, 0); } else if (PlayerPrefs.HasKey(COORD_KEY)) { Coord = coordFactory.Parse(PlayerPrefs.GetString(COORD_KEY)); } } }
/// <summary> /// Retrieves the current <see cref="location"/> and/or <see cref="compass"/>, if they are /// needed, updates the <see cref="currentTime"/>, calculates the correct sun position from /// that time, and optionally prints a debug report. /// </summary> public void Update() { currentTime = GetTime(); if (location.Coord != lastCoord) { lastCoord = location.Coord; orientation = location.Coord.ToSunPosition(currentTime); } if (DebugReport) { PrintDebugReport(); } }
/// <summary> /// If the time between reports has elapsed, retrieve a new GPS report, saving the results to /// PlayerPrefs and firing the <see cref="onPositionUpdated"/> and <see /// cref="PositionUpdated"/> events if one is found. /// </summary> public void Update() { if (!startingTask.IsRunning()) { if (startingTask != null) { if (startingTask.IsFaulted) { enabled = false; } else { startingTask = null; } } if (UseFakeCoord != lastUseFakeCoord) { UnityInput.compass.enabled = !UseFakeCoord; } lastUseFakeCoord = UseFakeCoord; if (Status == LocationServiceStatus.Running && !UseFakeCoord && Time.unscaledTime >= nextUpdateTime) { nextUpdateTime += timeBetweenUpdates; var newLocation = Location.lastData; if (newLocation.timestamp > lastLocation.timestamp) { Coord = new LatLngPoint(newLocation.latitude, newLocation.longitude, newLocation.altitude); PlayerPrefs.SetString(COORD_KEY, coordFactory.ToString(Coord)); lastLocation = newLocation; OnPositionUpdated(); } } } if (DebugReport) { PrintDebugReport(); } }
/// <summary> /// Builds the GUI for editing <see cref="LatLngPoint"/> s. /// </summary> /// <param name="position"></param> /// <param name="property"></param> /// <param name="label"></param> public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (property is null) { throw new System.ArgumentNullException(nameof(property)); } EditorGUI.BeginProperty(position, label, property); position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); var indent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; if (property.isArray) { EditorGUI.PropertyField(position, property, false); } else { var latRect = new Rect(position.x, position.y, position.width / 2, position.height); var lngRect = new Rect(position.x + position.width / 2, position.y, position.width / 2, position.height); var curPoint = property.GetObject <LatLngPoint>(); var curLat = curPoint.Latitude.ToString(CultureInfo.InvariantCulture); var curLng = curPoint.Longitude.ToString(CultureInfo.InvariantCulture); EditorGUIUtility.labelWidth = 25; var nextLat = EditorGUI.TextField(latRect, labelLat, curLat); var nextLng = EditorGUI.TextField(lngRect, labelLng, curLng); if (float.TryParse(nextLat, out var lat) && float.TryParse(nextLng, out var lng)) { curPoint = new LatLngPoint(lat, lng); property.SetValue(curPoint); } } EditorGUI.indentLevel = indent; EditorGUI.EndProperty(); }
/// <summary> /// Converts this LatLngPoint to a UTM point that is stored as a Unity Vector3 object. /// </summary> /// <param name="value"></param> /// <returns></returns> public static Vector3 ToVector3(this LatLngPoint value) { return(value.ToUTM().ToVector3()); }