打开一个空的Unity项目并在Hierarchy面板中,右键 3D Object -> Cube 新键一个Cube,选中它,在Inspector面板中 点击 Mesh Filter组件的 Mesh 选择按钮,如下图,查看cube网格数据来源
上面的Library/unity default resources是一个大的bundle包,里面保存了很多Unity默认的资源,它的路径在 Unity的安装目录\Editor\Data\Resources,如下图
打开后我们还能看到unity editor resources与unity_bulttin_extra两个文件,它们的作用和unity default resource类似,比如cube的material就是从unity_builtin_extra文件中加载的,我们也可以自己通过接口加载它们并使用
using System.Collections; using System.Collections.Generic; using UnityEngine; public class BuiltInAssets : MonoBehaviour { public UnityEngine.Object[] objs; [ContextMenu("GetBuiltInAssets")] void GetBuiltInAssets() { #if UNITY_EDITOR objs = UnityEditor.AssetDatabase.LoadAllAssetsAtPath("Library/unity default resources"); #endif } }
运行效果如下
加载unity_bulttin_extra
objs = UnityEditor.AssetDatabase.LoadAllAssetsAtPath("Resources/unity_builtin_extra");
加载unity editor resources
objs = UnityEditor.AssetDatabase.LoadAllAssetsAtPath("Library/unity editor resources");
文章评论