Ejemplo n.º 1
0
        private static MyTextureAtlas LoadTextureAtlas(string textureDir, string atlasFile)
        {
            MyTextureAtlas atlas = new MyTextureAtlas(0x40);

            using (Stream stream = MyFileSystem.OpenRead(Path.Combine(MyFileSystem.ContentPath, atlasFile)))
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    while (!reader.EndOfStream)
                    {
                        string str = reader.ReadLine();
                        if (!str.StartsWith("#"))
                        {
                            char[] trimChars = new char[] { ' ' };
                            if (str.Trim(trimChars).Length != 0)
                            {
                                string[]           strArray  = str.Split(new char[] { ' ', '\t', ',' }, StringSplitOptions.RemoveEmptyEntries);
                                string             str3      = strArray[1];
                                Vector4            uvOffsets = new Vector4(Convert.ToSingle(strArray[4], CultureInfo.InvariantCulture), Convert.ToSingle(strArray[5], CultureInfo.InvariantCulture), Convert.ToSingle(strArray[7], CultureInfo.InvariantCulture), Convert.ToSingle(strArray[8], CultureInfo.InvariantCulture));
                                MyTextureAtlasItem item      = new MyTextureAtlasItem(textureDir + str3, uvOffsets);
                                atlas.Add(strArray[0], item);
                            }
                        }
                    }
                }
            }
            return(atlas);
        }
Ejemplo n.º 2
0
        private static MyTextureAtlas LoadTextureAtlas(string textureDir, string atlasFile)
        {
            var fsPath = Path.Combine(MyFileSystem.ContentPath, atlasFile);

            if (!File.Exists(fsPath))
            {
                MyLog.Default.WriteLine("Warning: " + atlasFile + " not found.");
                return(null);
            }

            try
            {
                var atlas = new MyTextureAtlas(64);

                using (var file = MyFileSystem.OpenRead(fsPath))
                    using (StreamReader sr = new StreamReader(file))
                    {
                        while (!sr.EndOfStream)
                        {
                            string line = sr.ReadLine();

                            if (line.StartsWith("#"))
                            {
                                continue;
                            }
                            if (line.Trim(' ').Length == 0)
                            {
                                continue;
                            }

                            string[] parts = line.Split(new char[] { ' ', '\t', ',' }, StringSplitOptions.RemoveEmptyEntries);

                            string name      = parts[0];
                            string atlasName = parts[1];

                            Vector4 uv = new Vector4(
                                Convert.ToSingle(parts[4], System.Globalization.CultureInfo.InvariantCulture),
                                Convert.ToSingle(parts[5], System.Globalization.CultureInfo.InvariantCulture),
                                Convert.ToSingle(parts[7], System.Globalization.CultureInfo.InvariantCulture),
                                Convert.ToSingle(parts[8], System.Globalization.CultureInfo.InvariantCulture));

                            MyTexture2D        atlasTexture = MyTextureManager.GetTexture <MyTexture2D>(textureDir + atlasName);
                            MyTextureAtlasItem item         = new MyTextureAtlasItem(atlasTexture, uv);
                            atlas.Add(name, item);
                        }
                    }

                return(atlas);
            }
            catch (Exception e)
            {
                MyLog.Default.WriteLine("Warning: " + e.ToString());
            }

            return(null);
        }
        private static MyTextureAtlas LoadTextureAtlas(string textureDir, string atlasFile)
        {
            var atlas  = new MyTextureAtlas(64);
            var fsPath = Path.Combine(MyFileSystem.ContentPath, atlasFile);

            using (var stream = MyFileSystem.OpenRead(fsPath))
                using (StreamReader sr = new StreamReader(stream))
                {
                    while (!sr.EndOfStream)
                    {
                        string line = sr.ReadLine();

                        if (line.StartsWith("#"))
                        {
                            continue;
                        }
                        if (line.Trim(' ').Length == 0)
                        {
                            continue;
                        }

                        string[] parts = line.Split(new char[] { ' ', '\t', ',' }, StringSplitOptions.RemoveEmptyEntries);

                        string name = parts[0];

                        string atlasName = parts[1];

                        Vector4 uv = new Vector4(
                            Convert.ToSingle(parts[4], System.Globalization.CultureInfo.InvariantCulture),
                            Convert.ToSingle(parts[5], System.Globalization.CultureInfo.InvariantCulture),
                            Convert.ToSingle(parts[7], System.Globalization.CultureInfo.InvariantCulture),
                            Convert.ToSingle(parts[8], System.Globalization.CultureInfo.InvariantCulture));

                        string             atlasTexture = textureDir + atlasName;
                        MyTextureAtlasItem item         = new MyTextureAtlasItem(atlasTexture, uv);
                        atlas.Add(name, item);
                    }
                }

            return(atlas);
        }