示例#1
0
    public void Export(string _outfilename)
    {
        Debug.Log("Exporting sprite to " + _outfilename);

        int numFrames = m_imageConfig.GetNumFrames();

        int flags = 0x00;

        flags |= m_imageConfig.m_importAsBSprite ? 0x01 : 0x00;

        int outsize = 6 + numFrames;                    // 1 extra byte per frame, for the frame time

        byte[] outBytes = new byte[outsize];
        Halp.Write8(outBytes, 0, m_imageConfig.GetSpriteWidth());
        Halp.Write8(outBytes, 1, m_imageConfig.GetSpriteHeight());
        Halp.Write8(outBytes, 2, numFrames);
        Halp.Write8(outBytes, 3, flags);
        Halp.Write16(outBytes, 4, 0xdead);              // Put file handle here!

        int iFrame;

        for (iFrame = 0; iFrame < numFrames; iFrame++)
        {
            Halp.Write8(outBytes, 6 + iFrame, m_imageConfig.GetFrameTime(iFrame));
        }

        System.IO.File.WriteAllBytes(_outfilename, outBytes);
    }
示例#2
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();
        }
    }
示例#3
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();
        }
    }
示例#4
0
    void OnDrawImageSettings(int _id)
    {
        m_spriteFrameTimeScroll = GUILayout.BeginScrollView(m_spriteFrameTimeScroll);
        bool dirty = false;

        bool before = m_currentImageConfig.m_importAsSprite;

        m_currentImageConfig.m_importAsSprite = GUILayout.Toggle(before, "Import as sprite");
        if (m_currentImageConfig.m_importAsSprite != before)
        {
            dirty = true;
        }

        if (m_currentImageConfig.m_importAsSprite)
        {
            bool beforeB = m_currentImageConfig.m_importAsBSprite;
            m_currentImageConfig.m_importAsBSprite = GUILayout.Toggle(beforeB, "Import as B-sprite");
            if (m_currentImageConfig.m_importAsBSprite != beforeB)
            {
                dirty = true;
            }

            GUILayout.Label("Sprite w=" + m_currentImageConfig.GetSpriteWidth() + ", h=" + m_currentImageConfig.GetSpriteHeight());

            GUILayout.BeginHorizontal();
            GUILayout.Label("Num frames");
            string beforeString = m_currentFramesString;
            string newstring    = GUILayout.TextField(beforeString);
            GUILayout.EndHorizontal();
            m_currentFramesString = newstring;

            if (beforeString.CompareTo(newstring) != 0)
            {
                int newint;
                if (int.TryParse(newstring, out newint))
                {
                    m_currentImageConfig.SetNumFrames(newint);
                    dirty = true;
                }
            }

            GUILayout.Label("");
            GUILayout.Label("Frame times");

            int i;
            for (i = 0; i < m_currentImageConfig.GetNumFrames(); i++)
            {
                int time = m_currentImageConfig.GetFrameTime(i);

                GUILayout.BeginHorizontal();
                GUILayout.Label("Frame " + i + ":");
                if (m_currentFrameTimesString.ContainsKey(i) == false)
                {
                    m_currentFrameTimesString[i] = m_currentImageConfig.GetFrameTime(i).ToString();
                }
                beforeString = m_currentFrameTimesString[i];
                string newString = GUILayout.TextField(beforeString);;
                m_currentFrameTimesString[i] = newString;
                if (beforeString != newString)
                {
                    int newValue;
                    if (int.TryParse(newString, out newValue))
                    {
                        m_currentImageConfig.SetFrameTime(i, newValue);
                        dirty = true;
                    }
                }
                GUILayout.EndHorizontal();
            }

            GUILayout.Label("Hotspot");
            m_currentImageConfig.m_hotSpotX = EditorGUILayout.IntField("X:", m_currentImageConfig.m_hotSpotX);
            m_currentImageConfig.m_hotSpotY = EditorGUILayout.IntField("Y:", m_currentImageConfig.m_hotSpotY);
        }

        if (dirty)
        {
            m_currentImageConfig.Save();
        }
        GUI.DragWindow();

        GUILayout.EndScrollView();
    }