System.Collections.IEnumerator wwwDownload(string Description) { WWW www = new WWW("file://" + Path.Combine(Application.persistentDataPath, SceneTools.AreaNameDefault() + "//" + Description)); yield return(www); AudioClip clip = www.GetAudioClip(); //clip = www.GetAudioClip(false,false,AudioType.MPEG); clip = www.GetAudioClip(false, false, AudioType.MPEG); clip.name = Description; file.name = "url:" + Description; file.GetComponent <AudioSource>().clip = clip; Sound = file.GetComponent <AudioSource>(); //file = ob; }
void showNearestPOI() { GPSlocation userPosition = new GPSlocation(51.5221, -0.131411); if (UnityEngine.Input.location.status == LocationServiceStatus.Running) { double longitude = Input.location.lastData.longitude; double latitude = Input.location.lastData.latitude; userPosition = new GPSlocation(latitude, longitude); } if (area.POIs != null) { POI nearestPoi = area.GetNearestPOI(userPosition); // area.POIs[0]; string name = nearestPoi.Name; if (name.Contains(".")) { name = name.Split('.')[1]; } string s = "The nearest POI is " + name + "\n " + (int)(nearestPoi.GetDistance(userPosition)) + "m away."; DrawText(new Vector2(Screen.width * 0.2f, Screen.height * 0.6f), s); string p = Path.Combine(Application.persistentDataPath, SceneTools.AreaNameDefault() + "/" + "StreamingAssets" + "/" + nearestPoi.ImageTarget); if (NearestPOIpath != p) { Debug.Log("different"); if (System.IO.File.Exists(p)) { Texture2D texture = new Texture2D(512, 512); texture.LoadImage(System.IO.File.ReadAllBytes(p)); NearestPOITexture = texture; NearestPOIpath = p; //GameObject plane = GameObject.Find("NearPOI"); //plane.GetComponent<Renderer>().material.mainTexture = NearestPOITexture; } else { Debug.LogWarning("Texture " + p + " does not exist"); } } GUI.DrawTexture(new Rect((float)0.1 * Screen.width, (float)0.1 * Screen.width, (float)0.8 * Screen.width, (float)0.8 * Screen.width), NearestPOITexture, ScaleMode.ScaleToFit, true, 0); } }
void SetImageContent(Content example) { string p = Path.Combine(Application.persistentDataPath, SceneTools.AreaNameDefault() + "/" + example.Description); if (LastPath == p) { return; } if (System.IO.File.Exists(p)) { Texture2D texture = new Texture2D(512, 512); texture.LoadImage(System.IO.File.ReadAllBytes(p)); aTexture = texture; LastPath = p; //GameObject.Find("RawImage").transform.GetComponent<RawImage>().texture = texture; } else { Debug.LogWarning("Texture " + p + " does not exist"); } }
public void LinkTo(GameObject contentContainer) { GameObject content; Debug.LogWarning("contentContainer instantiate "); switch (Type) { case PoiDataType.texture2D: content = (GameObject)GameObject.CreatePrimitive(PrimitiveType.Plane); content.transform.parent = contentContainer.transform; content.name = content.transform.parent.name + "_tex2D"; content.transform.position = Position.getVector3(); content.transform.rotation = /*Rotation.getQuaternion() +*/ Quaternion.Euler(0f, 180f, 0f); //content.transform.localScale= Scale.getVector3(); content.transform.localScale = new Vector3(100, 100, 100); content.transform.parent.localScale = new Vector3(0.001f, 0.001f, 0.001f); string p = Path.Combine(Application.persistentDataPath, SceneTools.AreaNameDefault() + "/" + Description); Debug.Log(p); content.AddComponent <DragScript>(); if (System.IO.File.Exists(p)) { Texture2D texture = new Texture2D(512, 512); texture.LoadImage(System.IO.File.ReadAllBytes(p)); content.GetComponent <MeshCollider>().enabled = true; content.GetComponent <Renderer>().material.mainTexture = texture; } else { Debug.LogWarning("Texture " + p + " does not exist"); } Debug.Log("A picture from" + content.name); break; case PoiDataType.object3D: content = new GameObject(); content.transform.parent = contentContainer.transform; content.name = content.transform.parent.name + "_obj3D"; //content.layer = LayerMask.NameToLayer(SceneTools.ContentLayerMaskName()); //Model3D model3D = GameObject.Find("Object3DManager").GetComponent<Model3D>(); //GameObject[] models = model3D.Load(Path.Combine(Application.persistentDataPath, SceneTools.AreaNameDefault() + "/"+Description)); Debug.Log("A object3D from" + content.name); break; case PoiDataType.audio: if (Description.Contains("mp3")) { //Debug.Log("A audio called" + Description); GameObject prefeb_Container = (GameObject)Resources.Load("AudioContainer", typeof(GameObject)); content = GameObject.Instantiate <GameObject>(prefeb_Container, new Vector3(0, 0, 0), Quaternion.identity); content.transform.parent = contentContainer.transform; content.name = content.transform.parent.name + "_audio"; //content.layer = LayerMask.NameToLayer(SceneTools.ContentLayerMaskName()); Test t = (content.GetComponent("Test") as Test); t.sendAudioName(Description, content); content.transform.position = Position.getVector3(); Debug.Log("A audio from" + content.name); content.AddComponent <MeshCollider>(); content.AddComponent <DragScript>(); mediaGo = content; } break; case PoiDataType.text: GameObject TextContent = GameObject.Find("TextContent"); content = (GameObject)GameObject.Instantiate(TextContent); //augmentation.transform.parent = tb.gameObject.transform; content.transform.SetParent(contentContainer.transform); content.transform.localPosition = new Vector3(0f, 1f, 0f); Quaternion target = Quaternion.Euler(90f, 0, 0); content.transform.localRotation = target; // Quaternion.identity; content.name = content.transform.parent.name + "_text"; content.GetComponentInChildren <Text>().text = Description; content.GetComponent <Canvas>().enabled = true; content.transform.localScale = new Vector3(10f, 10f, 10f); content.transform.GetComponent <RectTransform>().sizeDelta = new Vector2(500, 900); GameObject textGo = content.transform.GetChild(0).gameObject; textGo.AddComponent <MeshCollider>(); textGo.AddComponent <DragScript>(); break; default: Debug.LogWarning("POI type not implemented"); break; } }
public static Area Load(string mod) //Area { string LastTime = ""; string LastTimeNew = ""; string Source = SceneTools.GetSettingValue("Source"); if (Source == "") { Source = "realdata"; SceneTools.ChangeSetting("realdata", "34", "false"); } SceneTools.CurrentSource = SceneTools.GetSettingValue("Source"); Debug.Log(Source); bool isExistDateFile = File.Exists(SceneTools.AreaZipLastTimeLocal()); if (mod.Equals("download"))//update or download { if (Source == "realdata") { Debug.LogWarning("Downloading readdata"); if (!File.Exists(SceneTools.AreaZipFileLocal()))//not exist zip { SceneTools.ClearLocalData(); SceneTools.DownloadFileFromUrlSync(SceneTools.AreaZipLastTimeUrl(), SceneTools.AreaZipLastTimeLocal()); SceneTools.DownloadFileFromUrlSync(SceneTools.AreaZipFileUrl(), SceneTools.AreaZipFileLocal()); new ZipIt(SceneTools.AreaZipFileLocal(), "", Application.persistentDataPath); } //} else //the have zip,then check the update { if (isExistDateFile) { LastTime = File.ReadAllText(SceneTools.AreaZipLastTimeLocal()); SceneTools.DownloadFileFromUrlSync(SceneTools.AreaZipLastTimeUrl(), SceneTools.AreaZipLastTimeLocal()); LastTimeNew = File.ReadAllText(SceneTools.AreaZipLastTimeLocal()); if (Convert.ToInt64(LastTimeNew) > Convert.ToInt64(LastTime)) { //update Debug.Log("Downloading new zip file"); SceneTools.DownloadFileFromUrlSync(SceneTools.AreaZipFileUrl(), SceneTools.AreaZipFileLocal()); new ZipIt(SceneTools.AreaZipFileLocal(), "", Application.persistentDataPath); } else { //not gonna update Debug.Log("Zip file is latest version"); } } else //unknown version ,so update ,or last version is test { SceneTools.ClearLocalData(); Debug.Log("Zip not File.Exists (SceneTools.AreaZipLastTimeLocal())"); SceneTools.DownloadFileFromUrlSync(SceneTools.AreaZipLastTimeUrl(), SceneTools.AreaZipLastTimeLocal()); SceneTools.DownloadFileFromUrlSync(SceneTools.AreaZipFileUrl(), SceneTools.AreaZipFileLocal());//AreaZipFileUrl() new ZipIt(SceneTools.AreaZipFileLocal(), "", Application.persistentDataPath); } } } else if (Source == "Test") { if (isExistDateFile) { //realdata SceneTools.ClearLocalData(); //delete realdata SceneTools.DownloadFileFromUrlSync(SceneTools.testZip, SceneTools.AreaZipFileLocal()); new ZipIt(SceneTools.AreaZipFileLocal(), "", Application.persistentDataPath); } else if (!File.Exists(SceneTools.AreaZipFileLocal())) { SceneTools.ClearLocalData();//delete realdata SceneTools.DownloadFileFromUrlSync(SceneTools.testZip, SceneTools.AreaZipFileLocal()); new ZipIt(SceneTools.AreaZipFileLocal(), "", Application.persistentDataPath); } } //{ } SceneTools.ChangeSetting(SceneTools.CurrentSource, "34", "false"); //convert the xml into a cs object (after downloading all the file or file is already) var serializer = new XmlSerializer(typeof(Area)); using (var stream = new FileStream(Path.Combine(Application.persistentDataPath + "/" + SceneTools.AreaNameDefault(), SceneTools.AreaNameDefault() + ".xml"), FileMode.Open)) { return(serializer.Deserialize(stream) as Area); } }