static public void CreateAssetbundleForChildren()
 {
     if (AssetBundleEditorHelper.HasValidSelection())
     {
         bool checkCreate = EditorUtility.DisplayDialog("CreateAssetbundleForChildren Warning",
                                                        "Create assetbundle for all children of cur selected objects will reset assetbundles which contains this dir, continue ?",
                                                        "Yes", "No");
         if (!checkCreate)
         {
             return;
         }
         Object[] selObjs = Selection.objects;
         AssetBundleEditorHelper.CreateAssetbundleForChildren(selObjs);
         List <string> removeList = AssetBundleEditorHelper.RemoveAssetbundleInParents(selObjs);
         removeList.AddRange(AssetBundleEditorHelper.RemoveAssetbundleInChildren(selObjs, true, false));
         string removeStr = string.Empty;
         int    i         = 0;
         foreach (string str in removeList)
         {
             removeStr += string.Format("[{0}]{1}\n", ++i, str);
         }
         if (removeList.Count > 0)
         {
             Debug.Log(string.Format("CreateAssetbundleForChildren done!\nRemove list :" +
                                     "\n-------------------------------------------\n" +
                                     "{0}" +
                                     "\n-------------------------------------------\n",
                                     removeStr));
         }
     }
 }
示例#2
0
        static public void ListAssetbundleDependencis(bool isAll)
        {
            if (AssetBundleEditorHelper.HasValidSelection())
            {
                string localFilePath = PackageUtils.GetCurBuildSettingAssetBundleManifestPath();

                Object[] selObjs  = Selection.objects;
                var      depsList = AssetBundleEditorHelper.GetDependancisFormBuildManifest(localFilePath, selObjs, isAll);
                if (depsList == null)
                {
                    return;
                }

                depsList.Sort();
                string depsStr = string.Empty;
                int    i       = 0;
                foreach (string str in depsList)
                {
                    depsStr += string.Format("[{0}]{1}\n", ++i, str);
                }

                string selStr = string.Empty;
                i = 0;
                foreach (Object obj in selObjs)
                {
                    selStr += string.Format("[{0}]{1};", ++i, AssetDatabase.GetAssetPath(obj));
                }
                Debug.Log(string.Format("Selection({0}) directly depends on the following assetbundles:" +
                                        "\n-------------------------------------------\n" +
                                        "{1}" +
                                        "\n-------------------------------------------\n",
                                        selStr,
                                        depsStr));
            }
        }
        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();
        }
示例#4
0
        /// <summary>
        /// 写入地址
        /// </summary>
        /// <param name="outFile"></param>
        /// <param name="outLines"></param>
        public static void WriteAssetsAddress()
        {
            string assetsaddress = AssetBundleUtility.PackagePathToAssetsPath(AssetBundleConfig.AssetsaddressConfig);

            if (!GameUtility.SafeWriteAllLines(assetsaddress, addressList.ToArray()))
            {
                Debug.LogError("BuildPathMapping failed!!! try rebuild it again!");
            }
            else
            {
                AssetDatabase.Refresh();
                AssetBundleEditorHelper.CreateAssetbundleForCurrent(assetsaddress);
                Debug.Log("BuildPathMapping success...");
            }
            AssetDatabase.Refresh();
        }
 static public void ListAssetDependencis()
 {
     if (AssetBundleEditorHelper.HasValidSelection())
     {
         Object[] selObjs = Selection.objects;
         string   depsStr = AssetBundleEditorHelper.GetDependencyText(selObjs, false);
         string   selStr  = string.Empty;
         int      i       = 0;
         foreach (Object obj in selObjs)
         {
             selStr += string.Format("[{0}]{1};", ++i, AssetDatabase.GetAssetPath(obj));
         }
         Debug.Log(string.Format("Selection({0}) depends on the following assets:" +
                                 "\n-------------------------------------------\n" +
                                 "{1}" +
                                 "\n-------------------------------------------\n",
                                 selStr,
                                 depsStr));
         AssetBundleEditorHelper.SelectDependency(selObjs, false);
     }
 }
示例#6
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();
        }