代码如下图,这样就不用在绝对路径和相对路径之间不断转换了。

想要得到绝对路径时就傅 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的更多相关文章

  1. 在Unity中高效工作(下)

    原地址:http://www.unity蛮牛.com/thread-20005-1-1.html Tips for Creating Better Games and Working More Eff ...

  2. Unity报与System.IO相关的错误

    比如这个: Type `System.IO.FileInfo' does not contain a definition for `OpenText' and no extension method ...

  3. unity中 UGUI的按下、拖动接口事件的实现

    using UnityEngine; using System.Collections.Generic; using DG.Tweening; using UnityEngine.EventSyste ...

  4. 关于Unity中获得自己节点下的组件的简易方法

    在一个节点下挂载一个脚本,脚本里面要使用自己节点下的其他组件 用法1 private Light light; void Start () { this.light=this.GetComponent ...

  5. IIS目录下文件共享后System.IO.File.Exists返回false

    场景:在iis目录下,因为特殊需要共享一个文件夹,给到其他的技术人员访问,突然发现小小的操作,搞“大”了,使用 string path = Server.MapPath("~/file/te ...

  6. 【C#遗补】获取应用程序路径之System.IO.Directory.GetCurrentDirectory和System.Windows.Forms.Application.StartupPath的区别

    原文:[C#遗补]获取应用程序路径之System.IO.Directory.GetCurrentDirectory和System.Windows.Forms.Application.StartupPa ...

  7. C#、.Net代码精简优化(空操作符(??)、as、string.IsNullOrEmpty() 、 string.IsNullOrWhiteSpace()、string.Equals()、System.IO.Path 的用法)

    一.空操作符(??)在程序中经常会遇到对字符串或是对象判断null的操作,如果为null则给空值或是一个指定的值.通常我们会这样来处理: .string name = value; if (name ...

  8. 移植UE4的模型操作到Unity中

    最近在Unity上要写一个东东,功能差不多就是在Unity编辑器上的旋转,移动这些,在手机上也能比较容易操作最好,原来用Axiom3D写过一个类似的,有许多位置并不好用,刚好在研究UE4的源码,在模型 ...

  9. 在.net程序中使用System.Net.Mail来发送邮件

    System.Net.Mail是微软自家提供的工具,在.net程序中可以使用该空间中的SmtpClient实例来实现邮件的发送. 使用System.Net.Mail空间与Web.config配置相配合 ...

随机推荐

  1. 倾旋之slack主题协同

    源:https://pocketcorp.slack.com/join/shared_invite/enQtNTk2MDYwNDA4NzU0LTg3ZGVlNDE5NWUzNjJhZTc1MDQ5MT ...

  2. git --> 工作使用流程

    [git]------git开发过程中的使用流程------[WangQi]   001.创建仓库 002.新建项目 003.初始化仓库  这一步不需要做 git init : 文件夹中会多出一个隐藏 ...

  3. docker--虚拟化

    1 什么是虚拟化 1.1 概念 在计算机中,虚拟化(英语:Virtualization)是一种资源管理技术,是将计算机的各种 实体资源,如服务器.网络.内存及存储等,予以抽象.转换后呈现出来,打破实体 ...

  4. C语言如何操作内存

    1.用变量名来访问内存(c语言对内存地址的封装.数据类型.函数名)--直接访问内存(使用地址) 如 int a; 编译器将申请32bit的内存(4个内存单元),同时将内存地址和变量名a绑定,操作a时, ...

  5. 剑指Offer编程题(Java实现)——二维数组中的查找

    题目描述 在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数 ...

  6. HDU 1069 Monkey and Banana dp 题解

    HDU 1069 Monkey and Banana 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种 ...

  7. Antd-react-mobile项目学习中遇到的问题记录(持续更新)

    1.Error:The "injectBabelPlugin" helper has been deprecated as of v2.0. You can use customi ...

  8. FCKeditor用在JSP中的几点注意事项

    转自:https://blog.csdn.net/asinzy/article/details/3854127 本篇文章主要介绍了"FCKeditor用在JSP中的几点注意事项", ...

  9. python 简易小爬虫

    此脚本用于爬站点的下载链接,最终输出到txt文档中. 如果是没有防盗链设置的站点,也可以使用脚本中的下载函数尝试直接下载. 本脚本是为了短期特定目标设计的,如果使用它爬其它特征的资源链接需自行修改配置 ...

  10. left join on and和left join on where条件的困惑[转]

    外连接:left join(左联接) left outer join 返回包括左表中的所有记录和右表中联结字段相等的记录right join(右联接) right outer join返回包括右表中的 ...