Unity资源的查找
Object.Destroy
Removes a gameobject, component or asset.
obj will be destroyed now or if a time is specified t seconds from now. If obj is a Component it will remove the component from the GameObject and destroy it. If objis a GameObject it will destroy the GameObject, all its components and all transform children of the GameObject. Actual object destruction is always delayed until after the current Update loop, but will always be done before rendering.| type | Type of the class to match while searching. |
Object[] An array of objects whose class is type or is derived from type.
Returns a list of all objects of Type type.
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);
}
}
import System.Collections.Generic; // This script finds all the objects in scene, excluding prefabs:
function GetAllObjectsInScene(): List.<GameObject> {
var objectsInScene: List.<GameObject> = new List.<GameObject>(); for (var go: GameObject in Resources.FindObjectsOfTypeAll(typeof(GameObject)) as GameObject[]) {
//对于一些不可编辑的资源,以及在场景中但隐藏,不保存,不删除的资源,例如mesh, texture,shader。跳过不处理。
if (go.hideFlags == HideFlags.NotEditable || go.hideFlags == HideFlags.HideAndDontSave)
continue; var assetPath: String = AssetDatabase.GetAssetPath(go.transform.root.gameObject);
// 如果是可编辑的但又找到了对应的AssetDataBase路径,则应该是Prefab。 需验证!
if (!String.IsNullOrEmpty(assetPath))
continue; objectsInScene.Add(go);
} return objectsInScene;
}
Component.GetComponentsInChildren
GameObject.GetComponentsInChildren
| t | The type of Component to retrieve. |
| includeInactive | Should inactive Components be included in the found set? |
Returns all components of Type type in the GameObject or any of its children.
using UnityEngine;
using System.Collections; public class Example : MonoBehaviour {
public Component[] hingeJoints;
void Example() {
hingeJoints = GetComponentsInChildren<HingeJoint>();
foreach (HingeJoint joint in hingeJoints) {
joint.useSpring = false;
}
}
}
| GetComponent | Returns the component of Type type if the game object has one attached, null if it doesn't. You can access both builtin components or scripts with this function. |
|---|---|
| GetComponentInChildren | Returns the component of Type type in the GameObject or any of its children using depth first search. |
| GetComponents | Returns all components of Type type in the GameObject. |
| GetComponentsInChildren | Returns all components of Type type in the GameObject or any of its children. |
GameObject.Find
Finds a game object by name and returns it.
根据路径或名称查找场景物件
name can be found, null is returned. If name contains a '/' character it will traverse the hierarchy like a path name. This function only returns active gameobjects.For performance reasons it is recommended to not use this function every frame Instead cache the result in a member variable at startup or use GameObject.FindWithTag(这个相对快一些?).
var hand : GameObject;
// This will return the game object named Hand in the scene.
hand = GameObject.Find("Hand");
// This will return the game object named Hand.
// Hand must not have a parent in the hierarchy view!
// 绝对路径查找
hand = GameObject.Find("/Hand");
// This will return the game object named Hand,
// which is a child of Arm -> Monster.
// Monster must not have a parent in the hierarchy view!
// 绝对路径查找
hand = GameObject.Find("MonsterArm/Hand");
// 应该是 hand = GameObject.Find("/Monster/Arm/Hand")吧?待验证
// This will return the game object named Hand,
// which is a child of Arm -> Monster.
// Monster may have a parent.
// 相对路径查找
hand = GameObject.Find("MonsterArmHand");
// 应该是hand = GameObject.Find("Monster/Arm/Hand")吧?待验证
// Find the hand inside Start and rotate it every frame
private var hand : GameObject;
function Start () {
hand = GameObject.Find("MonsterArm/Hand");
} function Update () {
hand.transform.Rotate(0, 100 * Time.deltaTime, 0);
}
| Find | Finds a game object by name and returns it. |
|---|---|
| FindGameObjectsWithTag | Returns a list of active GameObjects tagged tag. Returns empty array if no GameObject was found. |
| FindWithTag | Returns one active GameObject tagged tag. Returns null if no GameObject was found. |
Object.FindObjectsOfType
Returns a list of all active loaded objects of Type type.
类型查找Object, 由于是指定了Type的,除非指定的Type是GameObject或者Resource Object,一般该函数都是用来查找返回Component?
Please note that this function is very slow. It is not recommended to use this function every frame. In most cases you can use the singleton pattern instead.
// When clicking on the object, it will disable all springs on all
// hinges in the scene.
function OnMouseDown () {
var hinges : HingeJoint[] = FindObjectsOfType(HingeJoint) as HingeJoint[];
for (var hinge : HingeJoint in hinges) {
hinge.useSpring = false;
}
}
| FindObjectOfType | Returns the first active loaded object of Type type. |
|---|---|
| FindObjectsOfType | Returns a list of all active loaded objects of Type type. |
Unity资源的查找的更多相关文章
- unity资源机制(转)
原文地址:https://www.jianshu.com/p/ca5cb9d910c0作者:重装机霸 2.资源概述 Unity必须通过导入将所支持的资源序列化,生成AssetComponents后,才 ...
- Unity资源Assetmport New Asset对话框
Unity资源Assetmport New Asset对话框 1.2.2 资源 开发游戏一定会使用很多东西,如网格.纹理.电影.动画.声音.音乐.文本等等.这些文件都被Unity称为资源(Asset ...
- Android App资源的查找过程分析
Android资源管理框架实际就是由AssetManager和Resources两个类来实现的.其中,Resources类可以根据ID来查找资源,而AssetManager类根据文件名来查找资源.事实 ...
- Android应用程序资源的查找过程分析
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8806798 我们知道,在Android系统中, ...
- unity资源
unity资源集中贴 1.unity经验之谈 http://jingyan.baidu.com/article/19192ad820f17be53e570715.html 2.百度网盘,分享了一点模型 ...
- Unity资源打包学习笔记(一)、详解AssetBundle的流程
转载请标明出处:http://www.cnblogs.com/zblade/ 本文参照unity官网上对于assetBundle的一系列讲解,主要针对assetbundle的知识点做一个梳理笔记,也为 ...
- Unity资源Assetbundle
转 Unity资源打包之Assetbundle 本文原创版权归 csdn janeky 所有,转载请详细注明原创作者及出处,以示尊重! 作者:janeky 原文:http://blog.csdn.n ...
- Unity资源打包之Assetbundle
转 Unity资源打包之Assetbundle 本文原创版权归 csdn janeky 所有,转载请详细注明原创作者及出处,以示尊重! 作者:janeky 原文:http://blog.csdn.n ...
- Unity——资源文件夹介绍
Unity资源文件夹介绍 1.编辑时 在Asset文件下存在Resources和SteamingAsset文件夹: Resources 只读不可修改,打包时直接写死,没有办法通过热更新替换资源: 可以 ...
随机推荐
- java发送短信验证码的功能实现
总结一下发送短信验证码的功能实现 (题外话:LZ是在腾讯云买的第三方(山东鼎信)短信服务平台的接口,1块钱20次的套餐来练手,哈哈,给他们打个广告,有需要的可以去购买哈,下面是购买链接短信服务平台购买 ...
- [luoguP1896] [SCOI2005]互不侵犯King(状压DP)
传送门 先预处理出来一行中放置国王的所有情况和每种情况所用的国王个数. f[i][j][k]表示前i行放j个国王且最后一行的状态为k的方案数 状压DP即可 #include <cstdio> ...
- java.lang.ClassNotFoundException: org.apache.jsp.WEB_002dINF.views.login_jsp
背景:SpringBoot的项目配置了对jsp的支持,走控制器就报这个错误.相关配置如下: <!-- JSP BEGIN --> <dependency> <groupI ...
- 新装mvn建第一个项目报错org.apache.maven.plugins:maven-resources-plugin:2.6
1.第一次创建mvn项目会报maven-resources-plugin-2.6.jar错,原因是mvn无法自动下载这个jar包,多次删除这个目录下的C:\Users\Administrator\.m ...
- PKCS填充方式
1)RSA_PKCS1_PADDING 填充模式,最常用的模式要求: 输入 必须 比 RSA 钥模长(modulus) 短至少11个字节, 也就是 RSA_size(rsa) – 11.如果输入的明文 ...
- 1017 乘积最大 2000年NOIP全国联赛普及组NOIP全国联赛提高组
1017 乘积最大 2000年NOIP全国联赛普及组NOIP全国联赛提高组 #include <iostream> #include <string> #include & ...
- Redis集群方案收集
说明: 如果不考虑客户端分片去实现集群,那么市面上基本可以说就三种方案最成熟,它们分别如下所示: 系统 贡献者 是否官方Redis实现 编程语言 Twemproxy Twitter 是 C Redis ...
- jQuery—— jQuery get方法+一般处理程序处理文本框内容
网上常常看到这种交互方式,当去一个站点注冊username的时候,假设文本框内没有输入数据,或者数据输入的内容格式不正确.就会将文本框变成红色来提示你输入的内容有误. 自己将这个文本框验证的方式改变了 ...
- Mysql-SQL优化-统计某种类型的个数
有时我们想统计某种类型有多少个,会用这个SQL. 全表扫描之余,还要filesort.耗时1.34秒. mysql> select country,count(*) from t1 group ...
- react-color 颜色选择器组件
demo链接:github demo 安装: npm install react-color --save 有一下几种类型组件 <AlphaPicker /> <BlockPicke ...