/*--------------------------------------------------------------------
- Author Name: DXL
- Creation Time: 2018.11.10
- File Describe: 删除存在本地的二级界面图片
- ------------------------------------------------------------------*/
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
using LogPrint;
public class DeleteLocalTexture
{
static string[] scenesName;
//删除缓存在本地的真实场景的图片资源,后台配置的假场景不会删除,删除假场景,请使用GM命令F3
[MenuItem("HideUIRaycast/DeleteMainHouseImage")]
public static void DeleteLocalSceneTexture()
{
int num = 0;
scenesName = System.Enum.GetNames(typeof(SceneType));
string localDir = Application.persistentDataPath;
if (Directory.Exists(localDir))
{
//获取本地缓存的所有文件
DirectoryInfo direction = new DirectoryInfo(localDir);
FileInfo[] files = direction.GetFiles("*", SearchOption.AllDirectories);
for (int i = 0; i < files.Length; ++i)
{
if (IsMainHouseFile(files[i].Name))
{
File.Delete(localDir + "/" + files[i].Name);
Debug.Log("Delete successfully " + files[i].Name);
num++;
}
}
}
LogSystem.Log("Delete finished, delete " + num + " files this time");
}
//判断文件名字
static bool IsMainHouseFile(string name)
{
if (scenesName == null)
{
LogSystem.Log("No scene data,Please removed manually!");
return false;
}
for (int i = 0; i < scenesName.Length; ++i)
{
//文件名字包含场景名字 且 最后必须是.png
if (name.Contains(scenesName[i]) && name.Contains(".png"))
{
return true;
}
}
return false;
}
}