コード例 #1
0
ファイル: GraphicManager.cs プロジェクト: safawu/project2006
 /// <summary>
 /// 获取图片
 /// from和cache分开的逻辑可以实现加载本地文件但保存到内核cache
 /// 或者加载dll文件但放到临时cache
 /// 但是当不写明cache时,会根据from来对应出一个默认cache
 /// </summary>
 /// <param name="name"></param>
 /// <param name="from">来源</param>
 /// <param name="cache">保存到什么地方</param>
 /// <returns></returns>
 internal static Texture2D GetImage(string name, GraphicsFrom from, CacheKeep cache)
 {
     if (name == "")
     {
         return null;
     }
     Texture2D t = null;
     //任意目录
     if ((from & GraphicsFrom.Other) > 0)
     {
         t = getCache(name, cache);
         if (t != null)
             return t;
         t = Texture2D.FromStream(GameMain.Instance.Device, RWExternal.GetFileStream(name));
         if (t != null)
         {
             saveCache(name, t, cache);
             return t;
         }
         return null; //对于other,不要执行后续逻辑
     }
     //data目录
     if ((from & GraphicsFrom.File) > 0)
     {
         string localName = "data\\" + name;
         t = getCache(localName, cache);
         if (t != null)
             return t;
         t = Texture2D.FromStream(GameMain.Instance.Device, RWExternal.GetFileStream(localName));
         if (t != null)
         {
             saveCache(name, t, cache);
             return t;
         }
     }
     if ((from & GraphicsFrom.Own) > 0)
     {
         t = getCache(name, cache);
         if (t != null)
             return t;
         t = Texture2D.FromStream(GameMain.Instance.Device, mainDll.GetStream(name));
         if (t != null)
         {
             saveCache(name, t, cache);
             return t;
         }
     }
     return null;
 }
コード例 #2
0
ファイル: GraphicManager.cs プロジェクト: safawu/project2006
 internal static Texture2D GetImage(string name,GraphicsFrom from)
 {
     CacheKeep cache;
     switch (from)
     {
         case GraphicsFrom.Own:
             cache = CacheKeep.Intern;
             break;
         case GraphicsFrom.File:
             cache = CacheKeep.Extern;
             break;
         case GraphicsFrom.Other:
         default:
             cache = CacheKeep.Temp;
             break;
     }
     return GetImage(name, from, cache);
 }