[TASK] Initial commit with basic product setup

This commit is contained in:
2019-08-18 13:50:14 +02:00
commit 01a66a8e1f
2548 changed files with 167528 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
namespace Mapbox.Unity.Utilities.Android
{
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class AndroidSettings
{
public static void Open()
{
try
{
#if UNITY_ANDROID
using (var unityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
using (AndroidJavaObject currentActivityObject = unityClass.GetStatic<AndroidJavaObject>("currentActivity"))
{
string packageName = currentActivityObject.Call<string>("getPackageName");
using (var uriClass = new AndroidJavaClass("android.net.Uri"))
{
using (AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("fromParts", "package", packageName, null))
{
using (var intentObject = new AndroidJavaObject("android.content.Intent", "android.settings.APPLICATION_DETAILS_SETTINGS", uriObject))
{
intentObject.Call<AndroidJavaObject>("addCategory", "android.intent.category.DEFAULT");
intentObject.Call<AndroidJavaObject>("setFlags", 0x10000000);
currentActivityObject.Call("startActivity", intentObject);
}
}
}
}
}
#endif
}
catch (Exception ex)
{
Debug.LogException(ex);
}
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 0e89e010c4fa7c04f9cdfc02a5775e35
timeCreated: 1521064502
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,60 @@
namespace Mapbox.Unity.Utilities
{
using UnityEngine;
using UnityEngine.UI;
public class Console : MonoBehaviour
{
[SerializeField]
Button _toggleButton;
[SerializeField]
GameObject _menu;
[SerializeField]
Text _logText;
[SerializeField]
ScrollRect _logScroll;
static Console _instance;
public static Console Instance { get { return _instance; } }
string _log;
protected virtual void Awake()
{
if (_instance != null)
{
Debug.LogError("Duplicate singleton!", gameObject);
}
_instance = this;
ClearLog();
}
void ClearLog()
{
_log = "";
_logText.text = _log;
_logScroll.verticalNormalizedPosition = 0f;
}
public void Log(string log, string color)
{
if (!string.IsNullOrEmpty(_log) && _log.Length > 15000)
{
_log = "";
}
_log += string.Format("<color={0}>{1}</color>\n", color, log);
_logText.text = _log;
_logScroll.verticalNormalizedPosition = 0f;
}
public void ToggleMenu()
{
_menu.SetActive(!_menu.activeSelf);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c0d8056b5e53e42499659c2c1007be20
timeCreated: 1502253530
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,423 @@
//-----------------------------------------------------------------------
// <copyright file="Conversions.cs" company="Mapbox">
// Copyright (c) 2016 Mapbox. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Mapbox.Unity.Utilities
{
using Mapbox.Map;
using System;
using Mapbox.Utils;
using UnityEngine;
using System.Globalization;
using Mapbox.Unity.MeshGeneration.Data;
/// <summary>
/// A set of Geo and Terrain Conversion utils.
/// </summary>
public static class Conversions
{
private const int TileSize = 256;
/// <summary>according to https://wiki.openstreetmap.org/wiki/Zoom_levels</summary>
private const int EarthRadius = 6378137; //no seams with globe example
private const double InitialResolution = 2 * Math.PI * EarthRadius / TileSize;
private const double OriginShift = 2 * Math.PI * EarthRadius / 2;
/// <summary>
/// Converts <see cref="T:Mapbox.Utils.Vector2d"/> struct, WGS84
/// lat/lon to Spherical Mercator EPSG:900913 xy meters.
/// </summary>
/// <param name="v"> The <see cref="T:Mapbox.Utils.Vector2d"/>. </param>
/// <returns> A <see cref="T:UnityEngine.Vector2d"/> of coordinates in meters. </returns>
public static Vector2d LatLonToMeters(Vector2d v)
{
return LatLonToMeters(v.x, v.y);
}
/// <summary>
/// Convert a simple string to a latitude longitude.
/// Expects format: latitude, longitude
/// </summary>
/// <returns>The lat/lon as Vector2d.</returns>
/// <param name="s">string.</param>
public static Vector2d StringToLatLon(string s)
{
var latLonSplit = s.Split(',');
if (latLonSplit.Length != 2)
{
throw new ArgumentException("Wrong number of arguments");
}
double latitude = 0;
double longitude = 0;
if (!double.TryParse(latLonSplit[0], NumberStyles.Any, NumberFormatInfo.InvariantInfo, out latitude))
{
throw new Exception(string.Format("Could not convert latitude to double: {0}", latLonSplit[0]));
}
if (!double.TryParse(latLonSplit[1], NumberStyles.Any, NumberFormatInfo.InvariantInfo, out longitude))
{
throw new Exception(string.Format("Could not convert longitude to double: {0}", latLonSplit[0]));
}
return new Vector2d(latitude, longitude);
}
/// <summary>
/// Converts WGS84 lat/lon to Spherical Mercator EPSG:900913 xy meters.
/// SOURCE: http://stackoverflow.com/questions/12896139/geographic-coordinates-converter.
/// </summary>
/// <param name="lat"> The latitude. </param>
/// <param name="lon"> The longitude. </param>
/// <returns> A <see cref="T:UnityEngine.Vector2d"/> of xy meters. </returns>
public static Vector2d LatLonToMeters(double lat, double lon)
{
var posx = lon * OriginShift / 180;
var posy = Math.Log(Math.Tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180);
posy = posy * OriginShift / 180;
return new Vector2d(posx, posy);
}
/// <summary>
/// Converts WGS84 lat/lon to x/y meters in reference to a center point
/// </summary>
/// <param name="lat"> The latitude. </param>
/// <param name="lon"> The longitude. </param>
/// <param name="refPoint"> A <see cref="T:UnityEngine.Vector2d"/> center point to offset resultant xy, this is usually map's center mercator</param>
/// <param name="scale"> Scale in meters. (default scale = 1) </param>
/// <returns> A <see cref="T:UnityEngine.Vector2d"/> xy tile ID. </returns>
/// <example>
/// Converts a Lat/Lon of (37.7749, 122.4194) into Unity coordinates for a map centered at (10,10) and a scale of 2.5 meters for every 1 Unity unit
/// <code>
/// var worldPosition = Conversions.GeoToWorldPosition(37.7749, 122.4194, new Vector2d(10, 10), (float)2.5);
/// // worldPosition = ( 11369163.38585, 34069138.17805 )
/// </code>
/// </example>
public static Vector2d GeoToWorldPosition(double lat, double lon, Vector2d refPoint, float scale = 1)
{
var posx = lon * OriginShift / 180;
var posy = Math.Log(Math.Tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180);
posy = posy * OriginShift / 180;
return new Vector2d((posx - refPoint.x) * scale, (posy - refPoint.y) * scale);
}
public static Vector2d GeoToWorldPosition(Vector2d latLong, Vector2d refPoint, float scale = 1)
{
return GeoToWorldPosition(latLong.x, latLong.y, refPoint, scale);
}
public static Vector3 GeoToWorldGlobePosition(double lat, double lon, float radius)
{
double xPos = (radius) * Math.Cos(Mathf.Deg2Rad * lat) * Math.Cos(Mathf.Deg2Rad * lon);
double zPos = (radius) * Math.Cos(Mathf.Deg2Rad * lat) * Math.Sin(Mathf.Deg2Rad * lon);
double yPos = (radius) * Math.Sin(Mathf.Deg2Rad * lat);
return new Vector3((float)xPos, (float)yPos, (float)zPos);
}
public static Vector3 GeoToWorldGlobePosition(Vector2d latLong, float radius)
{
return GeoToWorldGlobePosition(latLong.x, latLong.y, radius);
}
public static Vector2d GeoFromGlobePosition(Vector3 point, float radius)
{
float latitude = Mathf.Asin(point.y / radius);
float longitude = Mathf.Atan2(point.z, point.x);
return new Vector2d(latitude * Mathf.Rad2Deg, longitude * Mathf.Rad2Deg);
}
/// <summary>
/// Converts Spherical Mercator EPSG:900913 in xy meters to WGS84 lat/lon.
/// Inverse of LatLonToMeters.
/// </summary>
/// <param name="m"> A <see cref="T:UnityEngine.Vector2d"/> of coordinates in meters. </param>
/// <returns> The <see cref="T:Mapbox.Utils.Vector2d"/> in lat/lon. </returns>
/// <example>
/// Converts EPSG:900913 xy meter coordinates to lat lon
/// <code>
/// var worldPosition = new Vector2d (4547675.35434,13627665.27122);
/// var latlon = Conversions.MetersToLatLon(worldPosition);
/// // latlon = ( 37.77490, 122.41940 )
/// </code>
/// </example>
public static Vector2d MetersToLatLon(Vector2d m)
{
var vx = (m.x / OriginShift) * 180;
var vy = (m.y / OriginShift) * 180;
vy = 180 / Math.PI * (2 * Math.Atan(Math.Exp(vy * Math.PI / 180)) - Math.PI / 2);
return new Vector2d(vy, vx);
}
/// <summary>
/// Gets the xy tile ID from Spherical Mercator EPSG:900913 xy coords.
/// </summary>
/// <param name="m"> <see cref="T:UnityEngine.Vector2d"/> XY coords in meters. </param>
/// <param name="zoom"> Zoom level. </param>
/// <returns> A <see cref="T:UnityEngine.Vector2d"/> xy tile ID. </returns>
///
/// <example>
/// Converts EPSG:900913 xy meter coordinates to web mercator tile XY coordinates at zoom 12.
/// <code>
/// var meterXYPosition = new Vector2d (4547675.35434,13627665.27122);
/// var tileXY = Conversions.MetersToTile (meterXYPosition, 12);
/// // tileXY = ( 655, 2512 )
/// </code>
/// </example>
public static Vector2 MetersToTile(Vector2d m, int zoom)
{
var p = MetersToPixels(m, zoom);
return PixelsToTile(p);
}
/// <summary>
/// Gets the tile bounds in Spherical Mercator EPSG:900913 meters from an xy tile ID.
/// </summary>
/// <param name="tileCoordinate"> XY tile ID. </param>
/// <param name="zoom"> Zoom level. </param>
/// <returns> A <see cref="T:UnityEngine.Rect"/> in meters. </returns>
public static RectD TileBounds(Vector2 tileCoordinate, int zoom)
{
var min = PixelsToMeters(new Vector2d(tileCoordinate.x * TileSize, tileCoordinate.y * TileSize), zoom);
var max = PixelsToMeters(new Vector2d((tileCoordinate.x + 1) * TileSize, (tileCoordinate.y + 1) * TileSize), zoom);
return new RectD(min, max - min);
}
public static RectD TileBounds(UnwrappedTileId unwrappedTileId)
{
var min = PixelsToMeters(new Vector2d(unwrappedTileId.X * TileSize, unwrappedTileId.Y * TileSize), unwrappedTileId.Z);
var max = PixelsToMeters(new Vector2d((unwrappedTileId.X + 1) * TileSize, (unwrappedTileId.Y + 1) * TileSize), unwrappedTileId.Z);
return new RectD(min, max - min);
}
/// <summary>
/// Gets the xy tile ID at the requested zoom that contains the WGS84 lat/lon point.
/// See: http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames.
/// </summary>
/// <param name="latitude"> The latitude. </param>
/// <param name="longitude"> The longitude. </param>
/// <param name="zoom"> Zoom level. </param>
/// <returns> A <see cref="T:Mapbox.Map.UnwrappedTileId"/> xy tile ID. </returns>
public static UnwrappedTileId LatitudeLongitudeToTileId(double latitude, double longitude, int zoom)
{
var x = (int)Math.Floor((longitude + 180.0) / 360.0 * Math.Pow(2.0, zoom));
var y = (int)Math.Floor((1.0 - Math.Log(Math.Tan(latitude * Math.PI / 180.0)
+ 1.0 / Math.Cos(latitude * Math.PI / 180.0)) / Math.PI) / 2.0 * Math.Pow(2.0, zoom));
return new UnwrappedTileId(zoom, x, y);
}
/// <summary>
/// Get coordinates for a given latitude/longitude in tile-space. Useful when comparing feature geometry to lat/lon coordinates.
/// </summary>
/// <returns>The longitude to tile position.</returns>
/// <param name="coordinate">Coordinate.</param>
/// <param name="tileZoom">The zoom level of the tile.</param>
/// <param name="layerExtent">Layer extent. Optional, but recommended. Defaults to 4096, the standard for Mapbox Tiles</param>
public static Vector2 LatitudeLongitudeToVectorTilePosition(Vector2d coordinate, int tileZoom, ulong layerExtent = 4096)
{
var coordinateTileId = Conversions.LatitudeLongitudeToTileId(
coordinate.x, coordinate.y, tileZoom);
var _meters = LatLonToMeters(coordinate);
var _rect = Conversions.TileBounds(coordinateTileId);
//vectortile space point (0 - layerExtent)
var vectorTilePoint = new Vector2((float)((_meters - _rect.Min).x / _rect.Size.x) * layerExtent,
(float)(layerExtent - ((_meters - _rect.Max).y / _rect.Size.y) * layerExtent));
return vectorTilePoint;
}
public static Vector2 LatitudeLongitudeToUnityTilePosition(Vector2d coordinate, UnityTile tile, ulong layerExtent = 4096)
{
return LatitudeLongitudeToUnityTilePosition(coordinate, tile.CurrentZoom, tile.TileScale, layerExtent);
}
/// <summary>
/// Get coordinates for a given latitude/longitude in tile-space. Useful when comparing feature geometry to lat/lon coordinates.
/// </summary>
/// <returns>The longitude to tile position.</returns>
/// <param name="coordinate">Coordinate.</param>
/// <param name="tileZoom">The zoom level of the tile.</param>
/// <param name="tileScale">Tile scale. Optional, but recommended. Defaults to a scale of 1.</param>
/// <param name="layerExtent">Layer extent. Optional, but recommended. Defaults to 4096, the standard for Mapbox Tiles</param>
public static Vector2 LatitudeLongitudeToUnityTilePosition(Vector2d coordinate, int tileZoom, float tileScale, ulong layerExtent = 4096)
{
var coordinateTileId = Conversions.LatitudeLongitudeToTileId(
coordinate.x, coordinate.y, tileZoom);
var _rect = Conversions.TileBounds(coordinateTileId);
//vectortile space point (0 - layerExtent)
var vectorTilePoint = LatitudeLongitudeToVectorTilePosition(coordinate, tileZoom, layerExtent);
//UnityTile space
var unityTilePoint = new Vector2((float)(vectorTilePoint.x / layerExtent * _rect.Size.x - (_rect.Size.x / 2)) * tileScale,
(float)((layerExtent - vectorTilePoint.y) / layerExtent * _rect.Size.y - (_rect.Size.y / 2)) * tileScale);
return unityTilePoint;
}
/// <summary>
/// Gets the WGS84 longitude of the northwest corner from a tile's X position and zoom level.
/// See: http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames.
/// </summary>
/// <param name="x"> Tile X position. </param>
/// <param name="zoom"> Zoom level. </param>
/// <returns> NW Longitude. </returns>
public static double TileXToNWLongitude(int x, int zoom)
{
var n = Math.Pow(2.0, zoom);
var lon_deg = x / n * 360.0 - 180.0;
return lon_deg;
}
/// <summary>
/// Gets the WGS84 latitude of the northwest corner from a tile's Y position and zoom level.
/// See: http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames.
/// </summary>
/// <param name="y"> Tile Y position. </param>
/// <param name="zoom"> Zoom level. </param>
/// <returns> NW Latitude. </returns>
public static double TileYToNWLatitude(int y, int zoom)
{
var n = Math.Pow(2.0, zoom);
var lat_rad = Math.Atan(Math.Sinh(Math.PI * (1 - 2 * y / n)));
var lat_deg = lat_rad * 180.0 / Math.PI;
return lat_deg;
}
/// <summary>
/// Gets the <see cref="T:Mapbox.Utils.Vector2dBounds"/> of a tile.
/// </summary>
/// <param name="x"> Tile X position. </param>
/// <param name="y"> Tile Y position. </param>
/// <param name="zoom"> Zoom level. </param>
/// <returns> The <see cref="T:Mapbox.Utils.Vector2dBounds"/> of the tile. </returns>
public static Vector2dBounds TileIdToBounds(int x, int y, int zoom)
{
var sw = new Vector2d(TileYToNWLatitude(y, zoom), TileXToNWLongitude(x + 1, zoom));
var ne = new Vector2d(TileYToNWLatitude(y + 1, zoom), TileXToNWLongitude(x, zoom));
return new Vector2dBounds(sw, ne);
}
/// <summary>
/// Gets the WGS84 lat/lon of the center of a tile.
/// </summary>
/// <param name="x"> Tile X position. </param>
/// <param name="y"> Tile Y position. </param>
/// <param name="zoom"> Zoom level. </param>
/// <returns>A <see cref="T:UnityEngine.Vector2d"/> of lat/lon coordinates.</returns>
public static Vector2d TileIdToCenterLatitudeLongitude(int x, int y, int zoom)
{
var bb = TileIdToBounds(x, y, zoom);
var center = bb.Center;
return new Vector2d(center.x, center.y);
}
/// <summary>
/// Gets the Web Mercator x/y of the center of a tile.
/// </summary>
/// <param name="x"> Tile X position. </param>
/// <param name="y"> Tile Y position. </param>
/// <param name="zoom"> Zoom level. </param>
/// <returns>A <see cref="T:UnityEngine.Vector2d"/> of lat/lon coordinates.</returns>
public static Vector2d TileIdToCenterWebMercator(int x, int y, int zoom)
{
double tileCnt = Math.Pow(2, zoom);
double centerX = x + 0.5;
double centerY = y + 0.5;
centerX = ((centerX / tileCnt * 2) - 1) * Constants.WebMercMax;
centerY = (1 - (centerY / tileCnt * 2)) * Constants.WebMercMax;
return new Vector2d(centerX, centerY);
}
/// <summary>
/// Gets the meters per pixels at given latitude and zoom level for a 256x256 tile.
/// See: http://wiki.openstreetmap.org/wiki/Zoom_levels.
/// </summary>
/// <param name="latitude"> The latitude. </param>
/// <param name="zoom"> Zoom level. </param>
/// <returns> Meters per pixel. </returns>
public static float GetTileScaleInMeters(float latitude, int zoom)
{
return (float)(40075016.685578d * Math.Cos(Mathf.Deg2Rad * latitude) / Math.Pow(2f, zoom + 8));
}
/// <summary>
/// Gets the degrees per tile at given zoom level for Web Mercator tile.
/// See: http://wiki.openstreetmap.org/wiki/Zoom_levels.
/// </summary>
/// <param name="latitude"> The latitude. </param>
/// <param name="zoom"> Zoom level. </param>
/// <returns> Degrees per tile. </returns>
public static float GetTileScaleInDegrees(float latitude, int zoom)
{
return (float)(360.0f / Math.Pow(2f, zoom + 8));
}
/// <summary>
/// Gets height from terrain-rgb adjusted for a given scale.
/// </summary>
/// <param name="color"> The <see cref="T:UnityEngine.Color"/>. </param>
/// <param name="relativeScale"> Relative scale. </param>
/// <returns> Adjusted height in meters. </returns>
public static float GetRelativeHeightFromColor(Color color, float relativeScale)
{
return GetAbsoluteHeightFromColor(color) * relativeScale;
}
/// <summary>
/// Specific formula for mapbox.terrain-rgb to decode height values from pixel values.
/// See: https://www.mapbox.com/blog/terrain-rgb/.
/// </summary>
/// <param name="color"> The <see cref="T:UnityEngine.Color"/>. </param>
/// <returns> Height in meters. </returns>
public static float GetAbsoluteHeightFromColor(Color color)
{
return (float)(-10000 + ((color.r * 255 * 256 * 256 + color.g * 255 * 256 + color.b * 255) * 0.1));
}
public static float GetAbsoluteHeightFromColor32(Color32 color)
{
return (float)(-10000 + ((color.r * 256 * 256 + color.g * 256 + color.b) * 0.1));
}
public static float GetAbsoluteHeightFromColor(float r, float g, float b)
{
return (float)(-10000 + ((r * 256 * 256 + g * 256 + b) * 0.1));
}
private static double Resolution(int zoom)
{
return InitialResolution / Math.Pow(2, zoom);
}
private static Vector2d PixelsToMeters(Vector2d p, int zoom)
{
var res = Resolution(zoom);
var met = new Vector2d();
met.x = (p.x * res - OriginShift);
met.y = -(p.y * res - OriginShift);
return met;
}
private static Vector2d MetersToPixels(Vector2d m, int zoom)
{
var res = Resolution(zoom);
var pix = new Vector2d(((m.x + OriginShift) / res), ((-m.y + OriginShift) / res));
return pix;
}
private static Vector2 PixelsToTile(Vector2d p)
{
var t = new Vector2((int)Math.Ceiling(p.x / (double)TileSize) - 1, (int)Math.Ceiling(p.y / (double)TileSize) - 1);
return t;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 298fcb875e96e4d6f9b039f9f30aad82
timeCreated: 1483998783
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: c2f9985805e6d4227a776425b7c33ca4
folderAsset: yes
timeCreated: 1512101271
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,13 @@
namespace Mapbox.Unity.Utilities.DebugTools
{
using UnityEngine;
public class SceneData : ScriptableObject
{
public string Name;
public string ScenePath;
public Texture2D Image;
public TextAsset Text;
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e5d9ef4c9a5f1410ea3cf247b3917654
timeCreated: 1512584162
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,59 @@
namespace Mapbox.Unity.Utilities.DebugTools
{
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class ScenesList : ScriptableObject
{
public SceneData[] SceneList;
//ensure that linked scenes are stored in this object
#if UNITY_EDITOR
public void LinkScenes()
{
for (int i = 0; i < SceneList.Length; i++)
{
if (!ThisAssetContainsScene(SceneList[i]))
{
//duplicate the asset
var path = AssetDatabase.GetAssetPath(this);
var newScene = ScriptableObject.CreateInstance<SceneData>();
newScene.name = SceneList[i].name;
newScene.ScenePath = SceneList[i].ScenePath;
newScene.Text = SceneList[i].Text;
newScene.Image = SceneList[i].Image;
//assign it to the current scene list
AssetDatabase.AddObjectToAsset(newScene, path);
SceneList[i] = newScene;
//save the scenelist
EditorUtility.SetDirty(this);
AssetDatabase.SaveAssets();
//TODO: clean up unreferenced sub-assets with Destroy
}
}
}
private bool ThisAssetContainsScene(SceneData scene)
{
var path = AssetDatabase.GetAssetPath(this);
Object[] assets = AssetDatabase.LoadAllAssetsAtPath(path);
foreach (var asset in assets)
{
if (asset == scene)
{
//Debug.Log("Asset " + scene + " is contained in " + path);
return true;
}
}
return false;
}
#endif
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c331d4375e95e4050aadbf5ed3492bba
timeCreated: 1512102887
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,22 @@
namespace Mapbox.VectorTile.Geometry
{
using System;
#if ENABLE_WINMD_SUPPORT
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
public class DescriptionAttribute : Attribute
{
private readonly string description;
public string Description { get { return description; } }
public DescriptionAttribute(string description)
{
this.description = description;
}
}
#endif
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3ec8e3a68b131f54489938159f37c582
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,24 @@
namespace Mapbox.Unity.Utilities
{
using UnityEngine;
public class DontDestroyOnLoad : MonoBehaviour
{
static DontDestroyOnLoad _instance;
[SerializeField]
bool _useSingleInstance;
protected virtual void Awake()
{
if (_instance != null && _useSingleInstance)
{
Destroy(gameObject);
return;
}
_instance = this;
DontDestroyOnLoad(gameObject);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 6db3a516f4a7041b4a415b35843f8841
timeCreated: 1512101563
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,14 @@
namespace Mapbox.Unity.Utilities
{
using UnityEngine;
/// <summary>
/// Property attribute used to create custom Geocode GUI field<para/>
/// Links to custom drawer:
/// <see cref="T:Mapbox.Editor.GeocodeAttributeDrawer"/>.
/// </summary>
public class GeocodeAttribute : PropertyAttribute
{
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 58ead4aa98d3e8c41972efbfcefbf74f
timeCreated: 1484134774
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,102 @@
//-----------------------------------------------------------------------
// <copyright file="HTTPRequest.cs" company="Mapbox">
// Copyright (c) 2016 Mapbox. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Mapbox.Unity.Utilities
{
using System;
using UnityEngine.Networking;
using System.Collections;
using Mapbox.Platform;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public enum HttpRequestType
{
Get,
Head
}
internal sealed class HTTPRequest : IAsyncRequest
{
private UnityWebRequest _request;
private HttpRequestType _requestType;
private int _timeout;
private readonly Action<Response> _callback;
public bool IsCompleted { get; private set; }
public HttpRequestType RequestType { get { return _requestType; } }
// TODO: simplify timeout for Unity 5.6+
// https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest-timeout.html
public HTTPRequest(string url, Action<Response> callback, int timeout, HttpRequestType requestType = HttpRequestType.Get)
{
IsCompleted = false;
_requestType = requestType;
switch (_requestType)
{
case HttpRequestType.Get:
_request = UnityWebRequest.Get(url);
break;
case HttpRequestType.Head:
_request = UnityWebRequest.Head(url);
break;
default:
_request = UnityWebRequest.Get(url);
break;
}
_request.timeout = timeout;
_callback = callback;
#if UNITY_EDITOR
if (!EditorApplication.isPlaying)
{
Runnable.EnableRunnableInEditor();
}
#endif
Runnable.Run(DoRequest());
}
public void Cancel()
{
if (_request != null)
{
_request.Abort();
}
}
private IEnumerator DoRequest()
{
#if UNITY_EDITOR
// otherwise requests don't work in Edit mode, eg geocoding
// also lot of EditMode tests fail otherwise
#pragma warning disable 0618
_request.Send();
#pragma warning restore 0618
while (!_request.isDone) { yield return null; }
#else
#pragma warning disable 0618
yield return _request.Send();
#pragma warning restore 0618
#endif
var response = Response.FromWebResponse(this, _request, null);
_callback(response);
_request.Dispose();
_request = null;
IsCompleted = true;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0af41ebc1f8e7485d93cb4b9070e9d1a
timeCreated: 1482363481
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,70 @@
namespace Mapbox.Unity.Utilities
{
using Mapbox.Unity.Map;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
public class MapVisualizerPerformance : MonoBehaviour
{
private Stopwatch _sw = new Stopwatch();
private AbstractMap _map;
private AbstractMapVisualizer _mapVisualizer;
public int TestCount = 10;
private int _currentTest = 1;
[NonSerialized]
public float TotalTime = 0;
private float _firstRun;
protected virtual void Awake()
{
TotalTime = 0;
_currentTest = 1;
_map = FindObjectOfType<AbstractMap>();
_mapVisualizer = _map.MapVisualizer;
_mapVisualizer.OnMapVisualizerStateChanged += (s) =>
{
if (s == ModuleState.Working)
{
_sw.Reset();
_sw.Start();
}
else if (s == ModuleState.Finished)
{
_sw.Stop();
if (_currentTest > 1)
{
TotalTime += _sw.ElapsedMilliseconds;
UnityEngine.Debug.Log("Test " + _currentTest + ": " + _sw.ElapsedMilliseconds);
}
else
{
_firstRun = _sw.ElapsedMilliseconds;
}
if (TestCount > _currentTest)
{
_currentTest++;
Invoke("Run", 1f);
}
else
{
if (_currentTest > 1)
{
UnityEngine.Debug.Log("First Run: " + _firstRun + " \r\nRest Average: " + TotalTime / (_currentTest - 1));
}
}
}
};
}
public void Run()
{
//TODO : FIX THIS ERROR
//_map.Reset();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 49949b46d9cfc4a4b9d2419caf98f859
timeCreated: 1509058153
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,16 @@
namespace Mapbox.Unity.Utilities
{
using UnityEngine;
using System.Collections;
using System;
public class NodeEditorElementAttribute : Attribute
{
public string Name;
public NodeEditorElementAttribute(string s)
{
Name = s;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c03cf5b7204de7844baa0bc6167637bc
timeCreated: 1502156751
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,43 @@
namespace Mapbox.Unity.MeshGeneration.Data
{
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjectPool<T>
{
private Queue<T> _objects;
private Func<T> _objectGenerator;
public ObjectPool(Func<T> objectGenerator)
{
if (objectGenerator == null) throw new ArgumentNullException("objectGenerator");
_objects = new Queue<T>();
_objectGenerator = objectGenerator;
}
public T GetObject()
{
if (_objects.Count > 0)
return _objects.Dequeue();
return _objectGenerator();
}
public void Put(T item)
{
_objects.Enqueue(item);
}
public void Clear()
{
_objects.Clear();
}
public IEnumerable<T> GetQueue()
{
return _objects;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 8e82366f4588af547bebd4cdaa52acfb
timeCreated: 1507502644
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,22 @@
namespace Mapbox.Unity.Utilities
{
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(Button))]
public class OpenUrlOnButtonClick : MonoBehaviour
{
[SerializeField]
string _url;
protected virtual void Awake()
{
GetComponent<Button>().onClick.AddListener(VisitUrl);
}
void VisitUrl()
{
Application.OpenURL(_url);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7d2bfe282373c4419b3edefc8dd20f68
timeCreated: 1495663466
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,70 @@
namespace Mapbox.Utils
{
using System.Collections.Generic;
using Mapbox.VectorTile.Geometry;
public static class PolygonUtils
{
/// <summary>
/// <para>Method to check if a point is contained inside a polygon, ignores vertical axis (y axis)</para>
/// <para>from https://stackoverflow.com/a/7123291</para>
/// </summary>
/// <returns><c>true</c>, if point lies inside the constructed polygon, <c>false</c> otherwise.</returns>
/// <param name="polygon">Polygon points.</param>
/// <param name="p">The point that is to be tested.</param>
public static bool PointInPolygon(Point2d<float> p, List<List<Point2d<float>>> polygon)
{
List<Point2d<float>> poly = polygon[0];
Point2d<float> p1;
Point2d<float> p2;
bool inside = false;
if (poly.Count < 3)
{
return inside;
}
var oldPoint = new Point2d<float>(
poly[poly.Count - 1].X
, poly[poly.Count - 1].Y
);
for (int i = 0; i < poly.Count; i++)
{
var newPoint = new Point2d<float>(poly[i].X, poly[i].Y);
if (newPoint.X > oldPoint.X)
{
p1 = oldPoint;
p2 = newPoint;
}
else
{
p1 = newPoint;
p2 = oldPoint;
}
if (
(newPoint.X < p.X) == (p.X <= oldPoint.X)
&& (p.Y - (long)p1.Y) * (p2.X - p1.X) < (p2.Y - (long)p1.Y) * (p.X - p1.X)
)
{
inside = !inside;
}
oldPoint = newPoint;
}
return inside;
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: a8bec9161e1794b4eb4297f7098296d7
timeCreated: 1526332346
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,172 @@
/**
* Copyright 2015 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
// Uncomment to enable debugging of the Runnable class.
//#define ENABLE_RUNNABLE_DEBUGGING
namespace Mapbox.Unity.Utilities
{
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// Helper class for running co-routines without having to inherit from MonoBehavior.
/// </summary>
public class Runnable : MonoBehaviour
{
#region Public Properties
/// <summary>
/// Returns the Runnable instance.
/// </summary>
public static Runnable Instance { get { return Singleton<Runnable>.Instance; } }
#endregion
#region Public Interface
/// <summary>
/// Start a co-routine function.
/// </summary>
/// <param name="routine">The IEnumerator returns by the co-routine function the user is invoking.</param>
/// <returns>Returns a ID that can be passed into Stop() to halt the co-routine.</returns>
public static int Run(IEnumerator routine)
{
Routine r = new Routine(routine);
return r.ID;
}
/// <summary>
/// Stops a active co-routine.
/// </summary>
/// <param name="ID">THe ID of the co-routine to stop.</param>
public static void Stop(int ID)
{
Routine r = null;
if (Instance.m_Routines.TryGetValue(ID, out r))
r.Stop = true;
}
/// <summary>
/// Check if a routine is still running.
/// </summary>
/// <param name="id">The ID returned by Run().</param>
/// <returns>Returns true if the routine is still active.</returns>
static public bool IsRunning(int id)
{
return Instance.m_Routines.ContainsKey(id);
}
#if UNITY_EDITOR
private static bool sm_EditorRunnable = false;
/// <summary>
/// This function enables the Runnable in edit mode.
/// </summary>
public static void EnableRunnableInEditor()
{
if (!sm_EditorRunnable)
{
sm_EditorRunnable = true;
UnityEditor.EditorApplication.update += UpdateRunnable;
}
}
static void UpdateRunnable()
{
if (!Application.isPlaying)
{
Instance.UpdateRoutines();
}
}
#endif
#endregion
#region Private Types
/// <summary>
/// This class handles a running co-routine.
/// </summary>
private class Routine : IEnumerator
{
#region Public Properties
public int ID { get; private set; }
public bool Stop { get; set; }
#endregion
#region Private Data
private bool m_bMoveNext = false;
private IEnumerator m_Enumerator = null;
#endregion
public Routine(IEnumerator a_enumerator)
{
m_Enumerator = a_enumerator;
Runnable.Instance.StartCoroutine(this);
Stop = false;
ID = Runnable.Instance.m_NextRoutineId++;
Runnable.Instance.m_Routines[ID] = this;
#if ENABLE_RUNNABLE_DEBUGGING
Debug.Log( string.Format("Coroutine {0} started.", ID ) );
#endif
}
#region IEnumerator Interface
public object Current { get { return m_Enumerator.Current; } }
public bool MoveNext()
{
m_bMoveNext = m_Enumerator.MoveNext();
if (m_bMoveNext && Stop)
m_bMoveNext = false;
if (!m_bMoveNext)
{
Runnable.Instance.m_Routines.Remove(ID); // remove from the mapping
#if ENABLE_RUNNABLE_DEBUGGING
Debug.Log( string.Format("Coroutine {0} stopped.", ID ) );
#endif
}
return m_bMoveNext;
}
public void Reset() { m_Enumerator.Reset(); }
#endregion
}
#endregion
#region Private Data
private Dictionary<int, Routine> m_Routines = new Dictionary<int, Routine>();
private int m_NextRoutineId = 1;
#endregion
/// <summary>
/// THis can be called by the user to force all co-routines to get a time slice, this is usually
/// invoked from an EditorApplication.Update callback so we can use runnable in Editor mode.
/// </summary>
public void UpdateRoutines()
{
if (m_Routines.Count > 0)
{
// we are not in play mode, so we must manually update our co-routines ourselves
List<Routine> routines = new List<Routine>();
foreach (var kp in m_Routines)
routines.Add(kp.Value);
foreach (var r in routines)
r.MoveNext();
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b87b2c1373aae46cda00a35c701735a8
timeCreated: 1490371125
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,84 @@
/**
* Copyright 2015 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
//#define SINGLETONS_VISIBLE
namespace Mapbox.Unity.Utilities {
using UnityEngine;
using System;
#if NETFX_CORE
using System.Reflection;
#endif
/// <summary>
/// Singleton pattern class. This class detects if T is a MonoBehavior and will
/// make a containing GameObject.
/// </summary>
/// <typeparam name="T">The typename of the class to create as a singleton object.</typeparam>
/// <remarks>An instance of this class needs to be of type <c>UnityEngine.Object</c> As long as this is used with UnityEngine classes, this should work fine. This is to resolve issue #116 <see href="https://github.com/mapbox/mapbox-unity-sdk/issues/116"/> </remarks>
public class Singleton<T> where T : UnityEngine.Object {
#region Private Data
static private T sm_Instance = null;
#endregion
#region Public Properties
/// <summary>
/// Returns the Singleton instance of T.
/// </summary>
public static T Instance {
get {
if (sm_Instance == null)
CreateInstance();
return sm_Instance;
}
}
#endregion
#region Singleton Creation
/// <summary>
/// Create the singleton instance.
/// </summary>
private static void CreateInstance() {
#if NETFX_CORE
if (typeof(MonoBehaviour).GetTypeInfo().IsAssignableFrom(typeof(T).GetTypeInfo())) {
#else
if (typeof(MonoBehaviour).IsAssignableFrom(typeof(T))) {
#endif
string singletonName = "_" + typeof(T).Name;
GameObject singletonObject = GameObject.Find(singletonName);
if (singletonObject == null)
singletonObject = new GameObject(singletonName);
#if SINGLETONS_VISIBLE
singletonObject.hideFlags = HideFlags.DontSave;
#else
singletonObject.hideFlags = HideFlags.HideAndDontSave;
#endif
sm_Instance = singletonObject.GetComponent<T>();
if (sm_Instance == null)
sm_Instance = singletonObject.AddComponent(typeof(T)) as T;
} else {
sm_Instance = Activator.CreateInstance(typeof(T)) as T;
}
if (sm_Instance == null)
throw new Exception("Failed to create instance " + typeof(T).Name);
}
#endregion
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a6eab0daac2d048669b548ca8aa46e33
timeCreated: 1490371156
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,21 @@
namespace Mapbox.Unity.Utilities
{
using System.Linq;
using UnityEngine;
public abstract class SingletonScriptableObject<T> : ScriptableObject where T : ScriptableObject
{
static T _instance = null;
public static T Instance
{
get
{
if (!_instance)
{
_instance = Resources.FindObjectsOfTypeAll<T>().FirstOrDefault();
}
return _instance;
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: bdbbf7395941a4ca09714114a184a222
timeCreated: 1499958792
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,14 @@
namespace Mapbox.Unity.Utilities
{
using UnityEngine;
/// <summary>
/// Property attribute used to search for styles associated with API token.<para/>
/// Links to custom drawer:
/// <see cref="T:Mapbox.Editor.StyleSearchAttributeDrawer"/>.
/// </summary>
public class StyleSearchAttribute : PropertyAttribute
{
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e0cf90e1694114eb59752c674484735f
timeCreated: 1500479391
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
namespace Mapbox.Unity.Utilities
{
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(Button))]
public class TelemetryConfigurationButton : MonoBehaviour
{
[SerializeField]
bool _booleanValue;
protected virtual void Awake()
{
GetComponent<Button>().onClick.AddListener(SetPlayerPref);
}
void SetPlayerPref()
{
MapboxAccess.Instance.SetLocationCollectionState(_booleanValue);
PlayerPrefs.Save();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 859a38e5f727a4ea7ad0839a89bcd655
timeCreated: 1495727882
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,18 @@
namespace Mapbox.Unity.MeshGeneration.Data
{
using Mapbox.Unity.MeshGeneration.Components;
using Mapbox.Unity.MeshGeneration.Data;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class VectorEntity
{
public GameObject GameObject;
public MeshFilter MeshFilter;
public Mesh Mesh;
public MeshRenderer MeshRenderer;
public VectorFeatureUnity Feature;
public Transform Transform;
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 528efe6105d5b1a4383498575196de07
timeCreated: 1507239975
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,139 @@
//-----------------------------------------------------------------------
// <copyright file="VectorExtensions.cs" company="Mapbox">
// Copyright (c) 2016 Mapbox. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Mapbox.Unity.Utilities
{
using Mapbox.Utils;
using UnityEngine;
public static class VectorExtensions
{
/// <summary>
/// Vector2 convenience method to convert Vector2 to Vector3.
/// </summary>
/// <returns>Vector3 with a y value of zero.</returns>
/// <param name="v">Vector2.</param>
public static Vector3 ToVector3xz(this Vector2 v)
{
return new Vector3(v.x, 0, v.y);
}
/// <summary>
/// Vector2d convenience method to convert Vector2d to Vector3.
/// </summary>
/// <returns>Vector3 with a y value of zero.</returns>
/// <param name="v">Vector2d.</param>
public static Vector3 ToVector3xz(this Vector2d v)
{
return new Vector3((float)v.x, 0, (float)v.y);
}
/// <summary>
/// Vector3 convenience method to convert Vector3 to Vector2.
/// </summary>
/// <returns>The Vector2.</returns>
/// <param name="v">Vector3.</param>
public static Vector2 ToVector2xz(this Vector3 v)
{
return new Vector2(v.x, v.z);
}
/// <summary>
/// Vector3 convenience method to convert Vector3 to Vector2d.
/// </summary>
/// <returns>The Vector2d.</returns>
/// <param name="v">Vector3.</param>
public static Vector2d ToVector2d(this Vector3 v)
{
return new Vector2d(v.x, v.z);
}
/// <summary>
/// Transform extension method to move a Unity transform to a specific latitude/longitude.
/// </summary>
/// <param name="t">Transform.</param>
/// <param name="lat">Latitude.</param>
/// <param name="lng">Longitude.</param>
/// <param name="refPoint">Reference point.</param>
/// <param name="scale">Scale.</param>
/// <example>
/// Place a Unity transform at 10, 10, with a map center of (0, 0) and scale 1:
/// <code>
/// transform.MoveToGeocoordinate(10, 10, new Vector2d(0, 0), 1f);
/// Debug.Log(transform.position);
/// // (1113195.0, 0.0, 1118890.0)
/// </code>
/// </example>
public static void MoveToGeocoordinate(this Transform t, double lat, double lng, Vector2d refPoint, float scale = 1)
{
t.position = Conversions.GeoToWorldPosition(lat, lng, refPoint, scale).ToVector3xz();
}
/// <summary>
/// Transform extension method to move a Unity transform to a specific Vector2d.
/// </summary>
/// <param name="t">Transform.</param>
/// <param name="latLon">Latitude Longitude.</param>
/// <param name="refPoint">Reference point.</param>
/// <param name="scale">Scale.</param>
/// <example>
/// Place a Unity transform at 10, 10, with a map center of (0, 0) and scale 1:
/// <code>
/// transform.MoveToGeocoordinate(new Vector2d(10, 10), new Vector2d(0, 0), 1f);
/// Debug.Log(transform.position);
/// // (1113195.0, 0.0, 1118890.0)
/// </code>
/// </example>
public static void MoveToGeocoordinate(this Transform t, Vector2d latLon, Vector2d refPoint, float scale = 1)
{
t.MoveToGeocoordinate(latLon.x, latLon.y, refPoint, scale);
}
/// <summary>
/// Vector2 extension method to convert from a latitude/longitude to a Unity Vector3.
/// </summary>
/// <returns>The Vector3 Unity position.</returns>
/// <param name="latLon">Latitude Longitude.</param>
/// <param name="refPoint">Reference point.</param>
/// <param name="scale">Scale.</param>
public static Vector3 AsUnityPosition(this Vector2 latLon, Vector2d refPoint, float scale = 1)
{
return Conversions.GeoToWorldPosition(latLon.x, latLon.y, refPoint, scale).ToVector3xz();
}
/// <summary>
/// Transform extension method to return the transform's position as a Vector2d latitude/longitude.
/// </summary>
/// <returns>Vector2d that represents latitude/longitude.</returns>
/// <param name="t">T.</param>
/// <param name="refPoint">Reference point.</param>
/// <param name="scale">Scale.</param>
/// <example>
/// Get the latitude/longitude of a transform at (1113195, 0, 1118890), map center (0, 0) and scale 1.
/// <code>
/// var latLng = transform.GetGeoPosition(new Vector2d(0, 0), 1);
/// Debug.Log(latLng);
/// // (10.00000, 10.00000)
/// </code>
/// </example>
public static Vector2d GetGeoPosition(this Transform t, Vector2d refPoint, float scale = 1)
{
var pos = refPoint + (t.position / scale).ToVector2d();
return Conversions.MetersToLatLon(pos);
}
public static Vector2d GetGeoPosition(this Vector3 position, Vector2d refPoint, float scale = 1)
{
var pos = refPoint + (position / scale).ToVector2d();
return Conversions.MetersToLatLon(pos);
}
public static Vector2d GetGeoPosition(this Vector2 position, Vector2d refPoint, float scale = 1)
{
return position.ToVector3xz().GetGeoPosition(refPoint, scale);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c1f035bcb5a8d45419d1342c88c8d47c
timeCreated: 1478552630
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: