Ejemplo n.º 1
0
        /// <summary>
        /// Build Asset Path = Unity Asset Path去掉"Assets/"
        /// 文件名需要特殊处理, 文件名等于前面的目录拼接起来,确保文件名唯一
        /// 可以进行过滤, 从一个路径,导出到任意自定义路径的AssetBundle
        /// </summary>
        /// <param name="unityAssetPath"></param>
        /// <returns></returns>
        public static string GetBuildAssetPath(string unityAssetPath)
        {
            var assetPrefix    = "Assets/";
            var cleanAssetPath = unityAssetPath.Replace("\\", "/");

            // 去掉空格
            cleanAssetPath = cleanAssetPath.Replace(" ", "_");

            // 无前缀直接返回, 但要修改文件名加上Internal,防止AssetBundle重名冲突
            if (!cleanAssetPath.StartsWith(assetPrefix))
            {
                var dirPath  = Path.GetDirectoryName(cleanAssetPath);
                var fileName = "Internal_" + Path.GetFileName(cleanAssetPath);
                var retPath  = String.Format("{0}/{1}", dirPath, fileName);
                if (BuildAssetPathFilter != null)
                {
                    retPath = BuildAssetPathFilter(retPath);
                }
                return(ResourceDepUtils.GetBuildPath(retPath));
            }

            // 去掉前缀
            cleanAssetPath = cleanAssetPath.Substring(assetPrefix.Length,
                                                      cleanAssetPath.Length - assetPrefix.Length);

            // 过滤器
            if (BuildAssetPathFilter != null)
            {
                cleanAssetPath = BuildAssetPathFilter(cleanAssetPath);
            }

            return(ResourceDepUtils.GetBuildPath(cleanAssetPath));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取资源打包相对路径,该路径跟Unity目录布置完全一致,但经过特殊字符处理
        /// </summary>
        /// <param name="object"></param>
        /// <returns></returns>
        public static string GetBuildAssetPath(Object @object)
        {
            var unityAssetPath = AssetDatabase.GetAssetPath(@object);

            var uAssetType = GetUnityAssetType(unityAssetPath);

            if (uAssetType == UnityAssetType.Builtin || uAssetType == UnityAssetType.Memory)
            {
                // 如果是Inner 类型材质, 自定义路径
                var depObjType = @object.GetType();
                Func <Object, string> getNameFunc;
                if (_buildInAssetType2BuildAssetPath.TryGetValue(depObjType, out getNameFunc))
                {
                    var inPath = getNameFunc(@object);
                    if (BuildAssetPathFilter != null)
                    {
                        inPath = BuildAssetPathFilter(inPath);
                    }
                    return(ResourceDepUtils.GetBuildPath(inPath));
                }
                else
                {
                    // 无视Mono Scrpt BuiltIn类型
                    if (depObjType != typeof(MonoScript))
                    {
                        Log.Error("Un handle Libray builtin resource, Type:{0}, Name: {1}", depObjType, @object.name);
                    }
                }
            }

            return(GetBuildAssetPath(unityAssetPath));
        }
Ejemplo n.º 3
0
    void TestLoadLevelAdditiveAsync()
    {
#if !(UNITY_5 || UNITY_2017)
        Log.Info("Load Scene");
        ResourceDepUtils.LoadLevelAdditiveAsync("BundleResources/NGUI/TestNGUI.unity");
#else
        Log.LogError("Not support on Unity 5.x");
#endif
    }
Ejemplo n.º 4
0
    public IEnumerator LoadUIAsset(CUILoadState openState, UILoadRequest request)
    {
        var name = openState.TemplateName;
        // 具体加载逻辑
        // manifest
        string manifestPath = ResourceDepUtils.GetBuildPath(string.Format("BundleResources/NGUI/{0}.prefab.manifest{1}", name,
                                                                          AppEngine.GetConfig(KEngineDefaultConfigs.AssetBundleExt)));
        var manifestLoader = KBytesLoader.Load(manifestPath, KResourceInAppPathType.PersistentAssetsPath, KAssetBundleLoaderMode.PersitentDataPathSync);

        while (!manifestLoader.IsCompleted)
        {
            yield return(null);
        }
        var manifestBytes = manifestLoader.Bytes;

        manifestLoader.Release(); // 释放掉文本字节
        var utf8NoBom    = new UTF8Encoding(false);
        var manifestList = utf8NoBom.GetString(manifestBytes).Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);

        for (var i = 0; i < manifestList.Length; i++)
        {
            var depPath   = manifestList[i] + AppEngine.GetConfig(KEngineDefaultConfigs.AssetBundleExt);
            var depLoader = KAssetFileLoader.Load(depPath);
            while (!depLoader.IsCompleted)
            {
                yield return(null);
            }
        }
        string path = ResourceDepUtils.GetBuildPath(string.Format("BundleResources/NGUI/{0}.prefab{1}", name, KEngine.AppEngine.GetConfig("AssetBundleExt")));

        var assetLoader = KStaticAssetLoader.Load(path);

        openState.UIResourceLoader = assetLoader; // 基本不用手工释放的
        while (!assetLoader.IsCompleted)
        {
            yield return(null);
        }
        request.Asset = assetLoader.TheAsset;
    }
Ejemplo n.º 5
0
 void TestLoadLevelAdditiveAsync()
 {
     Logger.Log("Load Scene");
     ResourceDepUtils.LoadLevelAdditiveAsync("BundleResources/NGUI/TestNGUI.unity");
 }