/// <summary>
 /// 获取SpriteLoadHelper实例
 /// </summary>
 /// <returns>SpriteLoadHelper实例</returns>
 public static SpriteLoadHelper GetInstance()
 {
     if (instance == null)
     {
         instance = new SpriteLoadHelper();
     }
     return(instance);
 }
Exemple #2
0
        public static void InjectData()
        {
            if (!Main.enabled)
            {
                return;
            }

            try
            {
                if (Directory.Exists(Main.imgresdir))
                {
                    //遍历 Texture目录子目录
                    foreach (string path in Directory.GetDirectories(Main.imgresdir))
                    {
                        Main.Logger.Log("[Texture] Found subdir : " + path);
                        if (Directory.Exists(path))
                        {
                            SpriteLoadHelper.GetInstance().ProcessDir(path);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Main.Logger.Log(e.ToString() + "  " + e.Message);
                Main.Logger.Log(e.StackTrace);
            }

            try
            {
                // 处理其他MOD的替换请求
                foreach (var kv in Main.mods_sprite_dict)
                {
                    Main.Logger.Log("[Texture] Found Mod subdir : " + kv.Value);
                    if (Directory.Exists(kv.Value))
                    {
                        SpriteLoadHelper.GetInstance().ProcessDir(kv.Value);
                    }
                    else
                    {
                        Main.Logger.Log("[Texture] subdir not exsit : " + kv.Value);
                    }
                }
            }
            catch (Exception e)
            {
                Main.Logger.Log(e.Message);
                Main.Logger.Log(e.StackTrace);
            }
            // 释放资源
            SpriteLoadHelper.ClearInstance();
        }
Exemple #3
0
 private static void StartSaveSprites()
 {
     // 游戏载入成功后再允许导出,否则会造成游戏UI NullReferenceException
     if (!DateFile.instance.openGame)
     {
         GUILayout.Label("请先进入游戏主菜单即可保存......");
     }
     else
     {
         if (spriteCounter == 0)
         {
             if (GUILayout.Button("点击导出贴图(Sprites)", GUILayout.Width(150f)))
             {
                 try
                 {
                     // 删除备份目录中的文件并导出贴图
                     if (Directory.Exists(backupimgdir))
                     {
                         Directory.Delete(backupimgdir, true);
                     }
                     Directory.CreateDirectory(backupimgdir);
                     SpriteLoadHelper.GetInstance().DumpCommonSprite();
                     SpriteLoadHelper.GetInstance().DumpSpecialSprite();
                     SpriteLoadHelper.ClearInstance();
                 }
                 catch (Exception e)
                 {
                     Logger.Log($"保存Sprite:\n{e.ToString()}");
                 }
             }
         }
         else
         {
             GUILayout.Label("正在导出...", GUILayout.Width(150f));
         }
     }
 }
 /// <summary>
 /// 清除SpriteLoadHelper实例
 /// </summary>
 public static void ClearInstance() => instance = null;
Exemple #5
0
 /// <summary>
 /// 清除SpriteLoadHelper实例
 /// </summary>
 public static void ClearInstance()
 {
     instance?.spriteNamesCache.Clear();
     instance = null;
 }