在开发过程中,对于游戏中使用的美术资源,很多时候都是配置在配置文件中的,但是随着不断地开发,配置文件和美术资源可能都经历了多次更新,很有可能深藏在配置文件中的资源路径是不对的,可以通过扫描配置文件,将所有的路径记录下来,然后在检查是否通过路径可以加载到对应资源的方式来检测。
在这里提供一下大体思路和代码,具体项目需要具体分析。
该脚本用于将配置文件中的路径存起来。
using System.Collections.Generic;
using System.IO;
using System.Text;
using UnityEditor;
using UnityEngine;
// ReSharper disable once CheckNamespace
namespace Game.model
{
public abstract class GenConfigArtRefsBase
{
public abstract void GetRefs(List<string> allList);
public static void Gen(HashSet<string> hashSet){
List<string> toWrite = new List<string>();
List<GenConfigArtRefsBase> ret = new List<GenConfigArtRefsBase>();
ret.Add(new GenConfActivityLordTaskEvent());
ret.Add(new GenConfAllianceBuildingPage());
ret.Add(new GenConfAllianceGift());
ret.Add(new GenConfAllianceIcon());
foreach (var genConfigArtRefsBase in ret)
{
toWrite.Add("-------------------------------------------------------------------------------------------------------------------------------------------------------- " + genConfigArtRefsBase.GetType());
var resList = new List<string>();
genConfigArtRefsBase.GetRefs(resList);
resList.Sort();
toWrite.AddRange(resList);
}
StringBuilder sb = new StringBuilder();
foreach (var s in toWrite)
{
var process = s.Trim().Trim('/