Ejemplo n.º 1
0
    /// <summary>
    /// Build all settings from import data
    /// </summary>
    public static void BuildFromImport()
    {
        // Setup icon atlas
        mIconManager = new AtlasBuilder(IconSize);


        // Build all items
        mItems = new ItemData[ImportCache.Count];

        for (int i = 0; i < ImportCache.Count; ++i)
        {
            ItemData item = Build((ushort)i, ImportCache[i]);
            mItems[i] = item;
        }
        ImportCache.Clear();


        mIconManager.BuildTexture();
        Debug.Log("Imported " + mItems.Length + " items onto " + mIconManager.mTextureAtlas.width + "x" + mIconManager.mTextureAtlas.height + " atlas");


        // Update terrain mat
        Material mat = mAtlasMaterial;

        mat.SetTexture("_AtlasTex", mIconManager.mTextureAtlas);
        mat.SetInt("_AtlasSize", mIconManager.CurrentAtlasSize);

        mat = mAtlasUIMaterial;
        mat.SetTexture("_AtlasTex", mIconManager.mTextureAtlas);
        mat.SetInt("_AtlasSize", mIconManager.CurrentAtlasSize);
    }
Ejemplo n.º 2
0
    // Use this function to add animations from external scripts
    public static void addAnimationToAtlas(string n, List<Texture2D> imgs, float fps, int wrap, bool playonwake)
    {
        aB = (AtlasBuilder)EditorWindow.GetWindow( typeof(AtlasBuilder) );

        if(imgs.Count > 0)
            aB.addAnimation(n, imgs, fps, wrap, playonwake);
    }
        private UITextureAtlas GetUiAtlas()
        {
            if (guiAtlas_ != null)
            {
                return(guiAtlas_);
            }

            // Create base atlas with backgrounds and no foregrounds
            var futureAtlas = new AtlasBuilder(
                atlasName: "SpeedLimits_Atlas",
                loadingPath: "SpeedLimits",
                sizeHint: new IntVector2(512));

            // Merge names of all button sprites atlasBuilder
            foreach (string prefix in new[]
                     { "MphToggle", "EditSegments", "EditLanes", "EditDefaults" })
            {
                ButtonSkin skin = ButtonSkin.CreateSimple(
                    foregroundPrefix: prefix,
                    backgroundPrefix: UConst.MAINMENU_ROUND_BUTTON_BG)
                                  .CanActivate(background: false)
                                  .CanHover(foreground: false);

                // Create keysets for lane arrow button icons and merge to the shared atlas
                skin.UpdateAtlasBuilder(
                    atlasBuilder: futureAtlas,
                    spriteSize: new IntVector2(50));
            }

            // Load actual graphics into an atlas
            return(futureAtlas.CreateAtlas());
        }
Ejemplo n.º 4
0
        static void Init()
        {
            Screen.ClearColor = 0x1e4e50ff;

            Texture.DefaultMinFilter = TextureFilter.Nearest;
            Texture.DefaultMagFilter = TextureFilter.Nearest;

            var builder = new AtlasBuilder(1024);

            //Pack a font
            var font   = new Font("Assets/NotoSans-Regular.ttf", FontCharSet.BasicLatin);
            var size32 = new FontSize(font, 32);

            builder.AddFont("font", size32, true);

            //Pack a bunch of icons
            builder.AddTiles("Assets/icons.png", 16, 16, true, true);

            atlas = builder.Build(1);
            if (atlas == null)
            {
                throw new Exception("Failed to build the atlas.");
            }

            icons = atlas.GetTiles("icons");

            batch = new DrawBatch2D();
        }
Ejemplo n.º 5
0
        static void Init()
        {
            var font = new Font("Assets/NotoSans-Regular.ttf", FontCharSet.BasicLatin);
            var size = new FontSize(font, 128f);

            var builder = new AtlasBuilder(2048);

            builder.AddBitmap("Assets/star.png", true, true);
            builder.AddBitmap("Assets/face.png", true, true);
            builder.AddBitmap("Assets/maritte.png", true, true);
            builder.AddFont("font", size, true);

            atlas = builder.Build(1);
            if (atlas == null)
            {
                throw new Exception("Failed to build atlas.");
            }

            batch  = new DrawBatch2D();
            shader = new Shader(Shader.Basic2D);

            view = new GuiView(shader, Screen.DrawWidth, Screen.DrawHeight, LayoutMode.Horizontal);
            view.BackgroundColor = Color4.Grey;
            view.Spacing         = 16;
            view.SetPadding(16);

            var left = view.AddChild(new GuiContainer());

            left.BackgroundColor = Color4.Black * 0.25f;
            left.FlexX           = left.FlexY = true;
            left.Spacing         = 16;

            var right = view.AddChild(new GuiContainer());

            right.BackgroundColor = Color4.Blue;
            right.FlexX           = right.FlexY = true;

            var items = left.AddChild(new GuiContainer());

            items.BackgroundColor = Color4.Black * 0.25f;
            items.FlexX           = items.FlexY = true;
            items.Spacing         = 1;
            items.ScrollableY     = true;

            var padding = left.AddChild(new GuiContainer(100, 100, LayoutMode.Vertical));

            padding.BackgroundColor = Color4.White * 0.25f;
            padding.FlexX           = true;
            padding.FlexY           = false;

            for (int i = 0; i < 50; ++i)
            {
                var item = items.AddChild(new GuiElement(16, 40));
                item.FlexY     = false;
                item.OnRender += b => b.DrawRect(item.RectX, item.RectY, item.RectW, item.RectH, Color4.Red);
            }

            Screen.ClearColor = Color4.Black;
            Screen.OnResized += () => view.SetSize(Screen.DrawWidth, Screen.DrawHeight);
        }
Ejemplo n.º 6
0
 public override void SetupButtonSkin(AtlasBuilder futureAtlas)
 {
     // Button backround (from BackgroundPrefix) is provided by MainMenuPanel.Start
     this.Skin = ButtonSkin.CreateSimple(
         foregroundPrefix: "JunctionRestrictions",
         backgroundPrefix: UConst.MAINMENU_ROUND_BUTTON_BG)
                 .CanHover(foreground: false)
                 .CanActivate();
     this.Skin.UpdateAtlasBuilder(
         atlasBuilder: futureAtlas,
         spriteSize: new IntVector2(50));
 }
Ejemplo n.º 7
0
 public override void SetupButtonSkin(AtlasBuilder futureAtlas)
 {
     // Button backround (from BackgroundPrefix) is provided by MainMenuPanel.Start
     this.Skin = new U.ButtonSkin {
         Prefix            = "ParkingRestrictions",
         BackgroundPrefix  = "RoundButton",
         BackgroundHovered = true,
         BackgroundActive  = true,
         ForegroundActive  = true,
     };
     this.Skin.UpdateAtlasBuilder(
         atlasBuilder: futureAtlas,
         spriteSize: new IntVector2(50));
 }
Ejemplo n.º 8
0
 public override void SetupButtonSkin(AtlasBuilder atlasBuilder)
 {
     // Button backround (from BackgroundPrefix) is provided by MainMenuPanel.Start
     this.Skin = new U.ButtonSkin()
     {
         Prefix            = "LaneConnector",
         BackgroundPrefix  = "RoundButton",
         BackgroundHovered = true,
         BackgroundActive  = true,
         ForegroundActive  = true,
     };
     this.Skin.UpdateAtlasBuilder(
         atlasBuilder: atlasBuilder,
         spriteSize: new IntVector2(50));
 }
Ejemplo n.º 9
0
    /// <summary>
    /// Build all settings from import data
    /// </summary>
    public static void BuildFromImport()
    {
        // Setup tile atlas
        mTileManager = new AtlasBuilder(TileSize);

        // Register black (null) tile
        Texture2D Tile = new Texture2D(TileSize, TileSize);

        Tile.name = "Null tile";
        for (int x = 0; x < TileSize; ++x)
        {
            for (int y = 0; y < TileSize; ++y)
            {
                Tile.SetPixel(x, y, Color.black);
            }
        }
        mTileManager.AddItem(Tile);


        // Build all voxels
        mVoxels = new VoxelData[ImportCache.Count];

        for (ushort i = 0; i < ImportCache.Count; ++i)
        {
            VoxelData voxel = Build(i, ImportCache[i]);
            mVoxels[i] = voxel;
        }
        ImportCache.Clear();


        mTileManager.BuildTexture();
        Debug.Log("Imported " + mVoxels.Length + " voxels onto " + mTileManager.mTextureAtlas.width + "x" + mTileManager.mTextureAtlas.height + " atlas");

        // Update terrain mat
        Material mat = mTerrainMaterial;

        mat.SetTexture("_AtlasTex", mTileManager.mTextureAtlas);
        mat.SetInt("_AtlasSize", mTileManager.CurrentAtlasSize);

        mat = mLiquidMaterial;
        mat.SetTexture("_AtlasTex", mTileManager.mTextureAtlas);
        mat.SetInt("_AtlasSize", mTileManager.CurrentAtlasSize);
    }
Ejemplo n.º 10
0
        public override void Import(string input, Stream output)
        {
            var           ser      = new JsonSerializer();
            AtlasMetadata metadata = null;

            string metaPath = "atlas.meta";

            if (File.Exists(metaPath))
            {
                using (var sr = new StreamReader(metaPath)) {
                    metadata = ser.Deserialize <AtlasMetadata>(new JsonTextReader(sr));
                }
            }
            else
            {
                metadata = new AtlasMetadata();
            }

            var lp = new LayoutProperties {
                inputFilePaths = (Directory.Exists("./sprites") ? Directory.GetFiles("./sprites") : Directory.GetFiles("."))
                                 .Where(p => SupportedFormats.Contains(Path.GetExtension(p).ToLower())).ToArray(),
                distanceBetweenImages = metadata.Padding,
                marginWidth           = metadata.Margin,
                powerOfTwo            = metadata.PowerOfTwo,
                maxSpriteWidth        = metadata.MaxSpriteWidth > 0 ? metadata.MaxSpriteWidth : 16384,
                maxSpriteHeight       = metadata.MaxSpriteHeight > 0 ? metadata.MaxSpriteHeight : 16384,
                filterMode            = metadata.FilterMode,
            };
            var sheetMaker = new AtlasBuilder(lp);

            using (var tw = new TarWriter(output)) {
                using (MemoryStream atlasStream = new MemoryStream(), sheetStream = new MemoryStream()) {
                    using (var bw = new BinaryWriter(atlasStream)) {
                        sheetMaker.Create(bw, sheetStream, ImageFormat.Png, metadata.NoPreMultiply);
                        bw.Flush();
                        atlasStream.Position = 0;
                        sheetStream.Position = 0;
                        tw.Write(atlasStream, atlasStream.Length, "atlas.bin");
                        tw.Write(sheetStream, sheetStream.Length, "sheet.png");
                    }
                }
            }
        }
        private UITextureAtlas GetAtlas()
        {
            if (laneArrowButtonAtlas_ != null)
            {
                return(laneArrowButtonAtlas_);
            }

            // Create base atlas with backgrounds and no foregrounds
            ButtonSkin backgroundOnlySkin = ButtonSkin.CreateSimple(
                foregroundPrefix: "LaneArrow",
                backgroundPrefix: "LaneArrow")
                                            .CanHover(foreground: false)
                                            .CanActivate(foreground: false)
                                            .NormalForeground(false);
            var futureAtlas = new AtlasBuilder(
                atlasName: "TMPE_LaneArrowsTool_Atlas",
                loadingPath: "LaneArrows",
                sizeHint: new IntVector2(256));

            backgroundOnlySkin.UpdateAtlasBuilder(
                atlasBuilder: futureAtlas,
                spriteSize: new IntVector2(64));

            // Merge names of all foreground sprites for 3 directions into atlasKeySet
            foreach (string prefix in new[]
                     { "LaneArrowLeft", "LaneArrowRight", "LaneArrowForward" })
            {
                ButtonSkin skin = ButtonSkin.CreateSimple(
                    foregroundPrefix: prefix,
                    backgroundPrefix: string.Empty)
                                  .CanActivate(background: false);

                // Create keysets for lane arrow button icons and merge to the shared atlas
                skin.UpdateAtlasBuilder(
                    atlasBuilder: futureAtlas,
                    spriteSize: new IntVector2(64));
            }

            // Load actual graphics into an atlas
            laneArrowButtonAtlas_ = futureAtlas.CreateAtlas();
            return(laneArrowButtonAtlas_);
        }
Ejemplo n.º 12
0
    void Start()
    {
        var mesh = this.GetComponent<MeshFilter>().mesh;
        _batcher = new Batcher(mesh, this.GetComponent<Camera>());

        AtlasBuilder atlasBuilder = new AtlasBuilder();

        var watch = new System.Diagnostics.Stopwatch();
        watch.Start();

        foreach(char c in "abcdefghijklmnopqrst")
        {
            atlasBuilder.AddTexture("Textures/" + c.ToString());
        }
        TextureItem[] items = atlasBuilder.Pack();

        watch.Stop();
        Debug.Log("Time to pack: " + watch.ElapsedMilliseconds);

        _batcher.AddTextureItems(items);

        renderer.material.mainTexture = atlasBuilder.atlasTexture;

        _root = new Container(new Vector2(0, 0));

        //		Container upperLeft = new Container("Textures/b", new Vector2(0, 0));
        //		upperLeft.batcher = _batcher;
        //
        //		Container lowerRight = new Container("Textures/b", new Vector2(Screen.width - 512f, Screen.height - 512f));
        //		lowerRight.batcher = _batcher;
        //
        //		_root.AddChild(upperLeft);
        //		_root.AddChild(lowerRight);

        for(int i = 0; i < 100; i++) {
            AddStuffToContainer(_root);
        }
    }
Ejemplo n.º 13
0
        //private static void BuildAppConfigFile(string root_path, AppProject project)
        //{
        //    GameProperties props = new GameProperties()
        //    {
        //        Title = project.Title,
        //        FrameRate = project.FrameRate,
        //        CanvasWidth = project.CanvasWidth,
        //        CanvasHeight = project.CanvasHeight,
        //        Fullscreen = project.StartFullscreen,
        //        PreloadResourcePaks = project.PreloadPaks
        //    };

        //    File.WriteAllBytes(Path.Combine(root_path, "Config.json"),
        //        JsonSerializer.PrettyPrintByteArray(JsonSerializer.Serialize(props)));

        //}

        private static List <ResourcePak> BuildProjectResources(GameAssetsManifest manifest)
        {
            var resource_groups = manifest.Resources;

            var results = new List <ResourcePak>();

            foreach (var(groupKey, group) in resource_groups)
            {
                var pak = new ResourcePak(groupKey);

                Console.WriteLine($"Creating resource Pak: {pak.Name}");

                if (group.Images != null)
                {
                    foreach (var image_info in group.Images)
                    {
                        var pixmap_data = ImageBuilder.Build(image_info.Id, image_info.Path);

                        pak.Images.Add(image_info.Id, pixmap_data);

                        pak.TotalResourcesCount++;

                        Console.WriteLine($"Added Image: {pixmap_data.Id}");
                    }
                }

                if (group.Shaders != null)
                {
                    foreach (var shader_info in group.Shaders)
                    {
                        var shader_data = ShaderBuilder.Build(shader_info.Id, shader_info.VsPath, shader_info.FsPath);

                        pak.Shaders.Add(shader_info.Id, shader_data);

                        pak.TotalResourcesCount++;

                        Console.WriteLine($"Added Shader: {shader_data.Id}");
                    }
                }

                if (group.Fonts != null)
                {
                    foreach (var font_info in group.Fonts)
                    {
                        var build_params = new FontBuildParams()
                        {
                            Id          = font_info.Id,
                            LineSpacing = font_info.LineSpacing,
                            Spacing     = font_info.Spacing,
                            DefaultChar = font_info.DefaultChar,
                            Faces       = font_info.Faces.Select(f => new FontFace()
                            {
                                CharRanges = f.CharRanges.Select(CharRange.GetFromKey).ToList(),
                                Path       = f.Path,
                                Size       = f.Size,
                            }).ToList()
                        };

                        var font_data = FontBuilder.Build(build_params);

                        pak.Fonts.Add(font_info.Id, font_data);

                        pak.TotalResourcesCount++;

                        Console.WriteLine($"Added Font: {font_data.Id}");
                    }
                }

                if (group.Atlases != null)
                {
                    foreach (var atlas_info in group.Atlases)
                    {
                        var atlas_data = AtlasBuilder.Build(atlas_info.Id, atlas_info.Path, atlas_info.Regions);

                        pak.Atlases.Add(atlas_data.Id, atlas_data);

                        pak.TotalResourcesCount++;

                        Console.WriteLine($"Added Atlas: {atlas_data.Id}");
                    }
                }

                if (group.TextFiles != null)
                {
                    foreach (var text_file_info in group.TextFiles)
                    {
                        var text_file_data = TextBuilder.Build(text_file_info.Id, text_file_info.Path);
                        pak.TextFiles.Add(text_file_info.Id, text_file_data);

                        pak.TotalResourcesCount++;

                        Console.WriteLine($"Added TextFile: {text_file_data.Id}");
                    }
                }

                results.Add(pak);
                Console.WriteLine($"Built PAK with {pak.TotalResourcesCount} resources.");
            }

            return(results);
        }
Ejemplo n.º 14
0
        //private static void BuildAppConfigFile(string root_path, AppProject project)
        //{
        //    GameProperties props = new GameProperties()
        //    {
        //        Title = project.Title,
        //        FrameRate = project.FrameRate,
        //        CanvasWidth = project.CanvasWidth,
        //        CanvasHeight = project.CanvasHeight,
        //        Fullscreen = project.StartFullscreen,
        //        PreloadResourcePaks = project.PreloadPaks
        //    };

        //    File.WriteAllBytes(Path.Combine(root_path, "Config.json"),
        //        JsonSerializer.PrettyPrintByteArray(JsonSerializer.Serialize(props)));

        //}

        private static List <ResourcePak> BuildProjectResources(GameAssetsManifest manifest)
        {
            var resource_groups = manifest.Resources;

            var results = new List <ResourcePak>();

            foreach (var resource_group in resource_groups)
            {
                var pak = new ResourcePak(resource_group.Key);

                Console.WriteLine($"Creating resource Pak: {pak.Name}");

                if (resource_group.Value.Images != null)
                {
                    foreach (var image_info in resource_group.Value.Images)
                    {
                        var pixmap_data = ImageBuilder.Build(image_info.Id, image_info.Path);

                        pak.Images.Add(image_info.Id, pixmap_data);

                        pak.TotalResourcesCount++;

                        Console.WriteLine($"Added Image: {pixmap_data.Id}");
                    }
                }

                if (resource_group.Value.Shaders != null)
                {
                    foreach (var shader_info in resource_group.Value.Shaders)
                    {
                        var shader_data = ShaderBuilder.Build(shader_info.Id, shader_info.VsPath, shader_info.FsPath);

                        pak.Shaders.Add(shader_info.Id, shader_data);

                        pak.TotalResourcesCount++;

                        Console.WriteLine($"Added Shader: {shader_data.Id}");
                    }
                }

                if (resource_group.Value.Fonts != null)
                {
                    foreach (var font_info in resource_group.Value.Fonts)
                    {
                        var build_params = new FontBuildParams()
                        {
                            Id             = font_info.Id,
                            Path           = font_info.Path,
                            Size           = font_info.Size,
                            CharRangeLevel = font_info.CharRangeLevel,
                            PaddingLeft    = font_info.Padding != null ? font_info.Padding[0] : 0,
                            PaddingRight   = font_info.Padding != null ? font_info.Padding[1] : 0,
                            PaddingUp      = font_info.Padding != null ? font_info.Padding[2] : 0,
                            PaddingDown    = font_info.Padding != null ? font_info.Padding[3] : 0,
                            DropShadow     = font_info.DropShadow,
                            ShadowOffsetX  = font_info.ShadowOffsetX,
                            ShadowOffsetY  = font_info.ShadowOffsetY,
                            ShadowColor    = font_info.ShadowColor != null?Color.FromHex(font_info.ShadowColor) : Color.Black
                        };

                        var font_data = FontBuilder.Build(build_params);

                        pak.Fonts.Add(font_info.Id, font_data);

                        pak.TotalResourcesCount++;

                        Console.WriteLine($"Added Font: {font_data.Id}");
                    }
                }

                if (resource_group.Value.Atlases != null)
                {
                    foreach (var atlas_info in resource_group.Value.Atlases)
                    {
                        var atlas_data = AtlasBuilder.Build(atlas_info.Id, atlas_info.Path, atlas_info.Regions);

                        pak.Atlases.Add(atlas_data.Id, atlas_data);

                        pak.TotalResourcesCount++;

                        Console.WriteLine($"Added Atlas: {atlas_data.Id}");
                    }
                }

                if (resource_group.Value.TextFiles != null)
                {
                    foreach (var text_file_info in resource_group.Value.TextFiles)
                    {
                        var text_file_data = TextBuilder.Build(text_file_info.Id, text_file_info.Path);
                        pak.TextFiles.Add(text_file_info.Id, text_file_data);

                        pak.TotalResourcesCount++;

                        Console.WriteLine($"Added TextFile: {text_file_data.Id}");
                    }
                }

                results.Add(pak);
                Console.WriteLine($"Built PAK with {pak.TotalResourcesCount} resources.");
            }

            return(results);
        }
Ejemplo n.º 15
0
        private static void CheckRasterFonts(string fontsDirectory = "./fonts", string rasterDirectory = "./cache/fonts")
        {
            DirectoryInfo cacheDir = new DirectoryInfo(rasterDirectory.Replace('/', Path.DirectorySeparatorChar));

            if (!cacheDir.Exists)
            {
                cacheDir.Create();
            }

            DirectoryInfo fontsDir = new DirectoryInfo(fontsDirectory.Replace('/', Path.DirectorySeparatorChar));

            if (!fontsDir.Exists)
            {
                fontsDir.Create();
                throw new FileNotFoundException(string.Format("The fonts directory doesnt exists ({0}). No font files installed on the application.", fontsDirectory));
            }

            FileInfo[] files     = fontsDir.GetFiles();
            long       fontCount = 0;

            if (files != null)
            {
                foreach (FileInfo font in files)
                {
                    if (string.Equals(font.Extension, ".otf", StringComparison.OrdinalIgnoreCase) || string.Equals(font.Extension, ".ttf", StringComparison.OrdinalIgnoreCase))
                    {
                        Log.WriteLine("Loading font file %@...", LogLevel.Message, font.Name);
                        FontLoader.LoadFromFile(font.FullName);
                        fontCount++;
                    }
                }
            }

            if (files == null || files.Length < 1 || fontCount < 1)
            {
                throw new FileNotFoundException(string.Format("No OTF font files found on the fonts directory ({0}). No font files installed on the application.", fontsDirectory));
            }

            Log.WriteLine("Loaded %@ fonts into the application.", LogLevel.Message, FontLoader.LoadedFonts.Length.ToString("N0"));

            GdiFontRasterizer rasterizer = new GdiFontRasterizer(true, true, true);

            foreach (FontFamily family in FontLoader.LoadedFonts)
            {
                FileInfo targetFile         = FontAtlas.GetAtlasFileFromName(cacheDir.FullName, family.Name);
                FileInfo targetFileMetadata = FontAtlas.GetAtlasMetadataFileFromName(cacheDir.FullName, family.Name);

                if (!targetFile.Exists)
                {
                    // Build font
                    Log.WriteLine("Font '%@' is missing from cache. Rasterizing it...", LogLevel.Message, family.Name);

                    rasterizer.SelectedFont = new Font(family, 18.0f);
                    GlyphCollection rasterizedFont = rasterizer.Raster();

                    if (rasterizedFont.Count < 1)
                    {
                        Log.WriteLine("Failed to process font file %@. No glyphs found inside the font file.", LogLevel.Error, family.Name);
                        continue;;
                    }

                    Atlas fontAtlas = AtlasBuilder.BuildAtlas(rasterizedFont, AtlasLayoutMode.Indexed);
                    fontAtlas.ToFile(targetFile.FullName, targetFileMetadata.FullName, ImageFormat.Bmp);
                }
            }
        }
Ejemplo n.º 16
0
 static void Init()
 {
     aB = (AtlasBuilder)EditorWindow.GetWindow( typeof(AtlasBuilder) );
     aB.Show();
 }