public void BuildFromFile(string path, int index, float uvTime, Texture mainTex)
        {
            if (!File.Exists(path))
            {
                Debug.LogError("wrong ean file path!");
                return;
            }
            FileStream   fs  = new FileStream(path, FileMode.Open);
            BinaryReader br  = new BinaryReader(fs);
            EanFile      ean = new EanFile();

            ean.Load(br, fs);
            fs.Close();
            EanAnimation eanim = ean.Anims[index];

            frames       = new Vector2[eanim.TotalCount];
            UVDimensions = new Vector2[eanim.TotalCount];
            int cols      = eanim.TileCount;
            int rows      = (eanim.TotalCount + cols - 1) / cols;
            int cellCount = 0;


            int tWidth  = mainTex.width;
            int tHeight = mainTex.height;

            //Vector2 Oft = new Vector2((float)eanim.MipWidth / tWidth, (float)eanim.MipHeight / tHeight);

            for (int row = 0; row < rows; ++row)
            {
                for (int col = 0; col < cols && cellCount < eanim.TotalCount; ++col)
                {
                    Vector2 cellSize = Vector2.zero;
                    cellSize.x                = (float)eanim.Frames[cellCount].Width / tWidth;
                    cellSize.y                = (float)eanim.Frames[cellCount].Height / tHeight;
                    frames[cellCount].x       = (float)eanim.Frames[cellCount].X / tWidth;
                    frames[cellCount].y       = 1f - (float)eanim.Frames[cellCount].Y / tHeight;
                    UVDimensions[cellCount]   = cellSize;
                    UVDimensions[cellCount].y = -UVDimensions[cellCount].y;
                    ++cellCount;
                }
            }
        }
Beispiel #2
0
        public void BuildFromFile(string path, int index, float uvTime, Texture mainTex)
        {
            if (!File.Exists(path))
            {
                Debug.LogError("wrong ean file path!");
                return;
            }
            FileStream fs = new FileStream(path, FileMode.Open);
            BinaryReader br = new BinaryReader(fs);
            EanFile ean = new EanFile();
            ean.Load(br, fs);
            fs.Close();
            EanAnimation eanim = ean.Anims[index];
            frames = new Vector2[eanim.TotalCount];
            UVDimensions = new Vector2[eanim.TotalCount];
            int cols = eanim.TileCount;
            int rows = (eanim.TotalCount + cols - 1) / cols;
            int cellCount = 0;


            int tWidth = mainTex.width;
            int tHeight = mainTex.height;

            //Vector2 Oft = new Vector2((float)eanim.MipWidth / tWidth, (float)eanim.MipHeight / tHeight);

            for (int row = 0; row < rows; ++row)
            {
                for (int col = 0; col < cols && cellCount < eanim.TotalCount; ++col)
                {
                    Vector2 cellSize = Vector2.zero;
                    cellSize.x = (float)eanim.Frames[cellCount].Width / tWidth;
                    cellSize.y = (float)eanim.Frames[cellCount].Height / tHeight;
                    frames[cellCount].x = (float)eanim.Frames[cellCount].X / tWidth;
                    frames[cellCount].y = 1f - (float)eanim.Frames[cellCount].Y / tHeight;
                    UVDimensions[cellCount] = cellSize;
                    UVDimensions[cellCount].y = -UVDimensions[cellCount].y;
                    ++cellCount;
                }
            }
        }