using UnityEngine;
using UnityEditor;
using System.IO;
using System;
using System.Text;
using System.Collections.Generic;
using LitJson;
public class BuildAssetBundlesFromDirectory
{
static List<JsonResource> config=new List<JsonResource>();
static Dictionary<string, List<JsonResource>> assetList=new Dictionary<string, List<JsonResource>>();
[@MenuItem("Asset/Build AssetBundles From Directory of Files")]//这里不知道为什么用"@",添加菜单
static void ExportAssetBundles ()
{//该函数表示通过上面的点击响应的函数
assetList.Clear();
string path = AssetDatabase.GetAssetPath(Selection.activeObject);//Selection表示你鼠标选择激活的对象
Debug.Log("Selected Folder: " + path); if (path.Length != )
{
path = path.Replace("Assets/", "");//因为AssetDatabase.GetAssetPath得到的是型如Assets/文件夹名称,且看下面一句,所以才有这一句。
Debug.Log("Selected Folder: " + path);
string [] fileEntries = Directory.GetFiles(Application.dataPath+"/"+path);//因为Application.dataPath得到的是型如 "工程名称/Assets" string[] div_line = new string[] { "Assets/" };
foreach(string fileName in fileEntries)
{
j++;
Debug.Log("fileName="+fileName);
string[] sTemp = fileName.Split(div_line, StringSplitOptions.RemoveEmptyEntries);
string filePath = sTemp[];
Debug.Log(filePath);
filePath = "Assets/" + filePath;
Debug.Log(filePath);
string localPath = filePath;
UnityEngine.Object t = AssetDatabase.LoadMainAssetAtPath(localPath); //Debug.Log(t.name);
if (t != null)
{
Debug.Log(t.name);
JsonResource jr=new JsonResource();
jr.Name=t.name;
jr.Source=path+"/"+t.name+".unity3d";
Debug.Log( t.name);
config.Add(jr);//实例化json对象
string bundlePath = Application.dataPath+"/../"+path;
if(!File.Exists(bundlePath))
{
Directory.CreateDirectory(bundlePath);//在Asset同级目录下相应文件夹
}
bundlePath+="/" + t.name + ".unity3d";
Debug.Log("Building bundle at: " + bundlePath);
BuildPipeline.BuildAssetBundle(t, null, bundlePath, BuildAssetBundleOptions.CompleteAssets);//在对应的文件夹下生成.unity3d文件
}
}
assetList.Add("AssetList",config);
for(int i=;i<config.Count;i++)
{
Debug.Log(config[i].Source);
}
}
string data=JsonMapper.ToJson(assetList);//序列化数据
Debug.Log(data);
string jsonInfoFold=Application.dataPath+"/../Scenes";
if(!Directory.Exists(jsonInfoFold))
{
Directory.CreateDirectory(jsonInfoFold);//创建Scenes文件夹
}
string fileName1=jsonInfoFold+"/json.txt";
if(File.Exists(fileName1))
{
Debug.Log(fileName1 +"already exists");
return;
}
UnicodeEncoding uni=new UnicodeEncoding(); using( FileStream fs=File.Create(fileName1))//向创建的文件写入数据
{
fs.Write(uni.GetBytes(data),,uni.GetByteCount(data));
fs.Close();
}
}
}

http://www.cnblogs.com/U-tansuo/archive/2012/07/11/2587173.html

unity3d 场景配置文件生成代码的更多相关文章

  1. unity3d随机地牢生成代码

    现在也是处于失业状态,碰巧看到个面试题是要用unity生成个随机地牢,就把做题过程中的思路和代码记录一下吧. 做完了以后我又想了一下,发现其实根本不需要这么麻烦,果然demo里的代码对我的思路影响还是 ...

  2. 自定义Mybatis自动生成代码规则

    前言 大家都清楚mybatis-generate-core 这个工程提供了获取表信息到生成model.dao.xml这三层代码的一个实现,但是这往往有一个痛点,比如需求来了,某个表需要增加字段,肯定需 ...

  3. Android注解使用之通过annotationProcessor注解生成代码实现自己的ButterKnife框架

    前言: Annotation注解在Android的开发中的使用越来越普遍,例如EventBus.ButterKnife.Dagger2等,之前使用注解的时候需要利用反射机制势必影响到运行效率及性能,直 ...

  4. mybatis Generator生成代码及使用方式

    本文原创,转载请注明:http://www.cnblogs.com/fengzheng/p/5889312.html 为什么要有mybatis mybatis 是一个 Java 的 ORM 框架,OR ...

  5. mybatis generator maven插件自动生成代码

    如果你正为无聊Dao代码的编写感到苦恼,如果你正为怕一个单词拼错导致Dao操作失败而感到苦恼,那么就可以考虑一些Mybatis generator这个差价,它会帮我们自动生成代码,类似于Hiberna ...

  6. 使用mybatis-generator生成代码

    文档地址: ​http://mbg.cndocs.tk/index.html ​ 以下是一个简单的配置内容. 一.在maven配置文件中添加mybatis-generator插件 1 2 3 4 5 ...

  7. WebStorm按Tab建快速生成代码模块

    WS中,比如调试每次都要写的console.log(xxx);每次都要敲一遍,还有if模块,for循环模块,难道没有快捷键,可以生成代码模块吗,答案是“有”. 操作步骤如下(汉化版WS): 1.Alt ...

  8. MyBatis自动生成代码示例

    在项目中使用到mybatis时,都会选择自动生成实体类,Mapper,SqlMap这三个东东. 手头上在用的又不方便,找了下网上,其实有很多文章,但有些引用外部文件时不成功,也不方便,所以重新整理了下 ...

  9. mybatis自动生成代码

    使用maven集成mybatis-generator插件生成Mybatis的实体类,DAO接口和Map映射文件 本例中,使用的是mysql数据库 前提:表已经建好  mybatis框架的jar包,数据 ...

随机推荐

  1. PhpStorm快捷键设置/个性化设置,如何多项目共存?如何更换主题?

    #常用快捷键  设置快捷键:File -> Settings -> IDE Settings -> Keymap -> 选择“Eclipse” -> 然后“Copy”一份 ...

  2. .export*读取图片

    *读取图片 read_image(Image,'D:/MyFile/halcon/数字识别/1.jpg define PHYS_FLASH2_1 0xBC000000 /* Image2 Bank # ...

  3. 软工实践 - 第十一次作业 Alpha 冲刺 (3/10)

    队名:起床一起肝活队 组长博客:https://www.cnblogs.com/dawnduck/p/9972061.html 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去 ...

  4. ajax的多次请求问题

    我们在用ajax请求数据时,可能会遇到一次点击多次触发的可能.(比如说:ajax 的 onreadystatechange 事件就会触发多次:这是因为 onreadystatechange 是一个事件 ...

  5. 第十章 用户数据报协议和IP分片

    用户数据报协议和IP分片 UDP是一种保留消息边界的简单的面向数据报的传输层协议.它仅提供差错检测.只是检测,而不是纠正,它只是把应用程序传给IP层的数据发送出去,但是并不会保证数据能够完好无损的到达 ...

  6. PHP文件开头session_start()

    session_start(); 告诉服务器使用session.一般来说,php是不会主动使用session的. 不过可以设置php.ini中的session.auto_start=1来自动对每个请求 ...

  7. 模拟Json格式传值请求与数据接收

    a.php代码: function http_post_json($url, $jsonStr) { $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, ...

  8. Apache二级域名实现

    Apache二级域名实现 首先,你的拥有一个有泛域名解析的顶级域名,例如: domain.com 其次,在 httpd.conf 中打开 mod_rewrite 之后,在 httpd.conf 的最后 ...

  9. COMPANY_点取消会卡死的解决方法

    // OLD void ctonedlg::onbtn_basedir_clicked() {     m_basedir = getUserSelectDir();     doSearchDir( ...

  10. UVA 10801 Lift Hopping 最短路

    2种方式直接代码就可以了.注意首次不需要60S的转换 #include <map> #include <set> #include <list> #include ...