Unity3D圣典3.3版本-中文版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Resources.FindObjectsOfTypeAll 查找所有类型的物体
# [Resources](Resources.html).FindObjectsOfTypeAll 查找所有类型的物体 static function *FindObjectsOfTypeAll* (*type* : Type) : [Object](../Object/Object.html)[] ### Parameters**参数** * *type* Type of the class to match while searching. 匹配搜索时类的类型 *Returns * [Object](../Object/Object.html)[] - An array of objects whose class is type or is derived from type. 返回一个物体类的类型或从 type 派生的数组。 *Description* 描述 Returns a list of all objects of Type type. 返回 Type 类型的所有物体的一个列表。 This function can return any type of Unity object that is loaded, including game objects, prefabs, materials, meshes, textures, etc. It will also list internal stuff, therefore please be extra careful the way you handle the returned objects. Contrary to [Object.FindObjectsOfType](../Object/Object.FindObjectsOfType.html) this function will also list disabled objects. 这个函数可以返回加载的 Unity 物体的任意类型,包含游戏物体、预设、材质、网格、纹理等等。它也会列出内部的东西,因此,请格外小心处理返回的物体的方式。相反 [Object.FindObjectsOfType](../Object/Object.FindObjectsOfType.html) 这个函数也会列出禁用的对象。 Please note that this function is very slow and is not recommended to be used every frame. 请注意这个函数非常慢,不推荐在每帧中使用。 * [C#](#) * [JavaScript](#) ``` using UnityEngine; using System.Collections; public class example : MonoBehaviour { void OnGUI() { GUILayout.Label("All " + Resources.FindObjectsOfTypeAll(typeof(UnityEngine.Object)).Length); GUILayout.Label("Textures " + Resources.FindObjectsOfTypeAll(typeof(Texture)).Length); GUILayout.Label("AudioClips " + Resources.FindObjectsOfTypeAll(typeof(AudioClip)).Length); GUILayout.Label("Meshes " + Resources.FindObjectsOfTypeAll(typeof(Mesh)).Length); GUILayout.Label("Materials " + Resources.FindObjectsOfTypeAll(typeof(Material)).Length); GUILayout.Label("GameObjects " + Resources.FindObjectsOfTypeAll(typeof(GameObject)).Length); GUILayout.Label("Components " + Resources.FindObjectsOfTypeAll(typeof(Component)).Length); } } ``` ``` // This script displays the number of allocated Unity objects by type. //这个脚本显示按类型分配的Unity物体的数量 // This is useful for finding leaks. Knowing the type of object //用于查找泄漏,知道物体的类型 // (mesh, texture, sound clip, game object) that is getting leaked is // the first step. You could then print the names of all leaked assets of that type. //(mesh, texture, sound clip, game object) 获得泄漏是第一步,然后,您可以打印所有按类型泄漏资源的名字 function OnGUI () { GUILayout.Label("All " + Resources.FindObjectsOfTypeAll(typeof(UnityEngine.Object)).Length); GUILayout.Label("Textures " + Resources.FindObjectsOfTypeAll(typeof(Texture)).Length); GUILayout.Label("AudioClips " + Resources.FindObjectsOfTypeAll(typeof(AudioClip)).Length); GUILayout.Label("Meshes " + Resources.FindObjectsOfTypeAll(typeof(Mesh)).Length); GUILayout.Label("Materials " + Resources.FindObjectsOfTypeAll(typeof(Material)).Length); GUILayout.Label("GameObjects " + Resources.FindObjectsOfTypeAll(typeof(GameObject)).Length); GUILayout.Label("Components " + Resources.FindObjectsOfTypeAll(typeof(Component)).Length); } ```
da
2022年5月23日 14:32
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码