Exemplo n.º 1
0
 /// <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;
 }
Exemplo n.º 2
0
 private static Dictionary<string, Texture2D> getDict(CacheKeep cache)
 {
     switch (cache)
     {
         case CacheKeep.Intern:
             return internalRes;
         case CacheKeep.Extern:
             return externalRes;
         case CacheKeep.Temp:
         default:
             return tempRes;
     }
 }
Exemplo n.º 3
0
 private static void saveCache(string name, Texture2D t, CacheKeep cache)
 {
     if (t == null)
     {
         return;
     }
     getDict(cache).Add(name, t);
 }
Exemplo n.º 4
0
 private static Texture2D getCache(string name, CacheKeep cache)
 {
     Texture2D t = null;
     if (getDict(cache).TryGetValue(name, out t))
     {
         return t;
     }
     return null;
 }