Пример #1
0
        public void LoadTextFile(string fileName, FileType fileType, Action <string> callback = null)
        {
            if (!ResourceMap.Instance.IsAssetLoaded(fileName))
            {
                ResourceMap.Instance.AsyncLoadRequested(fileName);

                try
                {
                    using (StreamReader sr = new StreamReader(fileName))
                    {
                        string fileContent = sr.ReadToEnd();
                        var    c           = GraphicsContext.CurrentContext;

                        if (fileType == FileType.TextFile)
                        {
                            TextAsset textAsset = new TextAsset(fileContent);
                            ResourceMap.Instance.AsyncLoadComleted(fileName, textAsset);
                            if (callback != null)
                            {
                                callback(fileName);
                            }
                        }
                        else if (fileType == FileType.XmlFile)
                        {
                            XmlDocument doc = new XmlDocument();

                            try
                            {
                                doc.LoadXml(fileContent);
                            }
                            catch (Exception e)
                            {
                                Logger.Instance.Print(
                                    "TextFileLoader.cs, Failed to open a file with the name: " +
                                    fileName + ". Message: " + e.Message);
                                return;
                            }

                            XmlAsset xmlAsset = new XmlAsset(doc);
                            ResourceMap.Instance.AsyncLoadComleted(fileName, xmlAsset);
                            if (callback != null)
                            {
                                callback(fileName);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Logger.Instance.Print("TextFleLoader.cs, LoadTextFile(). Message: " + e.Message);
                    return;
                }
            }
            else
            {
                ResourceMap.Instance.IncAssetRefCount(fileName);
            }
        }
Пример #2
0
        private void StoreLoadedFont(string fontInfoSourceString)
        {
            string         fontName       = fontInfoSourceString.Replace(".fnt", "");
            XmlAsset       xmlAsset       = ResourceMap.Instance.RetrieveAsset(fontInfoSourceString) as XmlAsset;
            CharacterInfo  characterInfo  = new CharacterInfo();
            CharacterAsset characterAsset = new CharacterAsset(characterInfo, xmlAsset);

            characterAsset.FontImageName = fontName + ".png";
            ResourceMap.Instance.AsyncLoadComleted(fontName, characterAsset);
        }