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

想要得到绝对路径时就傅 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. spring,springMVC的优点和区别

    spring 是是一个开源框架,是为了解决企业应用程序开发,功能如下◆目的:解决企业应用开发的复杂性◆功能:使用基本的JavaBean代替EJB,并提供了更多的企业应用功能◆范围:任何Java应用简单 ...

  2. 视频格式转换.ZC资料

    1.20191013: ZC:这些都是 2015年做的尝试,之前貌似没有记录下来,现在 再次用到,把用到的记录下来: ZC: (1) 使用的视频格式转换工具是 "??/XiGua Yings ...

  3. c#工厂模式

    创建一个抽象类: public abstract class Test {  public abstract void Print();//输出信息} 创建输出123的测试类 public class ...

  4. [Python3 填坑] 017 实例方法、静态方法、类方法的区别

    目录 1. print( 坑的信息 ) 2. 开始填坑 2.1 先上例子 2.2 分析 1. print( 坑的信息 ) 挖坑时间:2019/04/07 明细 坑的编码 内容 Py024-1 实例方法 ...

  5. [2019南京网络赛D题]Robots

    题目链接 2019.9.2更新 第二天睡醒想了想发现好像搜一遍就可以过,赛时写的花里胡哨的还错了,太菜了QAQ #include<bits/stdc++.h> using namespac ...

  6. PTA第二题

    #include<string.h> #include<stdio.h> #include<malloc.h> ]; ][]={"ling",& ...

  7. CentOS安装Python3.x

    安装python3.6可能使用的依赖# yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqli ...

  8. Vue+Element-Ui 异步表单效验

    简单的效验 Form 组件提供了表单验证的功能,只需要通过 rules 属性传入约定的验证规则,并将 Form-Item 的 prop 属性设置为需校验的字段名 /* ruleForm :表单绑定的数 ...

  9. Jquery WEUI 滚动加载(infinite)不触发

    源代码:(1.0.1版本) Infinite.prototype.scroll = function() { var container = this.container; var offset = ...

  10. 树——minimum-depth-of-binary-tree(二叉树的最小深度)

    问题: Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the s ...