unity3d 场景配置文件生成代码
- 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 场景配置文件生成代码的更多相关文章
- unity3d随机地牢生成代码
现在也是处于失业状态,碰巧看到个面试题是要用unity生成个随机地牢,就把做题过程中的思路和代码记录一下吧. 做完了以后我又想了一下,发现其实根本不需要这么麻烦,果然demo里的代码对我的思路影响还是 ...
- 自定义Mybatis自动生成代码规则
前言 大家都清楚mybatis-generate-core 这个工程提供了获取表信息到生成model.dao.xml这三层代码的一个实现,但是这往往有一个痛点,比如需求来了,某个表需要增加字段,肯定需 ...
- Android注解使用之通过annotationProcessor注解生成代码实现自己的ButterKnife框架
前言: Annotation注解在Android的开发中的使用越来越普遍,例如EventBus.ButterKnife.Dagger2等,之前使用注解的时候需要利用反射机制势必影响到运行效率及性能,直 ...
- mybatis Generator生成代码及使用方式
本文原创,转载请注明:http://www.cnblogs.com/fengzheng/p/5889312.html 为什么要有mybatis mybatis 是一个 Java 的 ORM 框架,OR ...
- mybatis generator maven插件自动生成代码
如果你正为无聊Dao代码的编写感到苦恼,如果你正为怕一个单词拼错导致Dao操作失败而感到苦恼,那么就可以考虑一些Mybatis generator这个差价,它会帮我们自动生成代码,类似于Hiberna ...
- 使用mybatis-generator生成代码
文档地址: http://mbg.cndocs.tk/index.html 以下是一个简单的配置内容. 一.在maven配置文件中添加mybatis-generator插件 1 2 3 4 5 ...
- WebStorm按Tab建快速生成代码模块
WS中,比如调试每次都要写的console.log(xxx);每次都要敲一遍,还有if模块,for循环模块,难道没有快捷键,可以生成代码模块吗,答案是“有”. 操作步骤如下(汉化版WS): 1.Alt ...
- MyBatis自动生成代码示例
在项目中使用到mybatis时,都会选择自动生成实体类,Mapper,SqlMap这三个东东. 手头上在用的又不方便,找了下网上,其实有很多文章,但有些引用外部文件时不成功,也不方便,所以重新整理了下 ...
- mybatis自动生成代码
使用maven集成mybatis-generator插件生成Mybatis的实体类,DAO接口和Map映射文件 本例中,使用的是mysql数据库 前提:表已经建好 mybatis框架的jar包,数据 ...
随机推荐
- ZOJ 3606 Lazy Salesgirl ( 线段树 + 思路 )
卖切糕的小女孩 http://www.cnblogs.com/wuyiqi/archive/2012/04/28/2474672.html #include <cstdio> #inclu ...
- 软工实践 - 第十九次作业 Alpha 冲刺 (10/10)
队名:起床一起肝活队 组长博客:https://www.cnblogs.com/dawnduck/p/10046955.htmlz 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 ...
- Ajax---概念介绍
Ajax不是某种编程语言,是一种在无需重新加载整个网页的情况下能够更新部分网页的技术. 运用HTML和CSS来实现页面,表达信息: 运用XMLHttpRequest和Web服务器进行数据的异步交换: ...
- hexo站点地图
将网站链接提交到百度 百度搜索引擎提交入口 有三种验证方式,我选择Html标签验证,在themes\next\layout\_partials\head.swing中添加验证代码: <meta ...
- BZOJ3238 [Ahoi2013]差异 【后缀数组 + 单调栈】
题目链接 BZOJ3238 题解 简单题 经典后缀数组 + 单调栈套路,求所有后缀\(lcp\) #include<iostream> #include<cstdio> #in ...
- BZOJ2208 [Jsoi2010]连通数 【图的遍历】
题目 输入格式 输入数据第一行是图顶点的数量,一个正整数N. 接下来N行,每行N个字符.第i行第j列的1表示顶点i到j有边,0则表示无边. 输出格式 输出一行一个整数,表示该图的连通数. 输入样例 3 ...
- 【CF Edu 28 A. Curriculum Vitae】
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- Codeforces Round #281 (Div. 2) B 模拟
B. Vasya and Wrestling time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- 乌龟git
相关操作 链接:http://www.cnblogs.com/hbujt/p/5554038.html 避免乌龟每次输入账户密码 链接:http://www.cnblogs.com/bldf/p/60 ...
- POJ1679 The Unique MST
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26782 Accepted: 9598 Description Give ...