zoukankan      html  css  js  c++  java
  • 原来在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");
        }
    }
  • 相关阅读:
    go_接口
    go_封装
    go_结构体和方法
    go_字符和字符串处理
    go_Map
    为啥别人运行程序那么快,而你的却是龟速?
    大一新生开发的小工具火了!不一样的Python编程体验,现在的新生都这么厉害的吗
    十七种方法轻松解决PyTorch训练速度慢!
    Leetcode 1577 数的平方等于两数乘积的方法数
    C++11的decltype关键字
  • 原文地址:https://www.cnblogs.com/timeObjserver/p/11008823.html
Copyright © 2011-2022 走看看