public static void BuildVariantMapping(BuildTarget target, AssetBundleManifest manifest)
        {
            mappingList.Clear();
            string rootPath       = System.IO.Path.Combine(Application.dataPath, AssetBundleConfig.AssetsFolderName);
            string outputFilePath = System.IO.Path.Combine(rootPath, AssetBundleConfig.VariantsMapFileName);

            string[] allVariants = manifest.GetAllAssetBundlesWithVariant();

            // 处理带variants的assetbundle
            foreach (string assetbundle in allVariants)
            {
                // 该assetbundle中包含的所有asset的路径(相对于Assets文件夹),如:
                // Assets/AssetsPackage/UI/Prefabs/Language/[Chinese]/TestVariant.prefab
                // Assets/AssetsPackage/UI/Prefabs/Language/[English]/TestVariant.prefab
                // 在代码使用的加载路径中,它们被统一处理为
                // Assets/AssetsPackage/UI/Prefabs/Language/[Variant]/TestVariant.prefab
                // 这里的variant为chinese、english,在AssetBundleManager中设置启用的variant会自动对路径进行正确还原
                string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundle(assetbundle);
                if (assetPaths == null || assetPaths.Length == 0)
                {
                    UnityEngine.Debug.LogError("Empty assetbundle with variant : " + assetbundle);
                    continue;
                }
                // 自本节点向上找到Assetbundle所在
                AssetBundleImporter assetbundleImporter = AssetBundleImporter.GetAtPath(assetPaths[0]);
                while (assetbundleImporter != null && string.IsNullOrEmpty(assetbundleImporter.assetBundleVariant))
                {
                    assetbundleImporter = assetbundleImporter.GetParent();
                }
                if (assetbundleImporter == null || string.IsNullOrEmpty(assetbundleImporter.assetBundleVariant))
                {
                    UnityEngine.Debug.LogError("Can not find assetbundle with variant : " + assetbundle);
                    continue;
                }
                string assetbundlePath = assetbundleImporter.assetPath;
                if (assetbundlePath.EndsWith("/"))
                {
                    assetbundlePath = assetbundlePath.Substring(0, assetbundlePath.Length - 1);
                }
                // 由于各个Variant的内部结构必须完全一致,而Load时也必须完全填写,所以这里不需要关注到assetbundle具体的每个资源
                string nowNode     = System.IO.Path.GetFileName(assetbundlePath);
                string mappingItem = string.Format("{0}{1}{2}", assetbundle, PATTREN, nowNode);
                mappingList.Add(mappingItem);
            }
            mappingList.Sort();
            if (!GameUtility.SafeWriteAllLines(outputFilePath, mappingList.ToArray()))
            {
                Debug.LogError("BuildVariantMapping failed!!! try rebuild it again!");
            }
            else
            {
                AssetDatabase.Refresh();
                string outputFileAssetPath = GameUtility.FullPathToAssetPath(outputFilePath);
                AssetBundleEditorHelper.CreateAssetbundleForCurrent(outputFileAssetPath);
                Debug.Log("BuildVariantMapping success...");
            }
            AssetDatabase.Refresh();
        }
 public AssetBundleDispatcher(AssetBundleDispatcherConfig config)
 {
     this.config = config;
     assetsPath  = AssetBundleUtility.PackagePathToAssetsPath(config.PackagePath);
     importer    = AssetBundleImporter.GetAtPath(assetsPath);
     if (importer == null)
     {
         Debug.LogError("Asset path err : " + assetsPath);
     }
 }
Exemplo n.º 3
0
 public AssetBundleChecker(AssetBundleCheckerConfig config)
 {
     this.config = config;
     assetsPath  = AssetBundleUtility.PackagePathToAssetsPath(config.PackagePath);
     importer    = AssetBundleImporter.GetAtPath(assetsPath);
     if (importer == null || !importer.IsValid)
     {
         Logger.LogError($"定义的Package信息path:({assetsPath}) 没有找不到,请对比Asset/Editor/AssetBundle/xxx和Asset/AssetsPackage/xxx");
     }
 }
        public static void CreateAssetbundleForChildren(string assetPath)
        {
            AssetBundleImporter importer = AssetBundleImporter.GetAtPath(assetPath);

            if (importer == null)
            {
                Debug.LogError(string.Format("importer null! make sure object at path({0}) is a valid assetbundle!", assetPath));
                return;
            }

            CreateAssetbundleForChildren(importer);
        }
Exemplo n.º 5
0
        public void CheckAssetBundleName()
        {
            if (!importer.IsValid)
            {
                return;
            }
            if (!AddressCofing2Lua.instance.addressList.Contains(assetsPath))
            {
                AddressCofing2Lua.instance.addressList.Add(assetsPath);
            }
            var checkerFilters = config.CheckerFilters;

            if (checkerFilters == null || checkerFilters.Count == 0)
            {
                //  Debug.LogError(importer.packagePath);
                importer.assetBundleName = assetsPath;
                // Debug.LogError(assetsPath);
            }
            else
            {
                foreach (var checkerFilter in checkerFilters)
                {
                    var relativePath = assetsPath;
                    if (!string.IsNullOrEmpty(checkerFilter.RelativePath))
                    {
                        relativePath = Path.Combine(assetsPath, checkerFilter.RelativePath);
                    }
                    var imp = AssetBundleImporter.GetAtPath(relativePath);
                    if (imp == null)
                    {
                        continue;
                    }
                    if (imp.IsFile)
                    {
                        importer.assetBundleName = assetsPath;
                        // Debug.LogError(assetsPath);
                        continue;
                    }
                    string[] objGuids = AssetDatabase.FindAssets(checkerFilter.ObjectFilter, new string[] { relativePath });
                    foreach (var guid in objGuids)
                    {
                        var path = AssetDatabase.GUIDToAssetPath(guid);
                        imp = AssetBundleImporter.GetAtPath(path);
                        imp.assetBundleName = assetsPath;
                        //Debug.LogError(assetsPath);
                    }
                }
            }
        }
Exemplo n.º 6
0
        public void CheckChannelName()
        {
            string channelAssetPath = Path.Combine(AssetBundleConfig.ChannelFolderName, config.PackagePath);

            channelAssetPath = AssetBundleUtility.PackagePathToAssetsPath(channelAssetPath) + ".bytes";
            if (!File.Exists(channelAssetPath))
            {
                GameUtility.SafeWriteAllText(channelAssetPath, "None");
                AssetDatabase.Refresh();
            }

            var imp = AssetBundleImporter.GetAtPath(channelAssetPath);

            imp.assetBundleName = assetsPath;
        }
        public static List <string> RemoveAssetBundleInChildren(string assetPath, bool containsSelf, bool countainsDirectly, REMOVE_TYPE removeType)
        {
            List <string>       removeList = new List <string>();
            AssetBundleImporter importer   = AssetBundleImporter.GetAtPath(assetPath);

            if (importer == null)
            {
                return(removeList);
            }

            //是否删除自身
            if (containsSelf && !string.IsNullOrEmpty(importer.assetBundleName))
            {
                removeList.Add(string.Format("{0}{1}", importer.assetPath,
                                             string.IsNullOrEmpty(importer.assetBundleVariant) ? null : string.Format("({0})", importer.assetBundleVariant)));
                importer.assetBundleName = null;
            }

            List <AssetBundleImporter> childImporter = importer.GetChildren();

            foreach (AssetBundleImporter child in childImporter)
            {
                if (!child.IsValid)
                {
                    continue;
                }

                if (!string.IsNullOrEmpty(child.assetBundleName) && countainsDirectly)
                {
                    if (removeType == REMOVE_TYPE.ALL ||
                        (removeType == REMOVE_TYPE.CHILDREN_DIR && child.IsFile == false) ||
                        (removeType == REMOVE_TYPE.CHILDREN_FILES && child.IsFile == true)
                        )
                    {
                        removeList.Add(string.Format("{0}{1}", child.assetPath,
                                                     string.IsNullOrEmpty(child.assetBundleVariant) ? null : string.Format("({0})", child.assetBundleVariant)));
                        child.assetBundleName = null;
                    }
                }
                if (!child.IsFile)
                {
                    // 为目录,递归:递归时containsSelf设置为false,是否删除本身由removeType确定
                    removeList.AddRange(RemoveAssetBundleInChildren(child.assetPath, false, true, removeType));
                }
            }
            return(removeList);
        }
Exemplo n.º 8
0
        public void CheckAssetBundleName()
        {
            if (importer == null || !importer.IsValid)
            {
                return;
            }

            var checkerFilters = config.CheckerFilters;

            if (checkerFilters == null || checkerFilters.Count == 0)
            {
                importer.assetBundleName = assetsPath;
            }
            else
            {
                foreach (var checkerFilter in checkerFilters)
                {
                    var relativePath = assetsPath;
                    if (!string.IsNullOrEmpty(checkerFilter.RelativePath))
                    {
                        relativePath = Path.Combine(assetsPath, checkerFilter.RelativePath);
                    }
                    var imp = AssetBundleImporter.GetAtPath(relativePath);
                    if (imp == null)
                    {
                        continue;
                    }
                    if (imp.IsFile)
                    {
                        importer.assetBundleName = assetsPath;
                        continue;
                    }
                    string[] objGuids = AssetDatabase.FindAssets(checkerFilter.ObjectFilter, new string[] { relativePath });
                    foreach (var guid in objGuids)
                    {
                        var path = AssetDatabase.GUIDToAssetPath(guid);
                        imp = AssetBundleImporter.GetAtPath(path);
                        imp.assetBundleName = assetsPath;
                    }
                }
            }
        }
Exemplo n.º 9
0
        ///// <summary>
        ///// 得到合适的FairyGUI AssetBundleName
        ///// </summary>
        public void CheckFairyGUIAssetBundleName()
        {
            if (!importer.IsValid)
            {
                return;
            }
            var checkerFilters = config.CheckerFilters;

            if (checkerFilters == null || checkerFilters.Count == 0)
            {
                importer.assetBundleName = assetsPath;
            }
            else
            {
                foreach (var checkerFilter in checkerFilters)
                {
                    var relativePath = assetsPath;
                    if (!string.IsNullOrEmpty(checkerFilter.RelativePath))
                    {
                        relativePath = Path.Combine(assetsPath, checkerFilter.RelativePath);
                    }
                    var imp = AssetBundleImporter.GetAtPath(relativePath);
                    if (imp == null)
                    {
                        continue;
                    }
                    if (imp.IsFile)
                    {
                        int position = relativePath.LastIndexOf(".");
                        relativePath = position > -1 ? relativePath.Substring(0, position) : relativePath;

                        int isResIndex = relativePath.IndexOf("@");
                        if (isResIndex > -1)
                        {
                            relativePath = relativePath.Substring(0, isResIndex) + "_res";
                        }
                        //Debug.Log(">>>>>>>>>>:" + relativePath);
                    }
                    importer.assetBundleName = relativePath;
                }
            }
        }
        public static List <string> RemoveAssetBundleInParents(string assetPath)
        {
            List <string>       removeList = new List <string>();
            AssetBundleImporter importer   = AssetBundleImporter.GetAtPath(assetPath);

            if (importer == null)
            {
                return(removeList);
            }

            AssetBundleImporter parentImporter = importer.GetParent();

            while (parentImporter != null)
            {
                if (!string.IsNullOrEmpty(parentImporter.assetBundleName))
                {
                    removeList.Add(string.Format("{0}{1}", parentImporter.assetPath,
                                                 string.IsNullOrEmpty(parentImporter.assetBundleVariant) ? null : string.Format("({0})", parentImporter.assetBundleVariant)));
                    parentImporter.assetBundleName = null;
                }
                parentImporter = parentImporter.GetParent();
            }
            return(removeList);
        }
Exemplo n.º 11
0
 public AssetBundleChecker(AssetBundleCheckerConfig config)
 {
     this.config = config;
     assetsPath  = AssetBundleUtility.PackagePathToAssetsPath(config.PackagePath);
     importer    = AssetBundleImporter.GetAtPath(assetsPath);
 }
Exemplo n.º 12
0
        public static void BuildPathMapping(AssetBundleManifest manifest)
        {
            mappingList.Clear();
            string outputFilePath = AssetBundleUtility.PackagePathToAssetsPath(AssetBundleConfig.AssetsPathMapFileName);

            string[] allAssetbundles = manifest.GetAllAssetBundles();
            string[] allVariants     = manifest.GetAllAssetBundlesWithVariant();

            List <string> assetbundlesWithoutVariant = null;
            List <string> variantWithoutDeplicate    = null;

            ProsessVariant(allAssetbundles, allVariants, out assetbundlesWithoutVariant, out variantWithoutDeplicate);

            // 处理所有不带variants的assetbundle
            foreach (string assetbundle in assetbundlesWithoutVariant)
            {
                // 该assetbundle中包含的所有asset的路径(相对于Assets文件夹),如:
                // Assets/AssetsPackage/UI/Prefabs/View/UILoading.prefab
                string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundle(assetbundle);
                foreach (string assetPath in assetPaths)
                {
                    string packagePath = AssetBundleUtility.AssetsPathToPackagePath(assetPath);
                    if (!addressList.Contains(packagePath))
                    {
                        addressList.Add(packagePath);
                    }
                    string mappingItem = string.Format("{0}{1}{2}", assetbundle, PATTREN, packagePath);
                    mappingList.Add(mappingItem);
                }
            }
            // 处理带variants的assetbundle(已经去重)
            // string variant = "[" + AssetBundleConfig.VariantMapParttren + "]";
            foreach (string assetbundle in variantWithoutDeplicate)
            {
                // 该assetbundle中包含的所有asset的路径(相对于Assets文件夹),如:
                // Assets/AssetsPackage/UI/Prefabs/Language/[Chinese]/TestVariant.prefab
                // Assets/AssetsPackage/UI/Prefabs/Language/[English]/TestVariant.prefab
                // 由于已经去重,以上条目有且仅有一条出现
                string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundle(assetbundle);
                if (assetPaths == null || assetPaths.Length == 0)
                {
                    UnityEngine.Debug.LogError("Empty assetbundle with variant : " + assetbundle);
                    continue;
                }
                // 自本节点向上找到Assetbundle所在
                AssetBundleImporter assetbundleImporter = AssetBundleImporter.GetAtPath(assetPaths[0]);
                while (assetbundleImporter != null && string.IsNullOrEmpty(assetbundleImporter.assetBundleVariant))
                {
                    assetbundleImporter = assetbundleImporter.GetParent();
                }
                if (assetbundleImporter == null || string.IsNullOrEmpty(assetbundleImporter.assetBundleVariant))
                {
                    UnityEngine.Debug.LogError("Can not find assetbundle with variant : " + assetbundle);
                    continue;
                }
                string assetbundlePath = assetbundleImporter.assetPath;
                if (assetbundlePath.EndsWith("/"))
                {
                    assetbundlePath = assetbundlePath.Substring(0, assetbundlePath.Length - 1);
                }
                // 将拿掉[Variant]目录名如:
                // Assets/AssetsPackage/UI/Prefabs/Language/TestVariant.prefab
                // 用此种方式可以统一路径,使加载Assetbundle时的路径与具体激活的variant无关
                string nowRoot = GameUtility.FormatToUnityPath(System.IO.Path.GetDirectoryName(assetbundlePath));
                foreach (string assetPath in assetPaths)
                {
                    string nowAsset     = assetPath.Replace(assetbundlePath, "");
                    string nowAssetPath = nowRoot + nowAsset;
                    string packagePath  = AssetBundleUtility.AssetsPathToPackagePath(nowAssetPath);
                    if (!addressList.Contains(packagePath))
                    {
                        addressList.Add(packagePath);
                    }
                    string mappingItem = string.Format("{0}{1}{2}", RemoveVariantSuffix(assetbundle), PATTREN, packagePath);
                    mappingList.Add(mappingItem);
                }
            }
            mappingList.Sort();
            addressList.Sort();
            if (!GameUtility.SafeWriteAllLines(outputFilePath, mappingList.ToArray()))
            {
                Debug.LogError("BuildPathMapping failed!!! try rebuild it again!");
            }
            else
            {
                AssetDatabase.Refresh();
                AssetBundleEditorHelper.CreateAssetbundleForCurrent(outputFilePath);
                Debug.Log("BuildPathMapping success...");
            }
            AssetDatabase.Refresh();
        }