public virtual TileUVCoordinate GetUV(string spriteName, long flameX, long fameY, int height = 0) { if (!ContainsKey(flameX, fameY)) { var rect = sprite.textureRect; Rect newRect = new Rect( rect.xMin + (flameX), rect.yMin + (fameY), 1, 1 ); var v1 = new Vector2(newRect.x / texture.width, newRect.y / texture.height); var v2 = new Vector2((newRect.x + newRect.width) / texture.width, newRect.y / texture.height); var v3 = new Vector2((newRect.x + newRect.width) / texture.width, (newRect.y + newRect.height) / texture.height); var v4 = new Vector2((newRect.x) / texture.width, (newRect.y + newRect.height) / texture.height); TileUVCoordinate uv = new TileUVCoordinate(); uv.uvP1 = v1; uv.uvP2 = v2; uv.uvP3 = v3; uv.uvP4 = v4; AddCacheValue(flameX, fameY, uv); return(uv); } else { return(GetCacheValue(flameX, fameY)); } }
public void LoadTiles(Texture2D texture) { uvEmpty = new TileUVCoordinate(); uvEmpty.uvP1 = Vector2.one; uvEmpty.uvP2 = Vector2.one; uvEmpty.uvP3 = Vector2.one; uvEmpty.uvP4 = Vector2.one; size = Settings.LIGHT_SIZE; this.texture = texture; //делаем спрайт sprite = Sprite.Create(texture, new Rect( 0, 0, size, size), new Vector2(0.5f, 0.5f), 1 ); sprite.name = "LightPalitra"; for (int i = 0; i < 10; i++) { var index1 = getIndex(i, i); cache[index1] = uvEmpty; } }
protected virtual void SetUV2(TileUVCoordinate uv, string spriteName, long flameX, long fameY, int height) { if (!spriteAtlasUV3.ContainsKey(spriteName)) { spriteAtlasUV3[spriteName] = new Dictionary <long, TileUVCoordinate>(); } spriteAtlasUV3[spriteName][GetUniqueKey(flameX, fameY, height)] = uv; }
void AddCacheValue(long flameX, long fameY, TileUVCoordinate val) { var index1 = getIndex(flameX, fameY); if (!cache.ContainsKey(index1)) { cache.Add(index1, val); return; } cache[index1] = val; }
public UvProvider() { uvEmpty = new TileUVCoordinate(); uvEmpty.uvP1 = Vector2.one; uvEmpty.uvP2 = Vector2.one; uvEmpty.uvP3 = Vector2.one; uvEmpty.uvP4 = Vector2.one; empty = uvEmpty; Sprite s = new Sprite(); //Sprite.Create() }
public virtual void LoadTiles(Sprite sprite, long shiftPaddingX = 1, long shiftPaddingY = 1, int countHeight = 1) { var rect = sprite.textureRect; float shiftX = 0; float shiftY = 0; for (int x = 0; x < GetFrameCountX(); x++) { for (int y = 0; y < GetFrameCountY(); y++) { for (int h = 0; h < countHeight; h++) { shiftX = GetTileSize() * x + GetPadding() * Mathf.FloorToInt((float)x / (float)shiftPaddingX); shiftY = GetTileSize() * y + GetPadding() * Mathf.FloorToInt((float)y / (float)shiftPaddingY); Rect newRect = new Rect( rect.xMin + shiftX, rect.yMax - GetTileSize() - shiftY + h, GetTileSize(), GetTileSize() ); var v1 = new Vector2(newRect.x / sprite.texture.width, newRect.y / sprite.texture.height); var v2 = new Vector2((newRect.x + newRect.width) / sprite.texture.width, newRect.y / sprite.texture.height); var v3 = new Vector2((newRect.x + newRect.width) / sprite.texture.width, (newRect.y + newRect.height) / sprite.texture.height); var v4 = new Vector2((newRect.x) / sprite.texture.width, (newRect.y + newRect.height) / sprite.texture.height); TileUVCoordinate uv = new TileUVCoordinate(); uv.uvP1 = v1; uv.uvP2 = v2; uv.uvP3 = v3; uv.uvP4 = v4; uv.rect = newRect; SetUV2(uv, sprite.name, x, y, h); } } } }