예제 #1
0
        public static IEnumerable <LoadedContentItem <T> > LoadAllForMod(ModContentPack mod)
        {
            string        contentDirPath = Path.Combine(mod.RootDir, GenFilePaths.ContentPath <T>());
            DirectoryInfo contentDir     = new DirectoryInfo(contentDirPath);

            if (contentDir.Exists)
            {
                DeepProfiler.Start("Loading assets of type " + typeof(T) + " for mod " + mod);
                FileInfo[] files = contentDir.GetFiles("*.*", SearchOption.AllDirectories);
                foreach (FileInfo file in files)
                {
                    if (IsAcceptableExtension(file.Extension))
                    {
                        LoadedContentItem <T> loadedItem = LoadItem(file.FullName, contentDirPath);
                        if (loadedItem != null)
                        {
                            yield return(loadedItem);

                            /*Error: Unable to find new state assignment for yield return*/;
                        }
                    }
                }
                DeepProfiler.End();
            }
        }
예제 #2
0
        public static IEnumerable <LoadedContentItem <T> > LoadAllForMod(ModContentPack mod)
        {
            string        contentDirPath = Path.Combine(mod.RootDir, GenFilePaths.ContentPath <T>());
            DirectoryInfo contentDir     = new DirectoryInfo(contentDirPath);

            if (contentDir.Exists)
            {
                DeepProfiler.Start(string.Concat(new object[]
                {
                    "Loading assets of type ",
                    typeof(T),
                    " for mod ",
                    mod
                }));
                FileInfo[] files = contentDir.GetFiles("*.*", SearchOption.AllDirectories);
                for (int i = 0; i < files.Length; i++)
                {
                    FileInfo file = files[i];
                    if (ModContentLoader <T> .IsAcceptableExtension(file.Extension))
                    {
                        LoadedContentItem <T> loadedItem = ModContentLoader <T> .LoadItem(file.FullName, contentDirPath);

                        if (loadedItem != null)
                        {
                            yield return(loadedItem);
                        }
                    }
                }
                DeepProfiler.End();
            }
        }
예제 #3
0
        public static IEnumerable <Pair <string, LoadedContentItem <T> > > LoadAllForMod(ModContentPack mod)
        {
            DeepProfiler.Start(string.Concat("Loading assets of type ", typeof(T), " for mod ", mod));
            Dictionary <string, FileInfo> allFilesForMod = ModContentPack.GetAllFilesForMod(mod, GenFilePaths.ContentPath <T>(), IsAcceptableExtension);

            foreach (KeyValuePair <string, FileInfo> item in allFilesForMod)
            {
                LoadedContentItem <T> loadedContentItem = LoadItem((FilesystemFile)item.Value);
                if (loadedContentItem != null)
                {
                    yield return(new Pair <string, LoadedContentItem <T> >(item.Key, loadedContentItem));
                }
            }
            DeepProfiler.End();
        }
예제 #4
0
        public static LoadedContentItem <T> LoadItem(string absFilePath, string contentDirPath = null)
        {
            string text = absFilePath;

            if (contentDirPath != null)
            {
                text = text.Substring(contentDirPath.ToString().Length);
            }
            text = text.Substring(0, text.Length - Path.GetExtension(text).Length);
            text = text.Replace('\\', '/');
            try
            {
                if (typeof(T) == typeof(string))
                {
                    LoadedContentItem <T> result = new LoadedContentItem <T>(text, (T)((object)GenFile.TextFromRawFile(absFilePath)));
                    return(result);
                }
                if (typeof(T) == typeof(Texture2D))
                {
                    LoadedContentItem <T> result = new LoadedContentItem <T>(text, (T)((object)ModContentLoader <T> .LoadPNG(absFilePath)));
                    return(result);
                }
                if (typeof(T) == typeof(AudioClip))
                {
                    if (Prefs.LogVerbose)
                    {
                        DeepProfiler.Start("Loading file " + text);
                    }
                    T t;
                    try
                    {
                        bool doStream = ModContentLoader <T> .ShouldStreamAudioClipFromPath(absFilePath);

                        t = (T)((object)Manager.Load(absFilePath, doStream, true, true));
                    }
                    finally
                    {
                        if (Prefs.LogVerbose)
                        {
                            DeepProfiler.End();
                        }
                    }
                    UnityEngine.Object @object = t as UnityEngine.Object;
                    if (@object != null)
                    {
                        @object.name = Path.GetFileNameWithoutExtension(new FileInfo(absFilePath).Name);
                    }
                    LoadedContentItem <T> result = new LoadedContentItem <T>(text, t);
                    return(result);
                }
            }
            catch (Exception ex)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Exception loading ",
                    typeof(T),
                    " from file.\nabsFilePath: ",
                    absFilePath,
                    "\ncontentDirPath: ",
                    contentDirPath,
                    "\nException: ",
                    ex.ToString()
                }), false);
            }
            if (typeof(T) == typeof(Texture2D))
            {
                return((LoadedContentItem <T>) new LoadedContentItem <Texture2D>(absFilePath, BaseContent.BadTex));
            }
            return(null);
        }