protected void Awake() { if (tileTemplate == null) { tileTemplate = TileBehaviour.CreateTileTemplate(); tileTemplate.hideFlags = HideFlags.HideAndDontSave; tileTemplate.GetComponent <Renderer>().enabled = false; } ++tileTemplateUseCount; }
/// <summary> /// Implementation of <see cref="http://docs.unity3d.com/ScriptReference/MonoBehaviour.html">MonoBehaviour</see>.Awake(). /// </summary> protected void Awake() { // create the tile template if needed if (tileTemplate == null) { tileTemplate = TileBehaviour.CreateTileTemplate(); tileTemplate.hideFlags = HideFlags.HideAndDontSave; tileTemplate.renderer.enabled = false; } ++tileTemplateUseCount; }
void CreateMarkerWhenReady() { // create some test 2D markers area = GameObject.Find("ARCamera").GetComponent <DynamicDataSetLoader>().area; if (area != null && finished == false) { GameObject go = TileBehaviour.CreateTileTemplate(TileBehaviour.AnchorPoint.BottomCenter).gameObject; go.GetComponent <Renderer>().material.mainTexture = MarkerTexture; go.GetComponent <Renderer>().material.renderQueue = 4001; go.transform.localScale = new Vector3(0.70588235294118f, 1.0f, 1.0f); go.transform.localScale /= 3.0f; go.AddComponent <CameraFacingBillboard>().Axis = Vector3.up; GameObject markerGO; GameObject parentGo = GameObject.Find("myui"); Vector2 size = parentGo.GetComponent <RectTransform>().sizeDelta; Vector2 scale = parentGo.GetComponent <RectTransform>().localScale; parentGo.GetComponent <RectTransform>().localPosition = new Vector3(Screen.width / 2 - size.x * scale.x / 2, Screen.height / 2 - size.y * scale.y / 2, 0f); foreach (POI poi in area.POIs) { markerGO = Instantiate(go) as GameObject; map.CreateMarker <MarkerBehaviour>(poi.Name, new double[2] { poi.Longitude, poi.Latitude }, markerGO); markerGO.name = poi.Name; poi.SetMarkerObj(markerGO); GameObject mapPoint = GameObject.Find("mypoi"); GameObject newmapPoint = Instantiate(mapPoint) as GameObject; newmapPoint.transform.parent = parentGo.transform; newmapPoint.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f); poi.SetmapPOI(newmapPoint); userPosition = new GPSlocation(51.5221, -0.131411); double dis = poi.GetDistance(userPosition); poi.GetmapPOI().GetComponent <Map>().distance = (float)dis / 7; newmapPoint.GetComponent <Map>().p = poi; } GameObject map2 = GameObject.Find("mypoi"); map2.SetActive(false); finished = true; DestroyImmediate(go); } }
/// <summary> /// Implementation of <see cref="http://docs.unity3d.com/ScriptReference/MonoBehaviour.html">MonoBehaviour</see>.Start(). /// </summary> private void Start() { // create the tile template if needed if (tileTemplate == null) { Debug.Log("Shader is " + Shader); tileTemplate = TileBehaviour.CreateTileTemplate(Shader); tileTemplate.hideFlags = HideFlags.HideAndDontSave; tileTemplate.GetComponent <Renderer>().enabled = false; } ++tileTemplateUseCount; if (tileTemplate.transform.localScale.x != Map.RoundedHalfMapScale) { tileTemplate.transform.localScale = new Vector3(Map.RoundedHalfMapScale, 1.0f, Map.RoundedHalfMapScale); } }
private IEnumerator Start() { // setup the gui scale according to the screen resolution guiXScale = (Screen.orientation == ScreenOrientation.Landscape ? Screen.width : Screen.height) / 480.0f; guiYScale = (Screen.orientation == ScreenOrientation.Landscape ? Screen.height : Screen.width) / 640.0f; // setup the gui area guiRect = new Rect(16.0f * guiXScale, 4.0f * guiXScale, Screen.width / guiXScale - 32.0f * guiXScale, 32.0f * guiYScale); // create the map singleton map = MapBehaviour.Instance; map.CurrentCamera = Camera.main; map.InputDelegate += UnitySlippyMap.Input.MapInput.BasicTouchAndKeyboard; map.CurrentZoom = 19.0f; //map.CenterWGS84 = new double[2] { 5.94780, 49.50478 }; //TEST Centralize the map //current location thingy GPS locationGiver = new GPS(); float longitude = locationGiver.longtitude; float latitude = locationGiver.latitude; Text myText = GameObject.Find("Canvas/Text").GetComponent <Text>(); myText.text = "longitude :" + longitude + " latitude : " + latitude; map.CenterWGS84 = new double[2] { latitude, longitude }; //Test END map.UsesLocation = true; map.InputsEnabled = true; map.ShowsGUIControls = true; map.GUIDelegate += Toolbar; layers = new List <LayerBehaviour>(); // create an OSM tile layer OSMTileLayer osmLayer = map.CreateLayer <OSMTileLayer>("OSM"); osmLayer.BaseURL = "http://a.tile.openstreetmap.org/"; layers.Add(osmLayer); // create a VirtualEarth tile layer /*VirtualEarthTileLayerBehaviour virtualEarthLayer = map.CreateLayer<VirtualEarthTileLayerBehaviour>("VirtualEarth"); * // Note: this is the key UnitySlippyMap, DO NOT use it for any other purpose than testing * virtualEarthLayer.Key = "ArgkafZs0o_PGBuyg468RaapkeIQce996gkyCe8JN30MjY92zC_2hcgBU_rHVUwT"; * #if UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9 * virtualEarthLayer.gameObject.SetActiveRecursively(false); #else * virtualEarthLayer.gameObject.SetActive(false); #endif * * layers.Add(virtualEarthLayer);*/ // create an MBTiles tile layer bool error = false; // on iOS, you need to add the db file to the Xcode project using a directory reference string mbTilesDir = "MBTiles/"; //string filename = "UnitySlippyMap_World_0_8.mbtiles"; string filename = "CountryMapWithUTfData.mbtiles"; string filepath = null; if (Application.platform == RuntimePlatform.IPhonePlayer) { filepath = Application.streamingAssetsPath + "/" + mbTilesDir + filename; } else if (Application.platform == RuntimePlatform.Android) { // Note: Android is a bit tricky, Unity produces APK files and those are never unzip on the device. // Place your MBTiles file in the StreamingAssets folder (http://docs.unity3d.com/Documentation/Manual/StreamingAssets.html). // Then you need to access the APK on the device with WWW and copy the file to persitentDataPath // to that it can be read by SqliteDatabase as an individual file string newfilepath = Application.temporaryCachePath + "/" + filename; if (File.Exists(newfilepath) == false) { Debug.Log("DEBUG: file doesn't exist: " + newfilepath); filepath = Application.streamingAssetsPath + "/" + mbTilesDir + filename; // TODO: read the file with WWW and write it to persitentDataPath WWW loader = new WWW(filepath); yield return(loader); if (loader.error != null) { Debug.LogError("ERROR: " + loader.error); error = true; } else { Debug.Log("DEBUG: will write: '" + filepath + "' to: '" + newfilepath + "'"); File.WriteAllBytes(newfilepath, loader.bytes); } } else { Debug.Log("DEBUG: exists: " + newfilepath); } filepath = newfilepath; } else { filepath = Application.streamingAssetsPath + "/" + mbTilesDir + filename; } /*if (error == false) * { * Debug.Log("DEBUG: using MBTiles file: " + filepath); * MBTilesLayerBehaviour mbTilesLayer = map.CreateLayer<MBTilesLayerBehaviour>("MBTiles"); * mbTilesLayer.Filepath = filepath; #if UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9 * mbTilesLayer.gameObject.SetActiveRecursively(false); #else * mbTilesLayer.gameObject.SetActive(false); #endif * * layers.Add(mbTilesLayer); * } * else * Debug.LogError("ERROR: MBTiles file not found!"); */ // create some test 2D markers GameObject go = TileBehaviour.CreateTileTemplate(TileBehaviour.AnchorPoint.BottomCenter).gameObject; go.GetComponent <Renderer>().material.mainTexture = MarkerTexture; go.GetComponent <Renderer>().material.renderQueue = 4001; go.transform.localScale = new Vector3(0.70588235294118f, 1.0f, 1.0f); go.transform.localScale /= 7.0f; go.AddComponent <CameraFacingBillboard>().Axis = Vector3.up; GameObject markerGO; markerGO = Instantiate(go) as GameObject; map.CreateMarker <MarkerBehaviour>("Maison du Savoir", new double[2] { 5.94919, 49.50424 }, markerGO); markerGO = Instantiate(go) as GameObject; map.CreateMarker <MarkerBehaviour>("Learning Center", new double[2] { 5.94744, 49.50223 }, markerGO); markerGO = Instantiate(go) as GameObject; map.CreateMarker <MarkerBehaviour>("Rock Haal", new double[2] { 5.94754, 49.50033 }, markerGO); markerGO = Instantiate(go) as GameObject; map.CreateMarker <MarkerBehaviour>("Haut Fourneau", new double[2] { 5.94820, 49.50125 }, markerGO); markerGO = Instantiate(go) as GameObject; map.CreateMarker <MarkerBehaviour>("Belval Plaza", new double[2] { 5.94551, 49.50091 }, markerGO); markerGO = Instantiate(go) as GameObject; map.CreateMarker <MarkerBehaviour>("Ruines", new double[2] { 5.94909, 49.50338 }, markerGO); DestroyImmediate(go); // create the location marker go = TileBehaviour.CreateTileTemplate().gameObject; go.GetComponent <Renderer>().material.mainTexture = LocationTexture; go.GetComponent <Renderer>().material.renderQueue = 4000; go.transform.localScale /= 27.0f; markerGO = Instantiate(go) as GameObject; map.SetLocationMarker <LocationMarkerBehaviour>(markerGO); DestroyImmediate(go); }
private IEnumerator Start() { // setup the gui scale according to the screen resolution guiXScale = (Screen.orientation == ScreenOrientation.Landscape ? Screen.width : Screen.height) / 480.0f; guiYScale = (Screen.orientation == ScreenOrientation.Landscape ? Screen.height : Screen.width) / 640.0f; // setup the gui area guiRect = new Rect(16.0f * guiXScale, 4.0f * guiXScale, Screen.width / guiXScale - 32.0f * guiXScale, 32.0f * guiYScale); // create the map singleton map = MapBehaviour.Instance; // GameObject.Find("Main Camera").GetComponent<Camera>() map.CurrentCamera = GameObject.Find("Main Camera").GetComponent <Camera>(); map.InputDelegate += UnitySlippyMap.Input.MapInput.BasicTouchAndKeyboard; map.CurrentZoom = 15.0f; // 9 rue Gentil, Lyon map.CenterWGS84 = new double[2] { -0.131411, 51.5221 }; // { 4.83527, 45.76487 }; map.UsesLocation = true; map.InputsEnabled = true; map.ShowsGUIControls = true; //map.GUIDelegate += Toolbar; layers = new List <LayerBehaviour>(); // create an OSM tile layer OSMTileLayer osmLayer = map.CreateLayer <OSMTileLayer>("OSM"); osmLayer.BaseURL = "http://a.tile.openstreetmap.org/"; layers.Add(osmLayer); // create a WMS tile layer WMSTileLayerBehaviour wmsLayer = map.CreateLayer <WMSTileLayerBehaviour>("WMS"); wmsLayer.BaseURL = "http://129.206.228.72/cached/osm?"; // http://www.osm-wms.de : seems to be of very limited use wmsLayer.Layers = "osm_auto:all"; #if UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9 wmsLayer.gameObject.SetActiveRecursively(false); #else wmsLayer.gameObject.SetActive(false); #endif layers.Add(wmsLayer); // create a VirtualEarth tile layer VirtualEarthTileLayerBehaviour virtualEarthLayer = map.CreateLayer <VirtualEarthTileLayerBehaviour>("VirtualEarth"); // Note: this is the key UnitySlippyMap, DO NOT use it for any other purpose than testing virtualEarthLayer.Key = "ArgkafZs0o_PGBuyg468RaapkeIQce996gkyCe8JN30MjY92zC_2hcgBU_rHVUwT"; #if UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9 virtualEarthLayer.gameObject.SetActiveRecursively(false); #else virtualEarthLayer.gameObject.SetActive(false); #endif layers.Add(virtualEarthLayer); // create an MBTiles tile layer bool error = false; // on iOS, you need to add the db file to the Xcode project using a directory reference string mbTilesDir = "MBTiles/"; //string filename = "UnitySlippyMap_World_0_8.mbtiles"; string filename = "CountryMapWithUTfData.mbtiles"; string filepath = null; if (Application.platform == RuntimePlatform.IPhonePlayer) { filepath = Application.streamingAssetsPath + "/" + mbTilesDir + filename; } else if (Application.platform == RuntimePlatform.Android) { // Note: Android is a bit tricky, Unity produces APK files and those are never unzip on the device. // Place your MBTiles file in the StreamingAssets folder (http://docs.unity3d.com/Documentation/Manual/StreamingAssets.html). // Then you need to access the APK on the device with WWW and copy the file to persitentDataPath // to that it can be read by SqliteDatabase as an individual file string newfilepath = Application.temporaryCachePath + "/" + filename; if (File.Exists(newfilepath) == false) { Debug.Log("DEBUG: file doesn't exist: " + newfilepath); filepath = Application.streamingAssetsPath + "/" + mbTilesDir + filename; // TODO: read the file with WWW and write it to persitentDataPath WWW loader = new WWW(filepath); yield return(loader); if (loader.error != null) { Debug.LogError("ERROR: " + loader.error); error = true; } else { Debug.Log("DEBUG: will write: '" + filepath + "' to: '" + newfilepath + "'"); File.WriteAllBytes(newfilepath, loader.bytes); } } else { Debug.Log("DEBUG: exists: " + newfilepath); } filepath = newfilepath; } else { filepath = Application.streamingAssetsPath + "/" + mbTilesDir + filename; } if (error == false) { Debug.Log("DEBUG: using MBTiles file: " + filepath); MBTilesLayerBehaviour mbTilesLayer = map.CreateLayer <MBTilesLayerBehaviour>("MBTiles"); mbTilesLayer.Filepath = filepath; #if UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9 mbTilesLayer.gameObject.SetActiveRecursively(false); #else mbTilesLayer.gameObject.SetActive(false); #endif layers.Add(mbTilesLayer); } else { Debug.LogError("ERROR: MBTiles file not found!"); } // create some test 2D markers GameObject go = TileBehaviour.CreateTileTemplate(TileBehaviour.AnchorPoint.BottomCenter).gameObject; go.GetComponent <Renderer>().material.mainTexture = MarkerTexture; go.GetComponent <Renderer>().material.renderQueue = 4001; go.transform.localScale = new Vector3(0.70588235294118f, 1.0f, 1.0f); go.transform.localScale /= 3.0f; go.AddComponent <CameraFacingBillboard>().Axis = Vector3.up; GameObject markerGO; //markerGO = Instantiate(go) as GameObject; //map.CreateMarker<MarkerBehaviour>("test marker - UCL", new double[2] { -0.131411, 51.5221 }, markerGO); //markerGO = Instantiate(go) as GameObject; //map.CreateMarker<MarkerBehaviour>("test marker - 31 rue de la Bourse, Lyon", new double[2] { 4.83699, 45.76535 }, markerGO); //markerGO = Instantiate(go) as GameObject; //map.CreateMarker<MarkerBehaviour>("test marker - 1 place St Nizier, Lyon", new double[2] { 4.83295, 45.76468 }, markerGO); userPosition = new GPSlocation(51.5221, -0.131411); //area = Area.Load(); area = GameObject.Find("ARCamera").GetComponent <DynamicDataSetLoader>().area; if (area != null && finished == false) { foreach (POI poi in area.POIs) { markerGO = Instantiate(go) as GameObject; map.CreateMarker <MarkerBehaviour>(poi.Name, new double[2] { poi.Longitude, poi.Latitude }, markerGO); markerGO.name = poi.Name; poi.SetMarkerObj(markerGO); } finished = true; } DestroyImmediate(go); // create the location marker go = TileBehaviour.CreateTileTemplate().gameObject; go.GetComponent <Renderer>().material.mainTexture = LocationTexture; go.GetComponent <Renderer>().material.renderQueue = 4000; go.transform.localScale /= 9.0f;//27 Debug.Log("after marker is generated"); markerGO = Instantiate(go) as GameObject; map.SetLocationMarker <LocationMarkerBehaviour>(markerGO); DestroyImmediate(go); }