Example #1
0
    bmp2tile()
    {
        m_project = null;
        if( PlayerPrefs.HasKey( PPKEY_PROJECT_PATH ))
        {
            LoadProject( PlayerPrefs.GetString( PPKEY_PROJECT_PATH ));
            //m_project = new Project( PlayerPrefs.GetString( PPKEY_PROJECT_PATH ));
        }

        if( PlayerPrefs.HasKey( PPKEY_LAST_OPEN_DIRECTORY ))
            m_lastOpenDirectory = PlayerPrefs.GetString( PPKEY_LAST_OPEN_DIRECTORY );
        else
            m_lastOpenDirectory = Application.dataPath;

        if( PlayerPrefs.HasKey( PPKEY_LAST_EXPORT_DIRECTORY ))
            m_lastExportDirectory = PlayerPrefs.GetString( PPKEY_LAST_EXPORT_DIRECTORY );
        else
            m_lastExportDirectory = Application.dataPath;

        m_imageTexture = null;
        m_currentImageData = null;
        m_currentImageConfig = null;
        m_tileBank = null;
        m_tileMap = null;

        m_haveLoadedImage = false;

        m_collisionAlpha = 0.5f;

        m_isResizingTileBank = false;
        m_isResizingPaletteRemap = false;
        m_isResizingImageSettings = false;
        m_isResizingProject = false;
        m_isResizingMapWindow = false;
    }
Example #2
0
    public TileMap(TileBank _bank, PalettizedImage _sourceImage)
    {
        //
        m_tileBank = _bank;

        //
        int w = _sourceImage.m_width;
        int h = _sourceImage.m_height;

        m_width  = 64;       //(_sourceImage.m_width+7) >> 3;
        m_height = 32;       //(_sourceImage.m_height+7) >> 3;
        int sourceWidth  = w >> 3;
        int sourceHeight = h >> 3;

        //
        m_tiles    = new TileInstance[m_width, m_height];
        m_rawTiles = null;

        //
        int x, y;

        for (y = 0; y < sourceHeight; y++)
        {
            string str = y.ToString() + "=(";
            for (x = 0; x < sourceWidth; x++)
            {
                int pixel_x = x * Tile.Width;
                int pixel_y = y * Tile.Height;

                Tile         srcTile      = new Tile(_sourceImage, pixel_x, pixel_y);
                TileInstance tileInstance = m_tileBank.GetTileInstance(srcTile);
                if (tileInstance == null)
                {
                    Debug.LogException(new UnityException("PANIC! Couldn't find tile instance for tile at coordinates " + pixel_x + "," + pixel_y));
                    return;
                }

                //
                m_tiles[x, y] = tileInstance;
                str          += tileInstance.m_tileBankIndex;
                if (tileInstance.m_flipX)
                {
                    str += "x";
                }
                if (tileInstance.m_flipY)
                {
                    str += "y";
                }
                if (x < sourceWidth - 1)
                {
                    str += ",";
                }
            }

            str += ")";
            //Debug.Log( str );
        }
    }
Example #3
0
 public TileInstance(TileBank _tileBank, Tile _tile, int _tileBankIndex, bool _flipX, bool _flipY)
 {
     m_tileBank      = _tileBank;
     m_tile          = _tile;
     m_paletteIndex  = 0;
     m_tileBankIndex = _tileBankIndex;
     m_flipX         = _flipX;
     m_flipY         = _flipY;
 }
 public TileInstance( TileBank _tileBank, Tile _tile, int _tileBankIndex, bool _flipX, bool _flipY )
 {
     m_tileBank = _tileBank;
     m_tile = _tile;
     m_paletteIndex = 0;
     m_tileBankIndex = _tileBankIndex;
     m_flipX = _flipX;
     m_flipY = _flipY;
 }
Example #5
0
    static public TileMap LoadJson(string _fileName)
    {
        string jsonString = System.IO.File.ReadAllText(_fileName);
        Dictionary <string, object> json = (Dictionary <string, object>)MiniJSON.Json.Deserialize(jsonString);

        // Load tile bank
        List <object> tilesetsJson = (List <object>)json["tilesets"];
        Dictionary <string, object> tilesetJson = (Dictionary <string, object>)tilesetsJson[0];
        string imageFileName = (string)tilesetJson["image"];
        string imageFullPath = System.IO.Path.GetDirectoryName(_fileName) + System.IO.Path.DirectorySeparatorChar + imageFileName;
        //LoadBMP( imageFullPath );

        PalettizedImageConfig imageConfig = new PalettizedImageConfig(imageFullPath + ".config");

        PalettizedImage imageData = PalettizedImage.LoadImage(imageFullPath, imageConfig);
        TileBank        tileBank  = null;

        if (imageData != null)
        {
            //
            imageConfig.SetImage(imageData);

            bool optimizeBank = (imageConfig.m_importAsSprite == false);                // Optimize bank when we're not loading the image as a sprite (i.e. optimize when we're loading as a tile bank)
            tileBank = new TileBank(imageData, optimizeBank);
        }

        // Create map texture
        int map_tiles_w  = ((int)(long)json["width"]);
        int map_tiles_h  = ((int)(long)json["height"]);
        int map_pixels_w = map_tiles_w * 8;
        int map_pixels_h = map_tiles_h * 8;

        TileMap ret = new TileMap(map_tiles_w, map_tiles_h);

        // Find each layer
        List <object> layersJson = (List <object>)json["layers"];
        Dictionary <string, object> layerJson = (Dictionary <string, object>)layersJson[0];
        List <object> layerData = (List <object>)layerJson["data"];
        int           tile_x, tile_y;

        for (tile_y = 0; tile_y < map_tiles_h; tile_y++)
        {
            for (tile_x = 0; tile_x < map_tiles_w; tile_x++)
            {
                int i       = tile_y * map_tiles_w + tile_x;
                int tile_id = (int)(long)layerData[i];
                tile_id--;
                TileInstance tileInstance = tileBank.m_allTileInstances[tile_id];

                //
                ret.SetRawTile(tile_x, tile_y, tile_id);
                ret.SetTile(tile_x, tile_y, tileInstance);
            }
        }

        return(ret);
    }
Example #6
0
    public void InitializeWithLevel(string levelName)
    {
        this.tileBank = new TileBank();
        bool fileExists = tileBank.InitializeWithLevel(levelName);

        if (!fileExists)
        {
            this.SetUpMockTiles();
        }
        else
        {
            this.SetUpTiles();
        }
    }
Example #7
0
    public TileMap( TileBank _bank, PalettizedImage _sourceImage )
    {
        //
        m_tileBank = _bank;

        //
        int w = _sourceImage.m_width;
        int h = _sourceImage.m_height;
        m_width = 64;//(_sourceImage.m_width+7) >> 3;
        m_height = 32;//(_sourceImage.m_height+7) >> 3;
        int sourceWidth = w >> 3;
        int sourceHeight = h >> 3;

        //
        m_tiles = new TileInstance[ m_width, m_height ];
        m_rawTiles = null;

        //
        int x, y;
        for( y=0; y<sourceHeight; y++ )
        {
            string str = y.ToString() + "=(";
            for( x=0; x<sourceWidth; x++ )
            {
                int pixel_x = x*Tile.Width;
                int pixel_y = y*Tile.Height;

                Tile srcTile = new Tile( _sourceImage, pixel_x, pixel_y );
                TileInstance tileInstance = m_tileBank.GetTileInstance( srcTile );
                if( tileInstance == null )
                {
                    Debug.LogException( new UnityException( "PANIC! Couldn't find tile instance for tile at coordinates "+pixel_x+","+pixel_y ));
                    return;
                }

                //
                m_tiles[ x, y ] = tileInstance;
                str += tileInstance.m_tileBankIndex;
                if( tileInstance.m_flipX ) str += "x";
                if( tileInstance.m_flipY ) str += "y";
                if( x<sourceWidth-1 )
                    str += ",";
            }

            str += ")";
            //Debug.Log( str );
        }
    }
        public void LoadLevel2()
        {
            this.gridDataStream = new FileStream("Content/Maps/tileMap2.tmx", FileMode.Open, FileAccess.Read);
            this.tileBankStream = new FileStream("Content/Maps/tileBank2.xml", FileMode.Open, FileAccess.Read);

            GridData gridData = GridData.NewFromStreamAndWorldPosition(gridDataStream, new Vector2(1, 0));
            TileBank tileBank = TileBank.CreateFromSerializedData(tileBankStream, content);

            gridDataStream.Position = 0;
            SerializedGridFactory gridFactory = SerializedGridFactory.NewFromData(gridDataStream, gridData, tileBank);

            level = Grid.NewGrid(gridData, gridFactory, DefaultGridDrawer.NewFromGridData(gridData, content, Color.Black));

            // YEY detta funkar
            Predicate <Tile> temp = FindHitboxTiles;

            hitboxList = level.GetLayer("hitbox").GetAllMatchingTiles(temp);
        }
Example #9
0
    bmp2tile()
    {
        m_project = null;
        if (PlayerPrefs.HasKey(PPKEY_PROJECT_PATH))
        {
            LoadProject(PlayerPrefs.GetString(PPKEY_PROJECT_PATH));
            //m_project = new Project( PlayerPrefs.GetString( PPKEY_PROJECT_PATH ));
        }

        if (PlayerPrefs.HasKey(PPKEY_LAST_OPEN_DIRECTORY))
        {
            m_lastOpenDirectory = PlayerPrefs.GetString(PPKEY_LAST_OPEN_DIRECTORY);
        }
        else
        {
            m_lastOpenDirectory = Application.dataPath;
        }

        if (PlayerPrefs.HasKey(PPKEY_LAST_EXPORT_DIRECTORY))
        {
            m_lastExportDirectory = PlayerPrefs.GetString(PPKEY_LAST_EXPORT_DIRECTORY);
        }
        else
        {
            m_lastExportDirectory = Application.dataPath;
        }

        m_imageTexture       = null;
        m_currentImageData   = null;
        m_currentImageConfig = null;
        m_tileBank           = null;
        m_tileMap            = null;

        m_haveLoadedImage = false;

        m_collisionAlpha = 0.5f;

        m_isResizingTileBank      = false;
        m_isResizingPaletteRemap  = false;
        m_isResizingImageSettings = false;
        m_isResizingProject       = false;
        m_isResizingMapWindow     = false;
    }
Example #10
0
    void LoadBMP( string _path )
    {
        m_openImageName = "<Untitled>";

        // Load corresponding config first as it have information on how the image should be loaded
        m_currentImageConfig = new PalettizedImageConfig( _path + ".config" );
        m_haveLoadedImage = true;

        m_currentImageData = PalettizedImage.LoadImage( _path, m_currentImageConfig );
        if( m_currentImageData != null )
        {
            //
            m_currentImageConfig.SetImage( m_currentImageData );

            //
            m_currentFramesString = m_currentImageConfig.GetNumFrames().ToString();
            m_currentFrameTimesString = new Dictionary<int, string>();
            int iFrame;
            for( iFrame=0; iFrame<m_currentImageConfig.GetNumFrames(); iFrame++ )
            {
                m_currentFrameTimesString[ iFrame ] = m_currentImageConfig.GetFrameTime( iFrame ).ToString();
            }

            //
            m_openImageName = System.IO.Path.GetFileNameWithoutExtension( _path );
            m_tileBankWindowRect = new Rect( m_projectWindowWidth + (m_windowPadding*2.0f), m_windowTop, m_currentImageData.m_width*2.0f+10.0f, m_currentImageData.m_height*2.0f+10.0f+15.0f );
            m_imageSettingsRect = new Rect( m_tileBankWindowRect.x + m_tileBankWindowRect.width + m_windowPadding, m_tileBankWindowRect.y, 200.0f, 200.0f );
            m_paletteRemapRect = new Rect( m_imageSettingsRect.x + m_imageSettingsRect.width + m_windowPadding, m_imageSettingsRect.y, 100.0f, 15.0f + (16.0f * 30.0f) );

            //
        //			m_planarImage = new PlanarImage( m_currentImageData);
            bool OptimizedTilebank = (m_currentImageConfig.m_importAsSprite == false); // If we import the image as a sprite we should not optimize the tile bank
            m_tileBank = new TileBank( m_currentImageData, OptimizedTilebank );
            m_tileMap = new TileMap( m_tileBank, m_currentImageData );
            m_tilePalette = new TilePalette( m_currentImageData );

            //
            int w, h;
            w = m_currentImageData.m_width;
            h = m_currentImageData.m_height;

            //
            m_imageTexture = new Texture2D( w, h, TextureFormat.ARGB32, false );
            m_imageTexture.filterMode = FilterMode.Point;

            //
            int x, y;
            for( y=0; y<h; y++ )
            {
                for( x=0; x<w; x++ )
                {
                    int ii = ((h-1-y)*w)+x;
                    int ic = m_currentImageData.m_image[ ii ];
                    Color col = m_currentImageData.m_palette[ ic ];
                    m_imageTexture.SetPixel( x, y, col );
                }
            }

            //
            m_imageTexture.Apply();
        }
    }
Example #11
0
    //
    void ExportAll()
    {
        //
        string outFileName = EditorUtility.SaveFilePanel( "Select folder to export to", m_lastExportDirectory, "filenameignored", "bin" );

        //
        m_lastExportDirectory = System.IO.Path.GetDirectoryName( outFileName );
        SaveLastExportDirectory();

        m_project.Export( m_lastExportDirectory );

        //
        // Export all images
        //
        string[] imageFiles = m_project.m_imageFiles;
        foreach( string imageFile in imageFiles )
        {
            Debug.Log( "Exporting file '" + imageFile + "'" );

            string outFileNameNoExt = System.IO.Path.GetFileNameWithoutExtension( imageFile ).ToLower();
            string outBaseName = m_lastExportDirectory + System.IO.Path.DirectorySeparatorChar + outFileNameNoExt;

            //
            PalettizedImageConfig imageConfig = new PalettizedImageConfig( imageFile + ".config" );
            PalettizedImage imageData = PalettizedImage.LoadImage( imageFile, imageConfig );

            //
            if( imageData != null )
            {
                //
                imageConfig.SetImage( imageData );

                // Convert to tile banks / planar images
        //				PlanarImage planarImage = new PlanarImage( imageData);
                TileBank tileBank = new TileBank( imageData, (imageConfig.m_importAsSprite==false) );
                TilePalette tilePalette = new TilePalette( imageData );

                // Export it
                if( imageConfig.m_importAsSprite )
                {
                    Sprite sprite = new Sprite( imageConfig );
                    string alternativeAmigaSpriteName;
                    if( imageConfig.m_importAsBSprite )
                    {
                        AmigaSprite amigaSprite = new AmigaSprite( imageData, imageConfig);
                        alternativeAmigaSpriteName = "_sprite_bank_amiga_b_hw.bin";
                        amigaSprite.Export( outBaseName + alternativeAmigaSpriteName );
                    }
                    else
                    {
                        AmigaBob amigaBob = new AmigaBob( imageData, imageConfig);
                        alternativeAmigaSpriteName = "_sprite_bank_amiga_a_bob.bin";
                        amigaBob.Export( outBaseName + alternativeAmigaSpriteName );
                    }
                    tileBank.ExportMegaDrive( outBaseName + "_sprite_bank.bin" );
                    tilePalette.Export( outBaseName + "_palette.bin" );
                    sprite.Export( outBaseName + "_sprite.bin" );
                }
                else
                {
                    TileMap tileMap = new TileMap( tileBank, imageData );

                    tileBank.ExportMegaDrive( outBaseName + "_bank.bin" );
                    tileBank.ExportAmiga( outBaseName + "_bank_amiga.bin" );
                    tileMap.Export( outBaseName + "_map.bin" );
                    tilePalette.Export( outBaseName + "_palette.bin" );
                }
            }
        }

        //
        // Export all maps
        //
        string[] mapFiles = m_project.m_mapFiles;
        foreach( string mapFile in mapFiles )
        {
            Debug.Log( "Exporting map '" + mapFile + "'" );

            string outFileNameNoExt = System.IO.Path.GetFileNameWithoutExtension( mapFile ).ToLower();
            string outBaseName = m_lastExportDirectory + System.IO.Path.DirectorySeparatorChar + outFileNameNoExt;

            //
            TileMap tileMap = TileMap.LoadJson( mapFile );
            CollisionMap collisionmap = new CollisionMap( tileMap );

            tileMap.Export( outBaseName + "_map.bin" );
            collisionmap.Export( outBaseName  + "_collisionmap.bin" );
        }

        //
        // Export all game objects
        //
        foreach( string goFile in m_project.m_gameObjectCollectionFiles )
        {
            Debug.Log( "Exporting game object '" + goFile + "'" );

            string outFileNameNoExt = m_project.GetOutFileNameNoExt( goFile );
            string outBaseName = m_lastExportDirectory + System.IO.Path.DirectorySeparatorChar;

            GameObjectCollection ggo = new GameObjectCollection(  goFile );
            ggo.Export( outBaseName + m_project.GetGreatGameObjectName( goFile ), m_project );
        }

        Debug.Log("Export is finished!");
    }
Example #12
0
    //
    void ExportAll()
    {
        //
        string outFileName = EditorUtility.SaveFilePanel("Select folder to export to", m_lastExportDirectory, "filenameignored", "bin");

        //
        m_lastExportDirectory = System.IO.Path.GetDirectoryName(outFileName);
        SaveLastExportDirectory();

        m_project.Export(m_lastExportDirectory);

        //
        // Export all images
        //
        string[] imageFiles = m_project.m_imageFiles;
        foreach (string imageFile in imageFiles)
        {
            Debug.Log("Exporting file '" + imageFile + "'");

            string outFileNameNoExt = System.IO.Path.GetFileNameWithoutExtension(imageFile).ToLower();
            string outBaseName      = m_lastExportDirectory + System.IO.Path.DirectorySeparatorChar + outFileNameNoExt;

            //
            PalettizedImageConfig imageConfig = new PalettizedImageConfig(imageFile + ".config");
            PalettizedImage       imageData   = PalettizedImage.LoadImage(imageFile, imageConfig);

            //
            if (imageData != null)
            {
                //
                imageConfig.SetImage(imageData);

                // Convert to tile banks / planar images
//				PlanarImage planarImage = new PlanarImage( imageData);
                TileBank    tileBank    = new TileBank(imageData, (imageConfig.m_importAsSprite == false));
                TilePalette tilePalette = new TilePalette(imageData);

                // Export it
                if (imageConfig.m_importAsSprite)
                {
                    Sprite sprite = new Sprite(imageConfig);
                    string alternativeAmigaSpriteName;
                    if (imageConfig.m_importAsBSprite)
                    {
                        AmigaSprite amigaSprite = new AmigaSprite(imageData, imageConfig);
                        alternativeAmigaSpriteName = "_sprite_bank_amiga_b_hw.bin";
                        amigaSprite.Export(outBaseName + alternativeAmigaSpriteName);
                    }
                    else
                    {
                        AmigaBob amigaBob = new AmigaBob(imageData, imageConfig);
                        alternativeAmigaSpriteName = "_sprite_bank_amiga_a_bob.bin";
                        amigaBob.Export(outBaseName + alternativeAmigaSpriteName);
                    }
                    tileBank.ExportMegaDrive(outBaseName + "_sprite_bank.bin");
                    tilePalette.Export(outBaseName + "_palette.bin");
                    sprite.Export(outBaseName + "_sprite.bin");
                }
                else
                {
                    TileMap tileMap = new TileMap(tileBank, imageData);

                    tileBank.ExportMegaDrive(outBaseName + "_bank.bin");
                    tileBank.ExportAmiga(outBaseName + "_bank_amiga.bin");
                    tileMap.Export(outBaseName + "_map.bin");
                    tilePalette.Export(outBaseName + "_palette.bin");
                }
            }
        }

        //
        // Export all maps
        //
        string[] mapFiles = m_project.m_mapFiles;
        foreach (string mapFile in mapFiles)
        {
            Debug.Log("Exporting map '" + mapFile + "'");

            string outFileNameNoExt = System.IO.Path.GetFileNameWithoutExtension(mapFile).ToLower();
            string outBaseName      = m_lastExportDirectory + System.IO.Path.DirectorySeparatorChar + outFileNameNoExt;

            //
            TileMap      tileMap      = TileMap.LoadJson(mapFile);
            CollisionMap collisionmap = new CollisionMap(tileMap);

            tileMap.Export(outBaseName + "_map.bin");
            collisionmap.Export(outBaseName + "_collisionmap.bin");
        }

        //
        // Export all game objects
        //
        foreach (string goFile in m_project.m_gameObjectCollectionFiles)
        {
            Debug.Log("Exporting game object '" + goFile + "'");

            string outFileNameNoExt = m_project.GetOutFileNameNoExt(goFile);
            string outBaseName      = m_lastExportDirectory + System.IO.Path.DirectorySeparatorChar;

            GameObjectCollection ggo = new GameObjectCollection(goFile);
            ggo.Export(outBaseName + m_project.GetGreatGameObjectName(goFile), m_project);
        }

        Debug.Log("Export is finished!");
    }
Example #13
0
    void LoadBMP(string _path)
    {
        m_openImageName = "<Untitled>";

        // Load corresponding config first as it have information on how the image should be loaded
        m_currentImageConfig = new PalettizedImageConfig(_path + ".config");
        m_haveLoadedImage    = true;

        m_currentImageData = PalettizedImage.LoadImage(_path, m_currentImageConfig);
        if (m_currentImageData != null)
        {
            //
            m_currentImageConfig.SetImage(m_currentImageData);

            //
            m_currentFramesString     = m_currentImageConfig.GetNumFrames().ToString();
            m_currentFrameTimesString = new Dictionary <int, string>();
            int iFrame;
            for (iFrame = 0; iFrame < m_currentImageConfig.GetNumFrames(); iFrame++)
            {
                m_currentFrameTimesString[iFrame] = m_currentImageConfig.GetFrameTime(iFrame).ToString();
            }

            //
            m_openImageName      = System.IO.Path.GetFileNameWithoutExtension(_path);
            m_tileBankWindowRect = new Rect(m_projectWindowWidth + (m_windowPadding * 2.0f), m_windowTop, m_currentImageData.m_width * 2.0f + 10.0f, m_currentImageData.m_height * 2.0f + 10.0f + 15.0f);
            m_imageSettingsRect  = new Rect(m_tileBankWindowRect.x + m_tileBankWindowRect.width + m_windowPadding, m_tileBankWindowRect.y, 200.0f, 200.0f);
            m_paletteRemapRect   = new Rect(m_imageSettingsRect.x + m_imageSettingsRect.width + m_windowPadding, m_imageSettingsRect.y, 100.0f, 15.0f + (16.0f * 30.0f));

            //
//			m_planarImage = new PlanarImage( m_currentImageData);
            bool OptimizedTilebank = (m_currentImageConfig.m_importAsSprite == false);             // If we import the image as a sprite we should not optimize the tile bank
            m_tileBank    = new TileBank(m_currentImageData, OptimizedTilebank);
            m_tileMap     = new TileMap(m_tileBank, m_currentImageData);
            m_tilePalette = new TilePalette(m_currentImageData);

            //
            int w, h;
            w = m_currentImageData.m_width;
            h = m_currentImageData.m_height;

            //
            m_imageTexture            = new Texture2D(w, h, TextureFormat.ARGB32, false);
            m_imageTexture.filterMode = FilterMode.Point;

            //
            int x, y;
            for (y = 0; y < h; y++)
            {
                for (x = 0; x < w; x++)
                {
                    int   ii  = ((h - 1 - y) * w) + x;
                    int   ic  = m_currentImageData.m_image[ii];
                    Color col = m_currentImageData.m_palette[ic];
                    m_imageTexture.SetPixel(x, y, col);
                }
            }

            //
            m_imageTexture.Apply();
        }
    }
Example #14
0
    void OnGUI()
    {
        GUILayout.Label("Here are Yo Banks", EditorStyles.boldLabel);

        float originalWidthOccupied = 5f;
        float widthOccupied         = originalWidthOccupied;
        float widthOfTile           = 32f;

        float originalHeightOccupied = 24;
        float heightOccupied         = originalHeightOccupied;
        float heightOfTile           = 32f;

        Vector2 padding = new Vector2(2, 2);

        if (tileBank != null)
        {
            float foldoutWidth  = position.width;
            float foldoutHeight = 16;

            showTileBank = EditorGUI.Foldout(new Rect(widthOccupied, heightOccupied, foldoutWidth, foldoutHeight), showTileBank, tileBank.name);

            widthOccupied   = originalWidthOccupied = widthOccupied + 15f;
            heightOccupied += foldoutHeight + padding.y;

            if (showTileBank)
            {
                foreach (GameObject obj in tileBank.tiles)
                {
                    if (obj == null)
                    {
                        continue;
                    }

                    SpriteRenderer spriteRenderer = obj.GetComponent <SpriteRenderer>();

                    if (spriteRenderer != null)
                    {
                        DrawTextureGUI(new Vector2(widthOccupied, heightOccupied),
                                       spriteRenderer.sprite,
                                       new Vector2(widthOfTile, heightOfTile));

                        widthOccupied += widthOfTile + padding.x;

                        if (widthOccupied + widthOfTile + padding.x > position.width)
                        {
                            heightOccupied += heightOfTile + padding.y;
                            widthOccupied   = originalWidthOccupied;
                        }
                    }
                }
            }
        }

        GUILayout.Space(heightOccupied);

        GUILayout.FlexibleSpace();

        tileBank = (TileBank)EditorGUILayout.ObjectField(tileBank,
                                                         typeof(TileBank),
                                                         false,
                                                         GUILayout.MaxWidth(200f));

        GUILayout.Space(10f);

        if (GUILayout.Button("Create new Tile Bank", GUILayout.ExpandWidth(false)))
        {
            ScriptableObjectUtility.CreateAsset <TileBank>();
        }

        /*
         * groupEnabled = EditorGUILayout.BeginToggleGroup ("Optional Settings", groupEnabled);
         * myBool = EditorGUILayout.Toggle ("Toggle", myBool);
         * myFloat = EditorGUILayout.Slider ("Slider", myFloat, -3, 3);
         * EditorGUILayout.EndToggleGroup ();
         */
    }
Example #15
0
    public static TileMap LoadJson( string _fileName )
    {
        string jsonString = System.IO.File.ReadAllText( _fileName );
        Dictionary<string,object> json = (Dictionary<string,object>)MiniJSON.Json.Deserialize( jsonString );

        // Load tile bank
        List<object> tilesetsJson = (List<object>)json[ "tilesets" ];
        Dictionary<string,object> tilesetJson = (Dictionary<string,object>)tilesetsJson[ 0 ];
        string imageFileName = (string)tilesetJson[ "image" ];
        string imageFullPath = System.IO.Path.GetDirectoryName( _fileName ) + System.IO.Path.DirectorySeparatorChar + imageFileName;
        //LoadBMP( imageFullPath );

        PalettizedImageConfig imageConfig  = new PalettizedImageConfig( imageFullPath + ".config" );

        PalettizedImage imageData = PalettizedImage.LoadImage( imageFullPath, imageConfig );
        TileBank tileBank = null;
        if( imageData != null )
        {
            //
            imageConfig.SetImage( imageData );

            bool optimizeBank = (imageConfig.m_importAsSprite==false);	// Optimize bank when we're not loading the image as a sprite (i.e. optimize when we're loading as a tile bank)
            tileBank = new TileBank( imageData, optimizeBank );
        }

        // Create map texture
        int map_tiles_w = ((int)(long)json[ "width" ]);
        int map_tiles_h = ((int)(long)json[ "height" ]);
        int map_pixels_w = map_tiles_w * 8;
        int map_pixels_h = map_tiles_h * 8;

        TileMap ret = new TileMap( map_tiles_w, map_tiles_h );

        // Find each layer
        List<object> layersJson = (List<object>)json[ "layers" ];
        Dictionary<string,object> layerJson = (Dictionary<string,object>)layersJson[ 0 ];
        List<object> layerData = (List<object>)layerJson[ "data" ];
        int tile_x, tile_y;
        for( tile_y=0; tile_y<map_tiles_h; tile_y++ )
        {
            for( tile_x=0; tile_x<map_tiles_w; tile_x++ )
            {
                int i = tile_y*map_tiles_w + tile_x;
                int tile_id = (int)(long)layerData[i];
                tile_id--;
                TileInstance tileInstance = tileBank.m_allTileInstances[ tile_id ];

                //
                ret.SetRawTile( tile_x, tile_y, tile_id );
                ret.SetTile( tile_x, tile_y, tileInstance );
            }
        }

        return ret;
    }