Files
JJBB/Assets/Project/Script/Common/Utilities/EditorTestUtility.cs
2024-08-23 15:49:34 +08:00

43 lines
1.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#if UNITY_EDITOR
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;
/// <summary>
/// 编辑器测试运行用的工具
/// </summary>
public static class EditorTestUtility
{
public static Dictionary<string, string> prefabDict;
public static void InitPrefabDict()
{
prefabDict = new Dictionary<string, string>();
var prefabPaths = from prefabPath in AssetDatabase.GetAllAssetPaths()
where Path.GetExtension(prefabPath) == ".prefab"
select new {name = Path.GetFileNameWithoutExtension(prefabPath), path = prefabPath};
foreach (var prefabPath in prefabPaths)
if (!prefabDict.ContainsKey(prefabPath.name))
prefabDict.Add(prefabPath.name, prefabPath.path);
}
public static GameObject LoadGameObject(string name)
{
if (prefabDict == null)
InitPrefabDict();
string path;
GameObject result = null;
// ReSharper disable once PossibleNullReferenceException
if (prefabDict.TryGetValue(name, out path))
{
result = AssetDatabase.LoadAssetAtPath<GameObject>(path);
// 特殊警告使用EffectBackup
if (path.StartsWith("Assets/Project3D/EffectBackup/"))
Debug.LogError("有物体试图调用EffectBackup路径的资源 " + path);
}
return result;
}
}
#endif