原来在UNITY中使用system.io下的所有函数都可以用相对路径 : Assets/xx
代码如下图,这样就不用在绝对路径和相对路径之间不断转换了。
想要得到绝对路径时就傅 Application.dataPath + xxx
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
public class abbuilder
{
[MenuItem("AssetBundle/BuildABx")]
public static void BuildAB()
{
var rootPath = "Assets/ResInGame"; if (!Directory.Exists(rootPath))
{
Debug.LogError("file not exist:" + rootPath);
return;
} var files = Directory.GetFiles(rootPath, "*", SearchOption.AllDirectories);
var abBuilds = new List<AssetBundleBuild>(files.Length / ); //估计值,肯定够了,因为每个文件夹也有META文件 var stopwt = System.Diagnostics.Stopwatch.StartNew();
var t1 = stopwt.ElapsedMilliseconds; foreach (var item in files)
{
var dir = Path.GetDirectoryName(item);
var fileName = Path.GetFileName(item); if (item.EndsWith(".meta"))
continue; var relativeDir = item.Substring();
var abBuild = new AssetBundleBuild();
abBuild.assetBundleName = relativeDir;
abBuild.assetNames = new string[] { item };
abBuild.assetBundleVariant = "ab";
//Debug.Log(item + "\n" + fileName + "\n"); abBuilds.Add(abBuild);
} var abPath = Application.dataPath.Substring(, Application.dataPath.Length-) + "Bundles"; if (!Directory.Exists(abPath))
{
Directory.CreateDirectory(abPath);
} var dt1 = stopwt.ElapsedMilliseconds - t1; BuildPipeline.BuildAssetBundles(abPath, abBuilds.ToArray(), BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.Android); var dt2 = stopwt.ElapsedMilliseconds - t1 - dt1; EditorUtility.DisplayDialog("", dt1 +"," + dt2, "ok");
}
}
原来在UNITY中使用system.io下的所有函数都可以用相对路径 : Assets/xx的更多相关文章
- 在Unity中高效工作(下)
原地址:http://www.unity蛮牛.com/thread-20005-1-1.html Tips for Creating Better Games and Working More Eff ...
- Unity报与System.IO相关的错误
比如这个: Type `System.IO.FileInfo' does not contain a definition for `OpenText' and no extension method ...
- unity中 UGUI的按下、拖动接口事件的实现
using UnityEngine; using System.Collections.Generic; using DG.Tweening; using UnityEngine.EventSyste ...
- 关于Unity中获得自己节点下的组件的简易方法
在一个节点下挂载一个脚本,脚本里面要使用自己节点下的其他组件 用法1 private Light light; void Start () { this.light=this.GetComponent ...
- IIS目录下文件共享后System.IO.File.Exists返回false
场景:在iis目录下,因为特殊需要共享一个文件夹,给到其他的技术人员访问,突然发现小小的操作,搞“大”了,使用 string path = Server.MapPath("~/file/te ...
- 【C#遗补】获取应用程序路径之System.IO.Directory.GetCurrentDirectory和System.Windows.Forms.Application.StartupPath的区别
原文:[C#遗补]获取应用程序路径之System.IO.Directory.GetCurrentDirectory和System.Windows.Forms.Application.StartupPa ...
- C#、.Net代码精简优化(空操作符(??)、as、string.IsNullOrEmpty() 、 string.IsNullOrWhiteSpace()、string.Equals()、System.IO.Path 的用法)
一.空操作符(??)在程序中经常会遇到对字符串或是对象判断null的操作,如果为null则给空值或是一个指定的值.通常我们会这样来处理: .string name = value; if (name ...
- 移植UE4的模型操作到Unity中
最近在Unity上要写一个东东,功能差不多就是在Unity编辑器上的旋转,移动这些,在手机上也能比较容易操作最好,原来用Axiom3D写过一个类似的,有许多位置并不好用,刚好在研究UE4的源码,在模型 ...
- 在.net程序中使用System.Net.Mail来发送邮件
System.Net.Mail是微软自家提供的工具,在.net程序中可以使用该空间中的SmtpClient实例来实现邮件的发送. 使用System.Net.Mail空间与Web.config配置相配合 ...
随机推荐
- web service接口 wsdl和asmx有什么区别
没有区别,只是后缀名的区别.Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求,轻量级的独立 ...
- Node.js实战9:用EventEmitter触发和响应事件。
Nodejs有一个重要的事件模块:EventEmitter. 它在Nodejs的内置及第三方模块中被大量使用,许多Nodejs项目的架构都是用它实现的. 可见,EventEmitter对于学习Node ...
- openWRT利用mac地址限制局域网内设备访问外网
利用iptable设置防火墙: iptables -A INPUT -p tcp -m mac --mac-source 44:94:FC:25:68:8D --dport 80 -j DROP
- Java 基础知识整理 (待整理)
JVM之类加载器(ClassLoader)基本介绍 类加载器用于将class文件加载到JVM中去执行.下面介绍类加载器涉及到的基本概念和加载基本过程. 一.Java虚拟机与程序的生命周期 在运行Jav ...
- oracle-第N篇加强专题
1.Oracle数据库日期类型 1>日期的比较 2>日期格式化 2.Oracle字符串类型 1>常用函数
- ARM汇编3
一. 什么是协处理器? 1.1. SoC内部另一处理核心,协助主CPU实现某些功能,被主CPU调用执行一定任务. 1.2. ARM设计上支持多达16个协处理器,但是一般SoC只实现其中的CP15.(c ...
- mysql自动备份脚本
linux系统mysql5.6版本实现自动备份步骤 1.sudo mysql --help | grep my.cnf 查找my.cnf文件2.在文件中添加如下行实现免输入密码[mysqldump]u ...
- LeetCode Lect7 堆及其应用
概述 堆是一颗完全二叉树.分为大根堆(父节点>=所有的子节点)和小根堆(父节点<=所有的子节点). 插入.删除堆顶都是O(logN),查询最值是O(1). 完全二叉树(Complete B ...
- github(1):
1.目的:借助github托管项目带按摩 2.仓库:创建一个Repository 3.收藏(Start):仓库主页start按钮,意思是收藏项目的人数,在github上如果有一个项目获得100个sta ...
- PHP表单数组的具体使用方法介绍
< input name="a[]" value="1" /> < input name="a[]" value=&quo ...