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. Redis在WEB开发中的应用与实践

    Redis在WEB开发中的应用与实践 一.Redis概述: Redis是一个功能强大.性能高效的开源数据结构服务器,Redis最典型的应用是NoSQL.但事实上Redis除了作为NoSQL数据库使用之 ...

  2. thinkphp 行为扩展以及插件机制介绍

    首先行为扩展这个概念是TP架构的核心组成之一,关于行为的解释我就粗略的概括一下吧:TP在从接受到HTTP请求到最终将视图输出,期间经历的很多步骤,这些步骤大家可以在http://document.th ...

  3. EF上下文管理

  4. 【AngularJS】—— 7 模块化

    AngularJS有几大特性,比如: 1 MVC 2 模块化 3 指令系统 4 双向数据绑定 那么本篇就来看看AngularJS的模块化. 首先先说一下为什么要实现模块化: 1 增加了模块的可重用性 ...

  5. ngCordova插件安装使用

    为什么ngCordova ngCordova是在Cordova Api基础上封装的一系列开源的AngularJs服务和扩展,让开发者可以方便的在HybridApp开发中调用设备能力,即可以在Angul ...

  6. linux系统安装yum环境

    http://blog.sina.com.cn/s/blog_63d8dad80101cn2s.html 1.卸载rhel的默认安装的yum包 查看yum包 rpm -qa|grep yum 卸载之 ...

  7. Redis安装和使用

    新年伊始,万象更新.祝大家:新的一年,工作顺利,生活越来越美好. http://www.redis.cn/commands.html http://try.redis.io/ http://www.c ...

  8. svn还原到指定版本

    svn还原到指定版本 1,选中文件夹,右健,show log 2,选中指定版本,右健,Revert to this revision 3,svn commit 4,ok

  9. 使用ajax获取JSON数据的jQuery代码的格式

    具体的也可以参考:http://www.w3cfuns.com/notes/16039/2b004b1bcdf79092f2e66b2bbe9f51df.html

  10. 提交上了,却在iTunes Connect没有新版本的任何消息

    上架的时候,收到这样的邮件 This app attempts to access privacy-sensitive data without a usage description. The ap ...