public void Initialize() { if (!((UnityEngine.Object)maskAtlas == (UnityEngine.Object)null) && maskAtlas.items != null) { biomeMasks = new Dictionary <string, BiomeMaskData>(); TextureAtlas.Item[] items = maskAtlas.items; for (int i = 0; i < items.Length; i++) { TextureAtlas.Item item = items[i]; string name = item.name; int num = name.IndexOf('/'); string text = name.Substring(0, num); string value = name.Substring(num + 1, 4); text = text.ToLower(); for (int num2 = text.IndexOf('_'); num2 != -1; num2 = text.IndexOf('_')) { text = text.Remove(num2, 1); } BiomeMaskData value2 = null; if (!biomeMasks.TryGetValue(text, out value2)) { value2 = new BiomeMaskData(text); biomeMasks[text] = value2; } int num3 = Convert.ToInt32(value, 2); Tile tile = value2.tiles[num3]; if (tile.variationUVs == null) { tile.isSource = true; tile.variationUVs = new UVData[1]; } else { UVData[] array = new UVData[tile.variationUVs.Length + 1]; Array.Copy(tile.variationUVs, array, tile.variationUVs.Length); tile.variationUVs = array; } Vector4 vector = new Vector4(item.uvBox.x, item.uvBox.w, item.uvBox.z, item.uvBox.y); Vector2 bl = new Vector2(vector.x, vector.y); Vector2 br = new Vector2(vector.z, vector.y); Vector2 tl = new Vector2(vector.x, vector.w); Vector2 tr = new Vector2(vector.z, vector.w); UVData uVData = new UVData(bl, br, tl, tr); tile.variationUVs[tile.variationUVs.Length - 1] = uVData; value2.tiles[num3] = tile; } foreach (KeyValuePair <string, BiomeMaskData> biomeMask in biomeMasks) { biomeMask.Value.GenerateRotations(); biomeMask.Value.Validate(); } } }
public TextureAtlas makeTextureAtlas(TextAsset jsonData, Texture2D texture) { TextureAtlas atlas = TextureAtlas.CreateInstance <TextureAtlas>(); atlas.texture = texture; JObject parsed = JObject.Parse(jsonData.text); List <TextureAtlas.Item> items = new List <TextureAtlas.Item>(); foreach (JObject jItem in parsed["Base"]["items"]["Array"]) { TextureAtlas.Item item = new TextureAtlas.Item(); item.name = jItem["data"]["name"].Value <string>(); item.name = item.name.Substring(1, item.name.Length - 2); item.uvBox = new Vector4(jItem["data"]["uvBox"]["x"].Value <float>(), jItem["data"]["uvBox"]["y"].Value <float>(), jItem["data"]["uvBox"]["z"].Value <float>(), jItem["data"]["uvBox"]["w"].Value <float>()); List <int> indices = new List <int>(); foreach (JObject indexItem in jItem["data"]["indices"]["Array"]) { indices.Add(indexItem["data"].Value <int>()); } item.indices = indices.ToArray(); List <Vector2> uvs = new List <Vector2>(); foreach (JObject uvItem in jItem["data"]["uvs"]["Array"]) { uvs.Add(new Vector2(uvItem["data"]["x"].Value <float>(), uvItem["data"]["y"].Value <float>())); } item.uvs = uvs.ToArray(); List <Vector3> vertices = new List <Vector3>(); foreach (JObject vertexItem in jItem["data"]["vertices"]["Array"]) { vertices.Add(new Vector3(vertexItem["data"]["x"].Value <float>(), vertexItem["data"]["y"].Value <float>())); } item.vertices = vertices.ToArray(); items.Add(item); } atlas.items = items.ToArray(); return(atlas); }
public void PostProcess() { if (decor != null && (UnityEngine.Object)atlas != (UnityEngine.Object)null && atlas.items != null) { for (int i = 0; i < decor.Length; i++) { if (decor[i].variants != null && decor[i].variants.Length != 0) { for (int j = 0; j < decor[i].variants.Length; j++) { bool flag = false; TextureAtlas.Item[] items = atlas.items; for (int k = 0; k < items.Length; k++) { TextureAtlas.Item atlasItem = items[k]; string text = atlasItem.name; int num = text.IndexOf("/"); if (num != -1) { text = text.Substring(num + 1); } if (decor[i].variants[j].name == text) { decor[i].variants[j].atlasItem = atlasItem; flag = true; break; } } if (!flag) { DebugUtil.LogErrorArgs(base.name, "/", decor[i].name, "could not find ", decor[i].variants[j].name, "in", atlas.name); } } } } } }
public RenderInfo(BlockTileRenderer renderer, int queryLayer, int renderLayer, BuildingDef def, SimHashes element) { this.queryLayer = queryLayer; this.renderLayer = renderLayer; rootPosition = new Vector3(0f, 0f, Grid.GetLayerZ(def.SceneLayer)); this.element = element; material = new Material(def.BlockTileMaterial); if (def.BlockTileIsTransparent) { material.renderQueue = RenderQueues.Liquid; decorZOffset = Grid.GetLayerZ(Grid.SceneLayer.TileFront) - Grid.GetLayerZ(Grid.SceneLayer.Liquid) - 1f; } else if (def.SceneLayer == Grid.SceneLayer.TileMain) { material.renderQueue = RenderQueues.BlockTiles; } material.DisableKeyword("ENABLE_SHINE"); if (element != SimHashes.Void) { material.SetTexture("_MainTex", def.BlockTileAtlas.texture); material.name = def.BlockTileAtlas.name + "Mat"; if ((UnityEngine.Object)def.BlockTileShineAtlas != (UnityEngine.Object)null) { material.SetTexture("_SpecularTex", def.BlockTileShineAtlas.texture); material.EnableKeyword("ENABLE_SHINE"); } } else { material.SetTexture("_MainTex", def.BlockTilePlaceAtlas.texture); material.name = def.BlockTilePlaceAtlas.name + "Mat"; } int num = Grid.WidthInCells / 16; int num2 = Grid.HeightInCells / 16; meshChunks = new Mesh[num, num2]; dirtyChunks = new bool[num, num2]; for (int i = 0; i < num2; i++) { for (int j = 0; j < num; j++) { dirtyChunks[j, i] = true; } } BlockTileDecorInfo blockTileDecorInfo = (element != SimHashes.Void) ? def.DecorBlockTileInfo : def.DecorPlaceBlockTileInfo; if ((bool)blockTileDecorInfo) { decorRenderInfo = new DecorRenderInfo(num, num2, queryLayer, def, blockTileDecorInfo); } string name = def.BlockTileAtlas.items[0].name; int length = name.Length; int num3 = length -= 4; int num4 = num3 - 8; int num5 = num4 - 1; int startIndex = num5 - 8; atlasInfo = new AtlasInfo[def.BlockTileAtlas.items.Length]; for (int k = 0; k < atlasInfo.Length; k++) { TextureAtlas.Item item = def.BlockTileAtlas.items[k]; string value = item.name.Substring(startIndex, 8); string value2 = item.name.Substring(num4, 8); int requiredConnections = Convert.ToInt32(value, 2); int forbiddenConnections = Convert.ToInt32(value2, 2); atlasInfo[k].requiredConnections = (Bits)requiredConnections; atlasInfo[k].forbiddenConnections = (Bits)forbiddenConnections; atlasInfo[k].uvBox = item.uvBox; atlasInfo[k].name = item.name; } trimUVSize = new Vector2(0.03125f, 0.03125f); }