原来在UNITY中使用system.io下的所有函数都可以用相对路径 : Assets/xx
生活随笔
收集整理的這篇文章主要介紹了
原来在UNITY中使用system.io下的所有函数都可以用相对路径 : Assets/xx
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
原來在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 / 2); //估計值,肯定夠了,因為每個文件夾也有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(17);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(0, Application.dataPath.Length-6) + "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");} }?
posted on 2019-06-12 12:06 時空觀察者9號 閱讀(...) 評論(...) 編輯 收藏
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的原来在UNITY中使用system.io下的所有函数都可以用相对路径 : Assets/xx的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SHADER 用 step替代 if-e
- 下一篇: 预置体很大的原因