public static void LoadSpriteOnURL(string url, Action <Sprite> callback, Action <string> error) { if (string.IsNullOrEmpty(url)) { callback?.Invoke(null); return; } ObservableWWW.GetWWW(url) // .Retry(3) // .SubscribeOnMainThread() .DoOnError(onError => { error?.Invoke(onError.ToString()); }) .Subscribe( www => { // Debug.LogError("LoadImgOnURL:" + www.texture.name); var tex = www.texture; if (tex == null) { return; } var ret = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero); ret.name = tex.name; callback?.Invoke(ret); }, onError => Debug.LogError("取得失敗") ); }
public override void Create(Tile tile) { base.Create(tile); var go = GameObject.CreatePrimitive(PrimitiveType.Quad).transform; go.name = "map"; go.SetParent(tile.transform, true); go.localScale = new Vector3((float)tile.Rect.Width, (float)tile.Rect.Width, 1); go.rotation = Quaternion.AngleAxis(90, new Vector3(1, 0, 0)); go.localPosition = Vector3.zero; go.localPosition -= new Vector3(0, 1, 0); var rend = go.GetComponent <Renderer>(); rend.material = tile.Material; var url = MapImageUrlBase + tile.Zoom + "/" + tile.TileTms.x + "/" + tile.TileTms.y + ".png"; ObservableWWW.GetWWW(url).Subscribe( success => { rend.material.mainTexture = new Texture2D(512, 512, TextureFormat.DXT5, false); rend.material.color = new Color(1f, 1f, 1f, 1f); success.LoadImageIntoTexture((Texture2D)rend.material.mainTexture); }, error => { Debug.Log(error); }); }
public static IObservable <WWW> getAnswers(string token, string questId) { return(ObservableWWW.GetWWW(URL + "/quests/" + questId + "/answers", new Hash() { { "X-Auth-Token", token } })); }
//------------------------ //Taverns //------------------------ public static IObservable <WWW> getTaverns(string token, double lat, double lon) { return(ObservableWWW.GetWWW(URL + "/nearest_entities?latitude=" + lat + "&longitude=" + lon, new Hash() { { "X-Auth-Token", token } })); }
public static IObservable <WWW> requestSkills(string token) { return(ObservableWWW.GetWWW(URL + "/skills/generate_test", new Hash() { { "X-Auth-Token", token } })); }
public void AddGeojsonLayer(Layer l) { if (l._active) { return; } var av = Config.ActiveView; ObservableWWW.GetWWW(l.Url).Subscribe( success => { var layerObject = new GameObject(l.Title); layerObject.transform.SetParent(Layers.transform, false); l._object = layerObject; l._active = true; var symbolFactory = layerObject.AddComponent <SymbolFactory>(); symbolFactory.InitLayer(l, success.text, av.Zoom, av.Lat, av.Lon, av.TileSize, av.Range); }, error => { Debug.Log(error); } ); }
/// <summary> /// GETリクエストを送信する。 /// </summary> /// <param name="url">URL。</param> /// <returns>レスポンス文字列。</returns> public virtual IObservable <string> Get(string url) { return(this.LogFilter( this.ResponseFilter( ObservableWWW.GetWWW(url, this.MakeDefaultHeaders())), "GET", url)); }
private static void Request(string serviceUrl, Dictionary <string, string> postFields, Action <string> callback) { IObservable <WWW> wWW; Dictionary <string, string> strs; WWWForm wWWForm = null; if (postFields != null) { wWWForm = new WWWForm(); foreach (KeyValuePair <string, string> postField in postFields) { if (postField.Key == null) { throw new NullReferenceException(string.Format("Post field key is null. URL: {0}\nFields:\n{1}", serviceUrl, WebService.GetFieldsString(postFields))); } if (postField.Value == null) { throw new NullReferenceException(string.Format("Post field value for key '{0}' is null. URL: {1}\nFields:\n{2}", postField.Key, serviceUrl, WebService.GetFieldsString(postFields))); } wWWForm.AddField(postField.Key, postField.Value); } } string str = Uri.EscapeUriString(serviceUrl); if (wWWForm == null) { strs = new Dictionary <string, string>() { { "ACCEPT-ENCODING", "gzip" } }; wWW = ObservableWWW.GetWWW(str, strs, null); } else { strs = new Dictionary <string, string>() { { "ACCEPT-ENCODING", "gzip" } }; wWW = ObservableWWW.PostWWW(str, wWWForm, strs, null); } wWW.Retry <WWW>(5).CatchIgnore <WWW, WWWErrorException>((WWWErrorException ex) => { AppLog.LogError(string.Format("WWW error: {0}", ex.RawErrorMessage), true); callback(null); }).Select <WWW, string>((WWW www) => { string empty = string.Empty; www.responseHeaders.TryGetValue("CONTENT-ENCODING", out empty); if (empty != "gzip") { return(www.text); } return(WebService.Ungzip(www.bytes)); }).Subscribe <string>(callback, (Exception e) => { AppLog.LogException(e, true); callback(null); }); }
private void SetUserImage() { if (userRecord.userType == User.LoginType.Facebook) { var pictureURL = string.Format("http://graph.facebook.com/{0}/picture?type=square", userRecord.userID); ObservableWWW.GetWWW(pictureURL).Subscribe(www => { photo.overrideSprite = Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), new Vector2(0.5f, 0.5f)); }); } }
private void Start() { var url = "https://unity3d.com/jp"; //結果(www.text)のみを受け取る場合 ObservableWWW.Get(url) .Subscribe(x => Debug.Log(x)); //通信終了時にwwwごと受け取る場合 ObservableWWW.GetWWW(url) .Subscribe(www => Debug.Log(www.text)); }
public string LoadPuzzleFromUrl(string url) { string guid = null; ObservableWWW.GetWWW(url) .Select(www => www.text) .Subscribe(data => { guid = loadPuzzleFromData(data); }); return(guid); }
public override void Start() { base.Start(); _button.OnClickAsObservable() .First() .SelectMany(ObservableWWW.GetWWW(resourceURL).Timeout(TimeSpan.FromSeconds(3))) .Select(www => Sprite.Create(www.texture, new Rect(0, 0, 400, 400), Vector2.zero)) .Subscribe(sprite => { _image.sprite = sprite; }, ex => _errorText.text = ex.ToString()); }
void WWW() { ObservableWWW.GetWWW("http://img.taopic.com/uploads/allimg/120428/128240-12042Q4020849.jpg") .Subscribe(down => { Texture2D temp2d = down.texture; Debug.Log(temp2d.name); Sprite tempSp = Sprite.Create(temp2d, new Rect(0, 0, temp2d.width, temp2d.height), Vector2.zero); UIMgr.GetPanel <UITestUniRx>().GetComponent <Image>().sprite = tempSp; } , x => Debug.Log("请求错误")) .AddTo(disposables); }
public virtual WWW Load(string path) { var result = ObservableWWW.GetWWW("file://" + path); WWW data = null; result.Subscribe(www => { data = www; Debug.Log("file load Response: "); }, Debug.LogException ); return(data); }
//------------------------ //QUESTS //------------------------ public static IObservable <WWW> getQuests(string token, string type) { string str; if (type == null) { str = "/quests"; } else { str = "/quests/me/" + type; } return(ObservableWWW.GetWWW(URL + str + "?size=20", new Hash() { { "X-Auth-Token", token } })); }
public override void Create(Tile tile) { base.Create(tile); var url = "https://tile.mapzen.com/mapzen/terrain/v1/terrarium/" + tile.Zoom + "/" + tile.TileTms.x + "/" + tile.TileTms.y + ".png?api_key=" + _key; ObservableWWW.GetWWW(url).Subscribe( success => { CreateMesh(tile, success); }, error => { Debug.Log(url + " - " + error); }); }
public static TilePromise GetTile(Vector3d tileZoom, Action <Texture2D> callback) { if (tileCache == null) { tileCache = new Dictionary <Vector3d, TilePromise>(); } var url = TileServiceUrls[(int)TileService] + tileZoom.z + "/" + tileZoom.x + "/" + tileZoom.y + ".png"; if (tileCache.ContainsKey(tileZoom)) { callback(tileCache[tileZoom].Texture); return(tileCache[tileZoom]); } else { TilePromise tp = new TilePromise(); tp.TileZoom = tileZoom; tileCache.Add(tileZoom, tp); ObservableWWW.GetWWW(url).Subscribe( success => { var texture = new Texture2D(512, 512, TextureFormat.DXT5, false); success.LoadImageIntoTexture(texture); tp.Texture = texture; callback(texture); }, error => { // TODO error texture Debug.Log(error); callback(null); }); return(tp); } /*if (Application.isPlaying) * {*/ //} }
public void DownloadTexture(Action <Texture2D> handler) { if (Image == null) { UnityEngine.Debug.Log("CreateTextureFromImage(): Image == null"); return; } ObservableWWW.GetWWW(Image.Url.AbsoluteUri) .CatchIgnore(new Action <Exception>(UnityEngine.Debug.LogException)) .Subscribe(www => { if (handler != null) { Texture = www.texture; handler(Texture); } }); }
private void ConstructAsync(string text) { string url; var heavyMethod = Observable.Start(() => new JSONObject(text)); heavyMethod.ObserveOnMainThread().Subscribe(mapData => { if (!this) // checks if tile still exists and haven't destroyed yet { return; } var go = GameObject.CreatePrimitive(PrimitiveType.Quad).transform; go.name = "map"; go.SetParent(transform, true); go.localScale = new Vector3((float)Rect.Width, (float)Rect.Width, 1); go.rotation = Quaternion.AngleAxis(90, new Vector3(1, 0, 0)); go.localPosition = Vector3.zero; go.localPosition -= new Vector3(0, 1, 0); var rend = go.GetComponent <Renderer>(); rend.material = _settings.Material; if (_settings.LoadImages) { url = MapImageUrlBase + _settings.Zoom + "/" + _settings.TileTms.x + "/" + _settings.TileTms.y + ".png"; ObservableWWW.GetWWW(url).Subscribe( success => { rend.material.mainTexture = new Texture2D(512, 512, TextureFormat.DXT5, false); rend.material.color = new Color(1f, 1f, 1f, 1f); success.LoadImageIntoTexture((Texture2D)rend.material.mainTexture); }, error => { Debug.Log(error); }); } RunFactories(mapData); }); }
public override void Create(Tile tile) { base.Create(tile); foreach (var tileLayer in tileLayers) { //AppState.Instance.Speech.Keywords.Add("Enable " + tileLayer.VoiceCommand, () => // { // if (tileLayer.Group()) // }); var go = GameObject.CreatePrimitive(PrimitiveType.Quad).transform; go.name = "tilelayer-" + tileLayer.Title; go.SetParent(tile.transform, false); go.localScale = new Vector3((float)tile.Rect.Width, (float)tile.Rect.Width, 1); go.rotation = Quaternion.AngleAxis(90, new Vector3(1, 0, 0)); //go.localPosition = Vector3.zero; go.localPosition += new Vector3(0, tileLayer.Height, 0); var rend = go.GetComponent <Renderer>(); rend.material = tile.Material; // var url = string.Format("{0}/{1}/{2}/{3}.png", tileLayer.Url, tile.Zoom, tile.TileTms.x, tile.TileTms.y); var url = tileLayer.Url.Replace("{z}", tile.Zoom.ToString()).Replace("{x}", tile.TileTms.x.ToString()).Replace("{y}", tile.TileTms.y.ToString()); Debug.Log(url); ObservableWWW.GetWWW(url).Subscribe( success => { if (rend) { rend.material.mainTexture = new Texture2D(512, 512, TextureFormat.DXT5, false); success.LoadImageIntoTexture((Texture2D)rend.material.mainTexture); } }, error => { Debug.Log(error); } ); } }
private void ConstructAsync(string text) { string url; var heavyMethod = Observable.Start(() => new JSONObject(text)); heavyMethod.ObserveOnMainThread().Subscribe(mapData => { if (!this) // checks if tile still exists and haven't destroyed yet { return; } var go = GameObject.CreatePrimitive(PrimitiveType.Quad).transform; go.name = "map"; go.SetParent(transform, true); go.localScale = new Vector3(Rect.width, Rect.width, 1); go.rotation = Quaternion.AngleAxis(90, new Vector3(1, 0, 0)); go.localPosition = Vector3.zero; go.localPosition -= new Vector3(0, 1, 0); var rend = go.GetComponent <Renderer>(); rend.material = Resources.Load <Material>("Ground"); rend.material.mainTexture = new Texture2D(512, 512, TextureFormat.DXT5, false); rend.material.color = new Color(.1f, .1f, .1f, 1f); if (_settings.LoadImages) { rend.material.color = new Color(1f, 1f, 1f, 1f); url = MapImageUrlBase + _settings.Zoom + "/" + _settings.TileTms.x + "/" + _settings.TileTms.y + ".png"; ObservableWWW.GetWWW(url).Subscribe(x => { x.LoadImageIntoTexture((Texture2D)rend.material.mainTexture); }); } StartCoroutine(CreateBuildings(mapData["buildings"], _settings.TileCenter)); StartCoroutine(CreateRoads(mapData["roads"], _settings.TileCenter)); StartCoroutine(CreateWater(mapData["water"], _settings.TileCenter)); }); }
void Start() { ScheduledNotifier <float> progress0 = new ScheduledNotifier <float>(); ScheduledNotifier <float> progress1 = new ScheduledNotifier <float>(); ScheduledNotifier <float> progress2 = new ScheduledNotifier <float>(); progress0.Subscribe(prog => slider[0].value = prog); progress1.Subscribe(prog => slider[1].value = prog); progress2.Subscribe(prog => slider[2].value = prog); button.OnClickAsObservable() .First() .SelectMany(ObservableWWW.GetWWW("http://t1.daumcdn.net/liveboard/newsade/e91ec5e3f766486191dee5010e8c27cd.jpg", null, progress0)) .Select(www => Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), Vector2.zero)) .Subscribe(sprite => { image[0].sprite = sprite; button.interactable = false; }, Debug.LogError); button.OnClickAsObservable() .First() .SelectMany(ObservableWWW.GetWWW("https://pbs.twimg.com/media/DDUkR_4UwAAiVyf.jpg", null, progress1)) .Select(www => Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), Vector2.zero)) .Subscribe(sprite => { image[1].sprite = sprite; button.interactable = false; }, Debug.LogError); button.OnClickAsObservable() .First() .SelectMany(ObservableWWW.GetWWW("http://cfile4.uf.tistory.com/image/2566C73F5951EE972AA220", null, progress2)) .Select(www => Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), Vector2.zero)) .Subscribe(sprite => { image[2].sprite = sprite; button.interactable = false; }, Debug.LogError); }
void Awake() { var fileItemList = new List <GameObject>(); var model = MusicSelectorModel.Instance; directoryPathInputField.OnValueChangeAsObservable() .Subscribe(path => model.DirectoryPath.Value = path); model.DirectoryPath.DistinctUntilChanged() .Subscribe(path => directoryPathInputField.text = path); model.DirectoryPath.Value = Application.persistentDataPath + "/Musics/"; if (!Directory.Exists(model.DirectoryPath.Value)) { Directory.CreateDirectory(model.DirectoryPath.Value); } Observable.Timer(TimeSpan.FromMilliseconds(300), TimeSpan.Zero) .Where(_ => Directory.Exists(model.DirectoryPath.Value)) .Select(_ => new DirectoryInfo(model.DirectoryPath.Value).GetFiles()) .Select(fileInfo => fileInfo.Select(file => file.FullName).ToList()) .Where(x => !x.SequenceEqual(model.FilePathList.Value)) .Subscribe(filePathList => model.FilePathList.Value = filePathList); model.FilePathList.AsObservable() .Select(filePathList => filePathList.Select(path => Path.GetFileName(path))) .Do(_ => fileItemList.ForEach(DestroyObject)) .Do(_ => fileItemList.Clear()) .SelectMany(fileNameList => fileNameList) .Select(fileName => new { fileName, obj = Instantiate(fileItem) as GameObject }) .Do(elm => fileItemList.Add(elm.obj)) .Do(elm => elm.obj.transform.SetParent(fileItemContainer.transform)) .Subscribe(elm => elm.obj.GetComponent <FileItem>().SetName(elm.fileName)); LoadButton.OnClickAsObservable() .Select(_ => model.SelectedFileName.Value) .Where(fileName => !string.IsNullOrEmpty(fileName)) .Subscribe(fileName => { ObservableWWW.GetWWW("file:///" + Application.persistentDataPath + "/Musics/" + fileName).Subscribe(www => { if (www.audioClip == null) { // selectedFileNameText.text = fileName + " は音楽ファイルじゃない件!!!!!!!!!!!!!"; return; } var editorModel = NotesEditorModel.Instance; editorModel.ClearNotesData(); // Apply music data editorModel.Audio.clip = www.audioClip; editorModel.MusicName.Value = fileName; editorModel.OnLoadedMusicObservable.OnNext(0); LoadNotesData(); }); }); // model.SelectedFileName.SubscribeToText(selectedFileNameText); }
public virtual IObservable <WWW> Load(string path) { return(ObservableWWW.GetWWW(@"file:///" + path)); }
public void InitMap() { var iv = Config.InitalView; var i = iv.Range; if (i > mapScales.Length) { i = mapScales.Length; } var mapScale = mapScales[i - 1]; Map.transform.localScale = new Vector3(mapScale, mapScale, mapScale); World = new GameObject("World"); World.transform.SetParent(Map.transform, false); // init map var tm = World.AddComponent <CachedTileManager>(); tm.Latitude = iv.Lat; tm.Longitude = iv.Lon; tm.Range = iv.Range; tm.Zoom = iv.Zoom; tm.TileSize = iv.TileSize; tm._key = "vector-tiles-dB21RAF"; TileManager = tm; #region UI var ui = new GameObject("UI"); // Placeholder (root element in UI tree) ui.transform.SetParent(World.transform, false); var place = new GameObject("PlaceContainer"); AddRectTransformToGameObject(place); place.transform.SetParent(ui.transform, false); var poi = new GameObject("PoiContainer"); AddRectTransformToGameObject(poi); poi.transform.SetParent(ui.transform, false); #endregion #region FACTORIES #region defaultfactories var factories = new GameObject("Factories"); factories.transform.SetParent(World.transform, false); var buildings = new GameObject("BuildingFactory"); buildings.transform.SetParent(factories.transform, false); var buildingFactory = buildings.AddComponent <BuildingFactory>(); //var flatBuildings = new GameObject("FlatBuildingFactory"); //flatBuildings.transform.SetParent(factories.transform, false); //var flatBuildingFactory = flatBuildings.AddComponent<FlatBuildingFactory>(); var roads = new GameObject("RoadFactory"); roads.transform.SetParent(factories.transform, false); var roadFactory = roads.AddComponent <RoadFactory>(); //var water = new GameObject("WaterFactory"); //water.transform.SetParent(factories.transform, false); //var waterFactory = water.AddComponent<WaterFactory>(); //var boundary = new GameObject("BoundaryFactory"); //boundary.transform.SetParent(factories.transform, false); //var boundaryFactory = boundary.AddComponent<BoundaryFactory>(); var landuse = new GameObject("LanduseFactory"); landuse.transform.SetParent(factories.transform, false); var landuseFactory = landuse.AddComponent <LanduseFactory>(); var places = new GameObject("PlacesFactory"); places.transform.SetParent(factories.transform, false); var placesFactory = places.AddComponent <PlacesFactory>(); var pois = new GameObject("PoiFactory"); pois.transform.SetParent(factories.transform, false); var poisFactory = pois.AddComponent <PoiFactory>(); #endregion SymbolMap = new GameObject("Layers"); SymbolMap.transform.SetParent(Table.transform); SymbolMap.transform.localPosition = new Vector3(0f, 0.5f, 0f); SymbolMap.transform.localScale = new Vector3(mapScale, mapScale, mapScale); var Symbolworld = new GameObject("Symbols"); Symbolworld.transform.SetParent(SymbolMap.transform, false); Config.Layers.ForEach(l => { if (l.Type == "geojson" && l.Enabled) { ObservableWWW.GetWWW(l.Url).Subscribe( success => { var symbolFactory = Symbolworld.AddComponent <SymbolFactory>(); symbolFactory.baseUrl = "http://gamelab.tno.nl/Missieprep/"; symbolFactory.geojson = "{ \"type\": \"FeatureCollection\", \"features\": [ { \"type\": \"Feature\", \"properties\": { \"IconUrl\": \"http://134.221.20.241:3000/images/pomp.png\", \"stats\":[{ \"name\":\"ammo\", \"type\":\"bar\", \"value\":\"10\", \"maxValue\":\"100\" },{ \"name\":\"ammo\", \"type\":\"bar\", \"value\":\"10\", \"maxValue\":\"100\" },{ \"name\":\"ammo\", \"type\":\"bar\", \"value\":\"10\", \"maxValue\":\"100\" },{ \"name\":\"ammo\", \"type\":\"bar\", \"value\":\"10\", \"maxValue\":\"100\" },{ \"name\":\"ammo\", \"type\":\"bar\", \"value\":\"10\", \"maxValue\":\"100\" }], \"Lan\":\"5.0466084480285645\", \"Lon\":\"52.45997114230474\" }, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ 5.0466084480285645, 52.45997114230474 ] } }, { \"type\": \"Feature\", \"properties\": {\"IconUrl\": \"http://134.221.20.241:3000/images/ambulanceposten.png\"}, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ 5.048539638519287, 52.45887287117959 ] } }, { \"type\": \"Feature\", \"properties\": {\"IconUrl\": \"http://134.221.20.241:3000/images/politie.png\"}, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ 5.046522617340088, 52.45781379807768 ] } }, { \"type\": \"Feature\", \"properties\": {\"IconUrl\": \"http://134.221.20.241:3000/images/politie.png\"}, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ 5.0501275062561035, 52.461265498103494 ] } } ] }"; // success.text; symbolFactory.zoom = iv.Zoom; symbolFactory.Latitude = iv.Lat; symbolFactory.Longitude = iv.Lon; symbolFactory.TileSize = iv.TileSize; symbolFactory.Layer = l; symbolFactory.Range = iv.Range; symbolFactory.AddSymbols(); }, error => { Debug.Log(error); } ); } }); #endregion #region TILE PLUGINS var tilePlugins = new GameObject("TilePlugins"); tilePlugins.transform.SetParent(World.transform, false); var mapImage = new GameObject("MapImage"); mapImage.transform.SetParent(tilePlugins.transform, false); var mapImagePlugin = mapImage.AddComponent <MapImagePlugin>(); mapImagePlugin.TileService = MapImagePlugin.TileServices.Default; var tileLayer = new GameObject("TileLayer"); tileLayer.transform.SetParent(tilePlugins.transform, false); var tileLayerPlugin = tileLayer.AddComponent <TileLayerPlugin>(); tileLayerPlugin.tileLayers = Config.Layers; #endregion }
public static IObservable <WWW> requestPassword(string email) { return(ObservableWWW.GetWWW(URL + "/reset_password?email=" + email)); }
public static IObservable <WWW> requestCode(Credentials creds) { return(ObservableWWW.GetWWW(URL + "/send_verification_code?email=" + creds.GetEmail())); }
private static UniRx.IObservable <long> CreateTimeObservable() { return(from www in ObservableWWW.GetWWW("https://fp-cloudsync.herokuapp.com/time?t=" + DateTime.UtcNow.Ticks).Timeout(TimeSpan.FromSeconds(5.0)) select Convert.ToInt64(www.text)); }
public IObservable <WWW[]> LoadFile(string url) { return(Observable.WhenAll(ObservableWWW.GetWWW(url))); }
private void CreateMesh(Tile tile, WWW terrarium) { var url = TileServiceUrls[(int)TileService] + tile.Zoom + "/" + tile.TileTms.x + "/" + tile.TileTms.y + ".png"; const int sampleCount = 3; var tex = new Texture2D(256, 256); terrarium.LoadImageIntoTexture(tex); ObservableWWW.GetWWW(url).Subscribe( success => { var go = new GameObject("TerrainHeight"); var mesh = go.AddComponent <MeshFilter>().mesh; var rend = go.AddComponent <MeshRenderer>(); var verts = new List <Vector3>(); // When sampleCount == 3, compute 9 points: the four corners, the center, and the four midpoints along the side // vertices are (all at the appropriate y = height): // 0) minX, minY // 1) minX, halfY // 2) minX, maxY // 3) halfX, minY // 4) halfX, halfY // 5) halfX, maxY // 6) maxX, minY // 7) maxX, halfY // 8) maxX, maxY for (float x = 0; x < sampleCount; x++) { for (float y = 0; y < sampleCount; y++) { // Lerp: Linearly interpolates between left and right corner. var xx = Mathf.Lerp((float)tile.Rect.Min.x, (float)(tile.Rect.Min.x + tile.Rect.Size.x), x / (sampleCount - 1)); var yy = Mathf.Lerp((float)tile.Rect.Min.y, (float)(tile.Rect.Min.y + tile.Rect.Size.y), y / (sampleCount - 1)); // Clamp: Clamps value between min and max and returns value. var px = (int)Mathf.Clamp((x / (sampleCount - 1) * 256), 0, 255); // 0, 128, 255 var py = (int)Mathf.Clamp((256 - (y / (sampleCount - 1) * 256)), 0, 255); // 255, 128, 0 // Compute relative vector with respect to the origin verts.Add(new Vector3( (float)(xx - tile.Rect.Center.x), GetTerrariumHeight(tex.GetPixel(px, py)), (float)(yy - tile.Rect.Center.y))); } } mesh.SetVertices(verts); // Create a mesh mesh.triangles = new int[] { 0, 3, 4, 0, 4, 1, 1, 4, 5, 1, 5, 2, 3, 6, 7, 3, 7, 4, 4, 7, 8, 4, 8, 5 }; mesh.SetUVs(0, new List <Vector2>() { new Vector2(0, 1), new Vector2(0, 0.5f), new Vector2(0, 0), new Vector2(0.5f, 1), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0), new Vector2(1, 1), new Vector2(1, 0.5f), new Vector2(1, 0), }); mesh.RecalculateNormals(); go.transform.SetParent(tile.transform, false); rend.material.mainTexture = new Texture2D(512, 512, TextureFormat.DXT5, false); rend.material.color = new Color(1f, 1f, 1f, 1f); success.LoadImageIntoTexture((Texture2D)rend.material.mainTexture); }, error => { Debug.Log(error); }); }