#if UNITY_EDITOR using System.Collections.Generic; using System.IO; using System.Linq; using UnityEditor; using UnityEngine; /// /// 编辑器测试运行用的工具 /// public static class EditorTestUtility { public static Dictionary prefabDict; public static void InitPrefabDict() { prefabDict = new Dictionary(); 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(path); // 特殊,警告使用EffectBackup if (path.StartsWith("Assets/Project3D/EffectBackup/")) Debug.LogError("有物体试图调用EffectBackup路径的资源 " + path); } return result; } } #endif