• 原来在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 + "
    " + fileName + "
    ");
    
                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");
        }
    }
  • 相关阅读:
    bzoj3527: [Zjoi2014]力 fft
    bzoj3295: [Cqoi2011]动态逆序对 cdq分治
    快速读入fread
    km板子(二分图最大权匹配)
    spfa毒瘤算法
    牛客网暑期ACM多校训练营(第三场)DEncrypted String Matching fft
    P4173 残缺的字符串 fft
    圆和多边形交模板
    hdu多校2C
    Codeforces Round #449 (Div. 1)C
  • 原文地址:https://www.cnblogs.com/timeObjserver/p/11008823.html
Copyright © 2020-2023  润新知