using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Collections.Generic;
using System.ComponentModel;
using Object = UnityEngine.Object; //在选中的资源中查找
public static class EnumAssets { //枚举所有的T类型的资源
public static IEnumerable<T> EnumInCurrentSelection<T>()
where T : Object
{
Object[] selectionAsset = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
foreach (var s in selectionAsset)
{
var temp = s as T;
if (null != temp)
{
yield return temp;
}
} } //枚举所有的GameObject类型的资源
public static IEnumerable<GameObject> EnumGameObjectInCurrentSelection()
{
foreach (var s in EnumInCurrentSelection<GameObject>())
{
yield return s;
} yield break;
} //递归枚举所有GameObject
public static IEnumerable<GameObject> EnumGameObjectRecursiveInCurrentSelection()
{
foreach (var s in EnumInCurrentSelection<GameObject>())
{
foreach(var g in EnumGameObjectRecursive(s))
{
yield return g;
}
}
} public static IEnumerable<GameObject> EnumGameObjectRecursive(GameObject go)
{
yield return go;
for(int i=0; i<go.transform.childCount; i++)
{
foreach (var t in EnumGameObjectRecursive(go.transform.GetChild(i).gameObject))
{
yield return t;
}
}
} //递归枚举所有Compoent
public static IEnumerable<T> EnumComponentRecursiveInCurrentSelection<T>()
where T : UnityEngine.Component
{
foreach (var go in EnumInCurrentSelection<GameObject>())
{
var cs = go.GetComponentsInChildren<T>(true);
foreach (var c in cs)
{
yield return c;
}
}
} //枚举所有GameObject在这个目录
//path是相对于Application.dataPath的 例如 Assets/Res/UI/
public static IEnumerable<GameObject> EnumGameObjectAtPath(string path)
{
var guids = AssetDatabase.FindAssets("t:GameObject", new string[] { path });
foreach (var guid in guids)
{
var p = AssetDatabase.GUIDToAssetPath(guid);
var go = AssetDatabase.LoadAssetAtPath(p, typeof(GameObject)) as GameObject;
if (null != go)
{
yield return go;
}
}
} //枚举所有资源
//path是相对于Application.dataPath的 例如 Assets/Res/UI/
public static IEnumerable<T> EnumAssetAtPath<T>(string path)
where T : Object
{
var guids = AssetDatabase.FindAssets("t:Object", new string[] { path });
foreach (var guid in guids)
{
var p = AssetDatabase.GUIDToAssetPath(guid);
var go = AssetDatabase.LoadAssetAtPath(p, typeof(System.Object)) as T;
if (null != go)
{
yield return go;
}
}
} //递归枚举这个目录下的GameObject的所有T类型组件
//path是相对于Application.dataPath的 例如 Assets/Res/UI/
public static IEnumerable<T> EnumComponentRecursiveAtPath<T>(string path)
where T : UnityEngine.Component
{
var gos= EnumGameObjectAtPath(path);
foreach (var go in gos)
{
var cs = go.GetComponentsInChildren<T>(true);
foreach(var c in cs)
{
yield return c;
}
}
} //递归枚举这个目录下的GameObject
//path是相对于Application.dataPath的 例如 Assets/Res/UI/
public static IEnumerable<GameObject> EnumGameOjectRecursiveAtPath(string path)
{
var gos = EnumComponentRecursiveAtPath<Transform>(path);
foreach (var go in gos)
{
yield return go.gameObject;
}
}
}

  

Unity3d 枚举某个目录下所有资源的更多相关文章

  1. android访问asset目录下的资源

    android提供了AssetManager来访问asset目录下的资源, 在activity中通过getAssets()获取AssetManager 常用的api如下: 1.列举路径下的资源Stri ...

  2. 安卓获取Assets目录下的资源

    获取Assets目录下的资源 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 ! ...

  3. Android 如何引用com.android.internal.R目录下的资源

    Android 如何引用com.android.internal.R目录下的资源 项目需求 有一个资源跟系统上的一个资源相同,想要引用它:frameworks/base/core/res/res/dr ...

  4. Android读取assets目录下的资源

    1.获取资源的输入流 资源文件 sample.txt 位于 $PROJECT_HOME/assets/ 目录下,可以在 Activity 中通过 Context.getAssets().open(“s ...

  5. Unity3d:播放物理目录下的MP3文件

    u3d里,是支持播放MP3文件的,但要放到资源里,不支持播放物理目录下的MP3文件.由于界面上无需显示,只是当作背景音乐来播放,所以想到调用c#的组件来解决此问题.主要代码都在附件中,根据需要加到自己 ...

  6. Java获取/resources目录下的资源文件方法

    Web项目开发中,经常会有一些静态资源,被放置在resources目录下,随项目打包在一起,代码中要使用的时候,通过文件读取的方式,加载并使用: 今天总结整理了九种方式获取resources目录下文件 ...

  7. Asp.Net配置不允许通过url方式访问目录下的资源

    Asp.Net网站发布后,有部分文件为了安全性,是不能直接通过url访问获取 通常有2种做法: 1.将文件目录建立在 App_code 或者App_Data 等默认的隐藏目录下 2.将文件的目录添加到 ...

  8. ASP.NET 通过配置hiddenSegment禁止目录下资源通过Url形式访问

    根据默认的ASP.NET配置,App_Data下的资源是禁止通过Url形式直接访问的,在实际开发中,可能也会有这样的需求,比如某些是系统资源目录,该目录下的资源也需要像App_Data目录一样禁止访问 ...

  9. Android开发之assets目录下资源使用总结

    预前知识: Android资源文件分类: Android资源文件大致可以分为两种: 第一种是res目录下存放的可编译的资源文件: 这种资源文件系统会在R.Java里面自动生成该资源文件的ID,所以访问 ...

随机推荐

  1. Thinkphp 模板中直接对数据处理 模板中使用函数 中文字符串截取

    1.Thinkphp 模板中直接对数据处理:{$data.name|substr=0,3} 2.中文字符串截取函数:mb_substr=0,14,'utf-8' 3.中文字符串统计:iconv_str ...

  2. hibernate 批量增加 修改 删除

    4.2  Hibernate的批量处理 Hibernate完全以面向对象的方式来操作数据库,当程序里以面向对象的方式操作持久化对象时,将被自动转换为对数据库的操作.例如调用Session的delete ...

  3. Spring实战 (第3版)——依赖注入

    首先弄明白几个概念: 1.什么是POJO 2.JavaBean规范 3.EJB(Enterprise JavaBean) 体会Spring如何简化Java开发. 创建应用对象(组件)之间协作关系的行为 ...

  4. git如何撤销合并

    撒销一个合并 如果你觉得你合并后的状态是一团乱麻,想把当前的修改都放弃,你可以用下面的命令回到合并之前的状态: $ git reset --hard HEAD 或者你已经把合并后的代码提交,但还是想把 ...

  5. [整理]Android开发(二)-Weather App

    private class WeatherData{ private String _weatherDescription; private Integer _currentTemperature; ...

  6. session 的用法

    </head> <body> <?php //session_start();//开启session,必须写在PHP代码最顶端 //HTTP,无状态性 //记录登陆者状态 ...

  7. call() 和 apply() ----预定义的函数方法

  8. mysql不同版本号之间的一些区别

    5.1.69-community和5.6.26-log版本相比,有一些语法不支持,如: datetime(3),CURRENT_TIMESTAMP(3)

  9. Android应用签名

    http://www.cnblogs.com/ghj1976/archive/2011/07/18/2109381.html 为了要签名? 开发Android的人这么多,完全有可能大家都把类名,包名起 ...

  10. leetcode 32. Longest Valid Parentheses

    Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...