Object.Destroy

static function Destroy(obj: Object, t: float = 0.0F): void;
 
Description

Removes a gameobject, component or asset.

The object 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.
 
 
 
 
Resources.FindObjectsOfTypeAll

static Object[] FindObjectsOfTypeAll(Type type);
static T[] FindObjectsOfTypeAll<T> ();
Parameters
type Type of the class to match while searching.
Returns
Object[] An array of objects whose class is type or is derived from type.
Description

Returns a list of all objects of 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.
 
可以用来查找场景中被disable了的物件。
Contrary to Object.FindObjectsOfType this function will also list disabled objects.
 
Please note that this function is very slow and is not recommended to be used every frame.
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

可以用来查找场景中被disable了的物件。
Component[] GetComponentsInChildren(Type t, bool includeInactive = false);
T[] GetComponentsInChildren<T>(bool includeInactive);
T[] GetComponentsInChildren<T>();
Parameters
t The type of Component to retrieve.
includeInactive Should inactive Components be included in the found set?
Description

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

static function Find(name: string): GameObject;
Description

Finds a game object by name and returns it.

根据路径或名称查找场景物件

If no game object with 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")吧?待验证
This function is most useful to automatically connect references to other objects at load time, eg. inside MonoBehaviour.Awake or MonoBehaviour.Start. You should avoid calling this function every frame eg. MonoBehaviour.Update for performance reasons. A common pattern is to assign a game object to a variable inside MonoBehaviour.Start. And use the variable in MonoBehaviour.Update.
	// 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

static function FindObjectsOfType(type: Type): Object[];
Description

Returns a list of all active loaded objects of Type type.

类型查找Object, 由于是指定了Type的,除非指定的Type是GameObject或者Resource Object,一般该函数都是用来查找返回Component?

It will return no assets (meshes, textures, prefabs, ...) or inactive objects.(无法查找资源以及被disable了的Object)
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资源的查找的更多相关文章

  1. unity资源机制(转)

    原文地址:https://www.jianshu.com/p/ca5cb9d910c0作者:重装机霸 2.资源概述 Unity必须通过导入将所支持的资源序列化,生成AssetComponents后,才 ...

  2. Unity资源Assetmport New Asset对话框

    Unity资源Assetmport New Asset对话框 1.2.2  资源 开发游戏一定会使用很多东西,如网格.纹理.电影.动画.声音.音乐.文本等等.这些文件都被Unity称为资源(Asset ...

  3. Android App资源的查找过程分析

    Android资源管理框架实际就是由AssetManager和Resources两个类来实现的.其中,Resources类可以根据ID来查找资源,而AssetManager类根据文件名来查找资源.事实 ...

  4. Android应用程序资源的查找过程分析

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8806798 我们知道,在Android系统中, ...

  5. unity资源

    unity资源集中贴 1.unity经验之谈 http://jingyan.baidu.com/article/19192ad820f17be53e570715.html 2.百度网盘,分享了一点模型 ...

  6. Unity资源打包学习笔记(一)、详解AssetBundle的流程

    转载请标明出处:http://www.cnblogs.com/zblade/ 本文参照unity官网上对于assetBundle的一系列讲解,主要针对assetbundle的知识点做一个梳理笔记,也为 ...

  7. Unity资源Assetbundle

    转  Unity资源打包之Assetbundle 本文原创版权归 csdn janeky 所有,转载请详细注明原创作者及出处,以示尊重! 作者:janeky 原文:http://blog.csdn.n ...

  8. Unity资源打包之Assetbundle

    转  Unity资源打包之Assetbundle 本文原创版权归 csdn janeky 所有,转载请详细注明原创作者及出处,以示尊重! 作者:janeky 原文:http://blog.csdn.n ...

  9. Unity——资源文件夹介绍

    Unity资源文件夹介绍 1.编辑时 在Asset文件下存在Resources和SteamingAsset文件夹: Resources 只读不可修改,打包时直接写死,没有办法通过热更新替换资源: 可以 ...

随机推荐

  1. jquery对JSON字符串的解析--eval函数

    jquery eval解析JSON中的注意点介绍----https://www.jb51.net/article/40842.htm

  2. HDU-1022Train Problem I,简单栈模拟;

    Train Problem I                                                                                     ...

  3. Frequent values(poj 3368)

    题意:给出n个数和Q个询问(l,r),对于每个询问求出(l,r)之间连续出现次数最多的次数. 代码: /* rmq算法 当询问到x,y时,设在x之后并且与a[x]相同的最后一个数编号为t,那么x到t之 ...

  4. Python基础之 一 字典(dict)

    字典:是一种key - value的数据类型.语法:info = { key:value }特性:无序,key必须唯一(所以天生去重) 方法如下:del dict[key]:删除字典指定键len(di ...

  5. 本地配置nginx的https

    前文:因为要用谷歌下的getUserMedia方法,而getUserMedia方法只能在https下才能调用,所以在本地搭建https来测试,现在说说步骤. 步骤1:下载nginx-1.10.3.zi ...

  6. 百度UEditor富文本上传图片

    项目中使用UEditor发现设置图片自定义保存路径会出现<请求后台配置项http错误,上传功能将不能正常使用!错误> /* 上传图片配置项 */ "imageActionName ...

  7. 如何使用TFTP客户端工具修复路由器固件

    如何使用TFTP客户端工具修复路由器固件 编号:12083       来自:NetGear       更新日期:2013-10-14       访问数量:24650 NETGEAR无线路由器中, ...

  8. luajit利用ffi结合C语言实现面向对象的封装库

    luajit中.利用ffi能够嵌入C.眼下luajit的最新版是2.0.4,在这之前的版本号我还不清楚这个扩展库详细怎么样,只是在2.04中,真的非常爽.  既然是嵌入C代码.那么要说让lua支持 ...

  9. .Net 与 Javascript 混合编程系列

    之前的文章有提到 edge 和 nodejs 交互,通过node的模块为C# 提供一些扩展,这个还是比較方便. 这里说下为什么要使用js. 1.SharpKit是一个用于在编译时将C#语言转换为Jav ...

  10. PromiseKit入门

    原文:Getting Started with PromiseKit 作者:Michael Katz 译者:kmyhy 异步编程真的让人头疼.不管你怎样小心,总是easy出现臃肿的托付.混乱的完毕句柄 ...