Esempio n. 1
0
 public static LoadedContentItem <T> LoadItem(VirtualFile file)
 {
     try
     {
         if (typeof(T) == typeof(string))
         {
             return(new LoadedContentItem <T>(file, (T)(object)file.ReadAllText()));
         }
         if (typeof(T) == typeof(Texture2D))
         {
             return(new LoadedContentItem <T>(file, (T)(object)LoadTexture(file)));
         }
         if (typeof(T) == typeof(AudioClip))
         {
             if (Prefs.LogVerbose)
             {
                 DeepProfiler.Start("Loading file " + file);
             }
             IDisposable extraDisposable = null;
             T           val;
             try
             {
                 bool   doStream = ShouldStreamAudioClipFromFile(file);
                 Stream stream   = file.CreateReadStream();
                 try
                 {
                     val = (T)(object)RuntimeAudioClipLoader.Manager.Load(stream, GetFormat(file.Name), file.Name, doStream);
                 }
                 catch (Exception)
                 {
                     stream.Dispose();
                     throw;
                 }
                 extraDisposable = stream;
             }
             finally
             {
                 if (Prefs.LogVerbose)
                 {
                     DeepProfiler.End();
                 }
             }
             UnityEngine.Object @object = val as UnityEngine.Object;
             if (@object != null)
             {
                 @object.name = Path.GetFileNameWithoutExtension(file.Name);
             }
             return(new LoadedContentItem <T>(file, val, extraDisposable));
         }
     }
     catch (Exception ex2)
     {
         Log.Error("Exception loading " + typeof(T) + " from file.\nabsFilePath: " + file.FullPath + "\nException: " + ex2.ToString());
     }
     if (typeof(T) == typeof(Texture2D))
     {
         return((LoadedContentItem <T>)(object) new LoadedContentItem <Texture2D>(file, BaseContent.BadTex));
     }
     return(null);
 }