言語: 日本語
  • C#
  • JS
  • Boo

スクリプト言語

お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。

Resources.FindObjectsOfTypeAll

public static function FindObjectsOfTypeAll(type: Type): Object[];

Parameters

type オブジェクトの型

Returns

Object[] type または type から派生したオブジェクトの配列

Description

/type/ で指定した型の全てのオブジェクトを取得します

この関数はUnityオブジェクトとしてロードされているものを対象として取得します。例えばゲームオブジェクト、プレハブ、マテリアル、メッシュ、テクスチャなどです。また、通常は触れない内部的なオブジェクトも取得することが出来ます。したがって十分に注意して扱うようにしてください。 この関数は Object.FindObjectsOfType と比べて更に無効となっているオブジェクトの取得まで出来てしまいます。 この関数はとても処理が遅いので毎フレーム使用するのは推奨されません。

	// This script displays the number of allocated Unity objects by type.
	// 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.

	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);
	}
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[]) {
        if (go.hideFlags == HideFlags.NotEditable || go.hideFlags == HideFlags.HideAndDontSave)
            continue;
        
        var assetPath: String = AssetDatabase.GetAssetPath(go.transform.root.gameObject);
        if (!String.IsNullOrEmpty(assetPath))
            continue;
        
        objectsInScene.Add(go);
    }
    
    return objectsInScene;
}
public static function FindObjectsOfTypeAll(): T[];

Description

/T/ で指定した型から全てのオブジェクトを取得します

この関数はUnityオブジェクトとしてロードされているものを対象として取得します。例えばゲームオブジェクト、プレハブ、マテリアル、メッシュ、テクスチャなどです。また、通常は触れない内部的なオブジェクトも取得することが出来ます。したがって十分に注意して扱うようにしてください。 この関数は Object.FindObjectsOfType と比べて更に無効となっているオブジェクトの取得まで出来てしまいます。 この関数はとても処理が遅いので毎フレーム使用するのは推奨されません。

	// This script displays the number of allocated Unity objects by type.
	// 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.

	function OnGUI () {
		GUILayout.Label("All " + Resources.FindObjectsOfTypeAll.<UnityEngine.Object>().Length);
		GUILayout.Label("Textures " + Resources.FindObjectsOfTypeAll.<Texture>().Length);
		GUILayout.Label("AudioClips " + Resources.FindObjectsOfTypeAll.<AudioClip>().Length);
		GUILayout.Label("Meshes " + Resources.FindObjectsOfTypeAll.<Mesh>().Length);
		GUILayout.Label("Materials " + Resources.FindObjectsOfTypeAll.<Material>().Length);
		GUILayout.Label("GameObjects " + Resources.FindObjectsOfTypeAll.<GameObject>().Length);
		GUILayout.Label("Components " + Resources.FindObjectsOfTypeAll.<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.<GameObject>()) {
        if (go.hideFlags == HideFlags.NotEditable || go.hideFlags == HideFlags.HideAndDontSave)
            continue;
        
        var assetPath: String = AssetDatabase.GetAssetPath(go.transform.root.gameObject);
        if (!String.IsNullOrEmpty(assetPath))
            continue;
        
        objectsInScene.Add(go);
    }
    
    return objectsInScene;
}