Esempio n. 1
0
        Texture2D GetTextureFromImg(ImgFile img)
        {
            DFBitmap  bitmap  = img.GetDFBitmap();
            Texture2D texture = new Texture2D(bitmap.Width, bitmap.Height, TextureFormat.ARGB32, false);

            texture.SetPixels32(img.GetColors32(ref bitmap, 0));
            texture.Apply(false, true);

            return(texture);
        }
        private void LoadNightSky()
        {
            const int width  = 512;
            const int height = 219;

            // Get night sky matching sky index
            int nightSky;

            if (SkyIndex >= 0 && SkyIndex <= 7)
            {
                nightSky = 3;
            }
            else if (SkyIndex >= 8 && SkyIndex <= 15)
            {
                nightSky = 1;
            }
            else if (SkyIndex >= 16 && SkyIndex <= 23)
            {
                nightSky = 2;
            }
            else
            {
                nightSky = 0;
            }

            string filename = string.Format("NITE{0:00}I0.IMG", nightSky);

            imgFile = new ImgFile(Path.Combine(dfUnity.Arena2Path, filename), FileUsage.UseMemory, true);
            imgFile.Palette.Load(Path.Combine(dfUnity.Arena2Path, imgFile.PaletteName));

            // Get sky bitmap
            DFBitmap dfBitmap = imgFile.GetDFBitmap(0, 0);

            // Draw stars
            if (ShowStars)
            {
                for (int i = 0; i < dfBitmap.Data.Length; i++)
                {
                    // Stars should only be drawn over clear sky indices
                    int index = dfBitmap.Data[i];
                    if (index > 16 && index < 32)
                    {
                        if (random.NextDouble() < starChance)
                        {
                            dfBitmap.Data[i] = starColorIndices[random.Next(0, starColorIndices.Length)];
                        }
                    }
                }
            }

            // Get sky colour array
            Color32[] colors = imgFile.GetColors32(ref dfBitmap);

            // Fix seam on right side of night skies
            for (int y = 0; y < height; y++)
            {
                int pos = y * width + width - 2;
                colors[pos + 1] = colors[pos];
            }

            skyColors.west       = colors;
            skyColors.east       = colors;
            skyColors.clearColor = skyColors.west[0];
        }