原来在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配置相配合 ...
随机推荐
- 毒瘤阅读题 LightOJ - 1220
Mysterious Bacteria LightOJ - 1220 https://vjudge.net/problem/LightOJ-1220 "Each case starts wi ...
- 应用安全 - 软件漏洞 - 泛微OA漏洞汇总
SQL注入 前台SQL注入 用户名:admin' or password like 'c4ca4238a0b923820dcc509a6f75849b' and 'a'='a 密码: 1 验证页面参数 ...
- boost的libboost_system问题
最近把cpp代码从开发机放到eclipse时,遇到了不少路径问题. 安装boost的时候,其实很简单 wget http://sourceforge.net/projects/boost/files/ ...
- Python3的基本数据类型
2.1. Python3中六个标准的基本数据类型: Number(数字) String(字符串) Sets(集合) Tuple(元组) List(列表) Dictionary(字典) 2.2. Pyt ...
- airtest自动化中的poco+python连接手机实现ui自动化
airtest:http://airtest.netease.com/docs/docs_AirtestIDE-zh_CN/index.html官网地址 AirtestIDE:跨平台的UI自动化测试编 ...
- PHP中的异常和错误(转载)
博客好久没有更新了,实在惭愧,最近在忙人生大事,哈哈!这段时间没有看什么新的东西,结合项目中遇到的PHP异常处理问题,我又重新梳理了之前模糊的概念,希望对大家理解PHP异常处理有所帮助. 请一定要注意 ...
- Dev Express之ImageComboBoxEdit,RepositoryItemImageComboBox使用方式
Dev Express之ImageComboBoxEdit,RepositoryItemImageComboBox使用方式 1.使用ImageComboBoxEdit实现下拉框键值数据函数 publ ...
- Spark Thrift Server
ThriftServer是一个JDBC/ODBC接口,用户可以通过JDBC/ODBC连接ThriftServer来访问SparkSQL的数据.ThriftServer在启动的时候,会启动了一个Spar ...
- WPF的DataTrigger使用
首先创建一个空的项目 然后看看前台写的代码,如下图所示 <Grid> <StackPanel HorizontalAlignment="Center" Verti ...
- 解决javax.servlet.jsp.JspException cannot be resolved to a type
转自:https://blog.csdn.net/fengspg/article/details/41645159