Exemple #1
0
        public static void Dump(BlockTileDecorInfo info)
        {
            if (info == null)
            {
                return;
            }

            Debug.Log("");
            Debug.Log($"Tile Decor Info: {info.name}");

            foreach (var d in info.decor)
            {
                Debug.Log("");
                Debug.Log($"name: {d.name}");
                Debug.Log($"probabilityCutoff: {d.probabilityCutoff}");
                Debug.Log($"requiredConnections: {d.requiredConnections}");
                Debug.Log($"forbiddenConnections: {d.forbiddenConnections}");
                Debug.Log("variants:");
                foreach (var v in d.variants)
                {
                    Debug.Log($"    name: {v.name}");
                    Debug.Log($"    offset: {v.offset}");
                    Debug.Log($"    variant.uvBox: {v.atlasItem.uvBox}");
                    for (int i = 0; i < v.atlasItem.uvs.Length; i++)
                    {
                        Debug.Log($"    variant.uvs[{i}]: {v.atlasItem.uvs[i]}");
                    }
                }
            }
        }
Exemple #2
0
 public DecorRenderInfo(int num_x_chunks, int num_y_chunks, int query_layer, BuildingDef def, BlockTileDecorInfo decorInfo)
 {
     this.decorInfo = decorInfo;
     queryLayer     = query_layer;
     material       = new Material(def.BlockTileMaterial);
     if (def.BlockTileIsTransparent)
     {
         material.renderQueue = RenderQueues.Liquid;
     }
     else if (def.SceneLayer == Grid.SceneLayer.TileMain)
     {
         material.renderQueue = RenderQueues.BlockTiles;
     }
     material.SetTexture("_MainTex", decorInfo.atlas.texture);
     if ((UnityEngine.Object)decorInfo.atlasSpec != (UnityEngine.Object)null)
     {
         material.SetTexture("_SpecularTex", decorInfo.atlasSpec.texture);
         material.EnableKeyword("ENABLE_SHINE");
     }
     else
     {
         material.DisableKeyword("ENABLE_SHINE");
     }
     meshChunks = new Mesh[num_x_chunks, num_y_chunks];
 }
Exemple #3
0
        private BlockTileDecorInfo makeBlockTileDecorInfo(TextAsset jsonData, TextAsset atlasData, Texture2D texture)
        {
            BlockTileDecorInfo blockTileDecorInfo = BlockTileDecorInfo.CreateInstance <BlockTileDecorInfo>();
            JObject            parsed             = JObject.Parse(jsonData.text);

            blockTileDecorInfo.sortOrder = parsed["sortOrder"].Value <int>();
            List <BlockTileDecorInfo.Decor> decorList = new List <BlockTileDecorInfo.Decor>();

            foreach (JObject jItem in parsed["decor"]["Array"])
            {
                BlockTileDecorInfo.Decor decor = new BlockTileDecorInfo.Decor();
                decor.name = jItem["name"].Value <string>();
                decor.requiredConnections  = (BlockTileRenderer.Bits)jItem["requiredConnections"].Value <int>();
                decor.forbiddenConnections = (BlockTileRenderer.Bits)jItem["forbiddenConnections"].Value <int>();
                decor.probabilityCutoff    = jItem["probabilityCutoff"].Value <float>();
                decor.sortOrder            = jItem["sortOrder"].Value <int>();
                List <BlockTileDecorInfo.ImageInfo> imageInfoList = new List <BlockTileDecorInfo.ImageInfo>();
                foreach (JObject jImageInfoItem in jItem["variants"]["Array"])
                {
                    BlockTileDecorInfo.ImageInfo imageInfo = new BlockTileDecorInfo.ImageInfo();
                    imageInfo.name   = jImageInfoItem["name"].Value <string>();
                    imageInfo.offset = new Vector3(jImageInfoItem["offset"]["x"].Value <float>(),
                                                   jImageInfoItem["offset"]["y"].Value <float>());
                    imageInfoList.Add(imageInfo);
                }
                decor.variants = imageInfoList.ToArray();
                decorList.Add(decor);
            }
            blockTileDecorInfo.decor = decorList.ToArray();
            TextureAtlas atlas = TextureAtlasHandler.Instance.makeTextureAtlas(atlasData, texture);

            blockTileDecorInfo.atlas = atlas;
            return(blockTileDecorInfo);
        }
Exemple #4
0
        public static BlockTileDecorInfo GetCustomTileDecor(string path, string baseInfo)
        {
            BlockTileDecorInfo decorInfo = null;

            try
            {
                BlockTileDecorInfo ReferenceDecorInfo = Assets.GetBlockTileDecorInfo(baseInfo);

                var data = File.ReadAllBytes(path);
                var tex  = new Texture2D(2, 2);
                tex.LoadImage(data);
                var textureAtlas = ScriptableObject.CreateInstance <TextureAtlas>();
                textureAtlas.texture     = tex;
                textureAtlas.scaleFactor = ReferenceDecorInfo.atlas.scaleFactor;
                textureAtlas.items       = ReferenceDecorInfo.atlas.items;

                decorInfo           = ScriptableObject.CreateInstance <BlockTileDecorInfo>();
                decorInfo.atlas     = textureAtlas;
                decorInfo.sortOrder = ReferenceDecorInfo.sortOrder;
                decorInfo.decor     = ReferenceDecorInfo.decor;
            }
            catch
            {
                Debug.LogError($"Could not load atlas image at path {path}");
            }

            return(decorInfo);
        }
Exemple #5
0
 static void Postfix(ref BlockTileDecorInfo __instance)
 {
     for (int i = 0; i < __instance.decor.Count(); i++)
     {
         if (decorsToRemove.Contains(__instance.decor[i].name))
         {
             __instance.decor[i].probabilityCutoff = float.MaxValue;
         }
     }
 }
        public static BuildingDef CreateTileBuildingDef(string ID, string materialName, bool spec = true)
        {
            string      mat = materialName.ToLower();
            BuildingDef def = BuildingTemplates.CreateBuildingDef(
                id: ID,
                width: 1,
                height: 1,
                anim: "floor_basic_kanim",
                hitpoints: 100,
                construction_time: 30f,
                construction_mass: new float[] { 50f, 50f },
                construction_materials: new string[] { "StainedGlassMaterial", "Glass" },
                melting_point: 1600f,
                build_location_rule: BuildLocationRule.Tile,
                decor: new EffectorValues(20, 1),
                noise: NOISE_POLLUTION.NONE
                );

            BuildingTemplates.CreateFoundationTileDef(def);

            def.ThermalConductivity = 10f;

            def.Floodable                = false;
            def.Overheatable             = false;
            def.Entombable               = false;
            def.UseStructureTemperature  = false;
            def.AudioCategory            = "Metal";
            def.AudioSize                = "small";
            def.BaseTimeUntilRepair      = -1f;
            def.SceneLayer               = Grid.SceneLayer.GlassTile;
            def.isKAnimTile              = true;
            def.isSolidTile              = true;
            def.BlockTileIsTransparent   = true;
            def.ConstructionOffsetFilter = BuildingDef.ConstructionOffsetFilter_OneDown;
            def.DragBuild                = true;
            def.ShowInBuildMenu          = true; // Does not actually show up because it has no category to show up in. However, this makes the mod Blueprints think it is buildable, tricking it into allowing to blueprint these tiles

            def.BlockTileMaterial = Assets.GetMaterial("tiles_solid");

            def.BlockTileAtlas      = GetCustomAtlas(LOCALPATH, mat + "_glass_tiles", Assets.GetTextureAtlas("tiles_metal"));
            def.BlockTilePlaceAtlas = GetCustomAtlas(LOCALPATH, mat + "_glass_tiles_place", Assets.GetTextureAtlas("tiles_metal"));

            BlockTileDecorInfo decorBlockTileInfo = UnityEngine.Object.Instantiate(Assets.GetBlockTileDecorInfo("tiles_glass_tops_decor_info"));

            decorBlockTileInfo.atlas    = GetCustomAtlas(LOCALPATH, mat + "_glass_tiles_tops", decorBlockTileInfo.atlas);
            def.DecorBlockTileInfo      = decorBlockTileInfo;
            def.DecorPlaceBlockTileInfo = Assets.GetBlockTileDecorInfo("tiles_glass_tops_decor_place_info"); // for placement original glass is perfectly good

            if (spec)
            {
                def.BlockTileShineAtlas = GetCustomAtlas(LOCALPATH, mat + "_glass_tiles_spec", Assets.GetTextureAtlas("tiles_metal"));
            }

            return(def);
        }
            public LayerRenderInfo(int queryLayer, int renderLayer, BuildingDef def,
                                   SimHashes element)
            {
                int   width = Grid.WidthInCells / CHUNK_SIZE + 1;
                int   height = Grid.HeightInCells / CHUNK_SIZE + 1;
                float z = Grid.GetLayerZ(def.SceneLayer), decorZOffset;

                this.queryLayer = queryLayer;
                this.element    = element;
                occupiedCells   = new Dictionary <int, int>(CHUNK_SIZE * CHUNK_SIZE / 4);
                renderMaterial  = def.GetMaterial(element);
                renderChunks    = new MeshChunk[width, height];
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        renderChunks[x, y] = new MeshChunk(renderMaterial, renderLayer, z);
                    }
                }
                // Spawn tile decor if needed
                decorRenderInfo = (element == SimHashes.Void) ? def.DecorPlaceBlockTileInfo :
                                  def.DecorBlockTileInfo;
                if (decorRenderInfo == null)
                {
                    decorMaterial  = null;
                    decorTriangles = null;
                    decorChunks    = null;
                }
                else
                {
                    // Decor has to appear in front to avoid z-fighting
                    if (def.BlockTileIsTransparent)
                    {
                        decorZOffset = Grid.GetLayerZ(Grid.SceneLayer.TileFront) - Grid.
                                       GetLayerZ(Grid.SceneLayer.Liquid) + DECOR_Z_OFFSET;
                    }
                    else
                    {
                        decorZOffset = DECOR_Z_OFFSET;
                    }
                    decorMaterial  = def.GetDecorMaterial(decorRenderInfo);
                    decorTriangles = new List <TriangleInfo>(32);
                    decorChunks    = new MeshChunk[width, height];
                    for (int x = 0; x < width; x++)
                    {
                        for (int y = 0; y < height; y++)
                        {
                            decorChunks[x, y] = new MeshChunk(decorMaterial, renderLayer, z +
                                                              decorZOffset);
                        }
                    }
                }
                atlasInfo = def.GenerateAtlas();
            }
        public override BuildingDef CreateBuildingDef()
        {
            BuildingDef def = BuildingTemplates.CreateBuildingDef(
                id: ID,
                width: 1,
                height: 1,
                anim: "floor_basic_kanim",
                hitpoints: 100,
                construction_time: 30f,
                construction_mass: new float[] { 50f, 50f },
                construction_materials: new string[] { "StainedGlassMaterial", "Glass" },
                melting_point: 1600f,
                build_location_rule: BuildLocationRule.Tile,
                decor: new EffectorValues(20, 3),
                noise: NOISE_POLLUTION.NONE
                );

            BuildingTemplates.CreateFoundationTileDef(def);

            // testing value. change later
            def.ThermalConductivity = 10f;

            def.Floodable                = false;
            def.Overheatable             = false;
            def.Entombable               = false;
            def.UseStructureTemperature  = false;
            def.AudioCategory            = "Metal";
            def.AudioSize                = "small";
            def.BaseTimeUntilRepair      = -1f;
            def.SceneLayer               = Grid.SceneLayer.GlassTile;
            def.isKAnimTile              = true;
            def.isSolidTile              = true;
            def.BlockTileIsTransparent   = true;
            def.ConstructionOffsetFilter = BuildingDef.ConstructionOffsetFilter_OneDown;
            def.DragBuild                = true;

            def.BlockTileMaterial = Assets.GetMaterial("tiles_solid");

            def.BlockTileAtlas      = GetCustomAtlas(LOCALPATH, mat + "_glass_tiles", Assets.GetTextureAtlas("tiles_metal"));
            def.BlockTilePlaceAtlas = GetCustomAtlas(LOCALPATH, mat + "_glass_tiles_place", Assets.GetTextureAtlas("tiles_metal"));

            BlockTileDecorInfo decorBlockTileInfo = UnityEngine.Object.Instantiate(Assets.GetBlockTileDecorInfo("tiles_glass_tops_decor_info"));

            decorBlockTileInfo.atlas    = GetCustomAtlas(LOCALPATH, mat + "_glass_tiles_tops", decorBlockTileInfo.atlas);
            def.DecorBlockTileInfo      = decorBlockTileInfo;
            def.DecorPlaceBlockTileInfo = Assets.GetBlockTileDecorInfo("tiles_glass_tops_decor_place_info");
            def.BlockTileShineAtlas     = GetCustomAtlas(LOCALPATH, mat + "_glass_tiles_spec", Assets.GetTextureAtlas("tiles_metal"));

            return(def);
        }
Exemple #9
0
        private List <BlockTileDecorInfo> loadDirectory(string directoryPath)
        {
            if (!Directory.Exists(directoryPath))
            {
                return(new List <BlockTileDecorInfo>());
            }

            List <BlockTileDecorInfo> blockTileDecorInfoList = new List <BlockTileDecorInfo>();

            foreach (FileInfo file in new DirectoryInfo(directoryPath).GetFiles())
            {
                TextAsset text      = null;
                TextAsset atlasText = null;
                Texture2D texture   = null;
                foreach (UnityEngine.Object asset in AssetBundle.LoadFromFile(file.FullName).LoadAllAssets())
                {
                    if (asset is Texture2D)
                    {
                        texture = asset as Texture2D;
                    }
                    else if (asset.name.EndsWith("_info"))
                    {
                        text = asset as TextAsset;
                    }
                    else if (asset.name.EndsWith("_atlas"))
                    {
                        atlasText = asset as TextAsset;
                    }
                }
                if (text == null)
                {
                    DebugUtil.LogWarningArgs(string.Format("could not load decor file, skipping {0}", file.Name));
                }
                if (atlasText == null)
                {
                    DebugUtil.LogWarningArgs(string.Format("could not load atlas file, skipping {0}", file.Name));
                }
                if (texture == null)
                {
                    DebugUtil.LogWarningArgs(string.Format("could not load texture file, skipping {0}", file.Name));
                }
                BlockTileDecorInfo blockTileDecorInfo = makeBlockTileDecorInfo(text, atlasText, texture);
                blockTileDecorInfo.name = file.Name;
                blockTileDecorInfoList.Add(blockTileDecorInfo);
            }
            return(blockTileDecorInfoList);
        }
Exemple #10
0
        /// <summary>
        /// Gets the material to use for rendering decor ornaments on tiled buildings.
        /// </summary>
        /// <param name="def">The building def to render.</param>
        /// <param name="decorInfo">The decor atlases to use for the ornaments.</param>
        /// <returns>The material to use for the mesh renderers.</returns>
        public static Material GetDecorMaterial(this BuildingDef def,
                                                BlockTileDecorInfo decorInfo)
        {
            var material = GetBaseMaterial(def);

            material.SetTexture("_MainTex", decorInfo.atlas.texture);
            var atlasSpec = decorInfo.atlasSpec;

            if (atlasSpec != null)
            {
                material.SetTexture("_SpecularTex", atlasSpec.texture);
                material.EnableKeyword(SHINE);
            }
            else
            {
                material.DisableKeyword(SHINE);
            }
            return(material);
        }
Exemple #11
0
 public void FreeResources()
 {
     decorInfo = null;
     UnityEngine.Object.DestroyImmediate(material);
     material = null;
     for (int i = 0; i < meshChunks.GetLength(0); i++)
     {
         for (int j = 0; j < meshChunks.GetLength(1); j++)
         {
             if ((UnityEngine.Object)meshChunks[i, j] != (UnityEngine.Object)null)
             {
                 UnityEngine.Object.DestroyImmediate(meshChunks[i, j]);
                 meshChunks[i, j] = null;
             }
         }
     }
     meshChunks = null;
     triangles.Clear();
 }
Exemple #12
0
 /// <summary>
 /// Applied after GetBlockTileDecorInfo runs.
 /// </summary>
 internal static bool Prefix(ref BlockTileDecorInfo __result)
 {
     __result = null;
     return(false);
 }
Exemple #13
0
            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);
            }