Пример #1
0
        public T LoadFromProject <T>(string assetName)
        {
            string oldRelativePath = FileManager.RelativeDirectory;

            FlatRedBall.IO.FileManager.RelativeDirectory = FileManager.GetDirectory(assetName);



        #if DEBUG
            bool shouldCheckForXnb = true;

                #if ANDROID
            if (typeof(T) == typeof(Song))
            {
                shouldCheckForXnb = false;
            }
                #endif


            string fileToCheckFor = assetName + ".xnb";


            if (shouldCheckForXnb && !FileManager.FileExists(fileToCheckFor))
            {
                string errorString = "Could not find the file " + fileToCheckFor + "\n";

        #if !WINDOWS_8
                List <string> filesInDirectory = FileManager.GetAllFilesInDirectory(FileManager.GetDirectory(assetName), null, 0);

                errorString += "Found the following files:\n\n";

                foreach (string s in filesInDirectory)
                {
                    errorString += FileManager.RemovePath(s) + "\n";
                }
        #endif
                throw new FileNotFoundException(errorString);
            }
        #endif

        #if XNA4 && !MONOGAME
            if (!FileManager.IsRelative(assetName))
            {
                assetName = FileManager.MakeRelative(
                    assetName, System.Windows.Forms.Application.StartupPath + "/");
            }
        #endif

        #if USES_DOT_SLASH_ABOLUTE_FILES
            T asset;

            if (assetName.StartsWith(@".\") || assetName.StartsWith(@"./"))
            {
                asset = base.Load <T>(assetName.Substring(2));
            }
            else
            {
                asset = base.Load <T>(assetName);
            }
        #else
            T asset = base.Load <T>(assetName);
        #endif
            if (!mAssets.ContainsKey(assetName))
            {
                mAssets.Add(assetName, asset);
            }

            FileManager.RelativeDirectory = oldRelativePath;

            return(AdjustNewAsset(asset, assetName));
        }
Пример #2
0
        private void MakeAssetsRelative(string fileName)
        {
            string oldRelativeDirectory = FileManager.RelativeDirectory;

            if (FileManager.IsRelative(fileName))
            {
                fileName = FileManager.MakeAbsolute(fileName);
            }
            FileManager.RelativeDirectory = FileManager.GetDirectory(fileName);


            #region SpriteSave - Make textures relative
            foreach (SpriteSave ss in SpriteList)
            {
                ss.MakeRelative();
            }
            #endregion


            #region SpriteFrameSave - Make the textures relative

            foreach (SpriteFrameSave sfs in SpriteFrameSaveList)
            {
                sfs.ParentSprite.Texture = FileManager.MakeRelative(sfs.ParentSprite.Texture);

                if (string.IsNullOrEmpty(sfs.ParentSprite.AnimationChainsFile) == false)
                {
                    sfs.ParentSprite.AnimationChainsFile =
                        FileManager.MakeRelative(sfs.ParentSprite.AnimationChainsFile);
                }
            }

            #endregion


            #region SpriteGridSave - Make textures realtive
            foreach (SpriteGridSave sgs in SpriteGridList)
            {
                sgs.BaseTexture       = FileManager.MakeRelative(sgs.BaseTexture);
                sgs.Blueprint.Texture = FileManager.MakeRelative(sgs.Blueprint.Texture);
                foreach (string[] row in sgs.GridTexturesArray)
                {
                    for (int i = 0; i < row.Length; i++)
                    {
                        row[i] = FileManager.MakeRelative(row[i]);
                    }
                }

                if (sgs.AnimationChainGridSave != null)
                {
                    sgs.AnimationChainGridSave.MakeRelative();
                }
            }
            #endregion

            #region TextSaves - Make textures and .fnt files relative

            foreach (TextSave textSave in TextSaveList)
            {
                textSave.FontTexture = FileManager.MakeRelative(textSave.FontTexture);
                textSave.FontFile    = FileManager.MakeRelative(textSave.FontFile);
            }

            #endregion

            FileManager.RelativeDirectory = oldRelativeDirectory;
        }