原来在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配置相配合 ...
随机推荐
- 怎么用 pytorch 查看 GPU 信息
如果你用的 Keras 或者 TensorFlow, 请移步 怎么查看keras 或者 tensorflow 正在使用的GPU In [1]: import torch In [2]: torch.c ...
- python基础-6.1 match search findall group(s) 区别
import re # match findall经常用 # re.match() #从开头匹配,没有匹配到对象就返回NONE # re.search() #浏览全部字符,匹配第一个符合规则的字符串 ...
- JAVA总结--java基本语法
static :静态的~ static :静态变量.静态方法: 被修饰的成员变量或者方法独立于该类的任何对象,只要该类被加载,被修饰的成员变量或者方法就存在并可以使用. 用public修饰的stat ...
- RESUful风格
1.7 RESTful风格 1.7.1 RESTful风格介绍 RESTful是一种软件架构风格! RESTful架构风格规定,数据的元操作,即CRUD(create, read, update和de ...
- HDU-3665 Seaside
XiaoY is living in a big city, there are N towns in it and some towns near the sea. All these towns ...
- ssh_exchange_identification: read: Connection reset by peer解决办法
使用本地终端连接centos服务器,提示ssh_exchange_identification: read: Connection reset by peer $ssh root@10.xxx.xxx ...
- Linux时间命令date
date:打印当前时间 date "+定制信息":自定义格式打印时间 - date "+%H":打印当前时间的小时数 - date "+%H%M%S& ...
- JavaScript、ES6中的类和对象
面向对象可以用于描述现实世界的事物,但是事物分为具体的(特指的)事物和抽象的(泛指的)事物. 面向对象思维的特点: 1.抽取(抽象)对象共有的属性和行为组织(封装)成一个类(模板) 2. ...
- HTML使用框架跳转到指定的节
内容区(links.html) <html> <body> <h2>Chapter 1</h2> <p>This chapter expla ...
- vue.js(18)--父组件向子组件传值
子组件是不能直接使用父组件中数据的,需要进行属性绑定(v-bind:自定义属性名=“msg”),绑定后需要在子组件中使用props[‘自定义属性名’]数组来定义父组件的自定义名称. props数组中的 ...