static void AddAssetBundleToBuildMap(AssetBundleBuild[] buildMap, int position, AssetBundleManageData data, AssetBundleData assetbundle)
        {
            if (assetbundle.GetAllContents().Count <= 0)
            {
                buildMap[position].assetBundleName = "noname";
                buildMap[position].assetNames      = null;
                return;
            }
            // add all path to list
            List <string> files = new List <string>();

            foreach (var path in assetbundle.GetAllContentsPath())
            {
                if (File.Exists(path))
                {
                    files.Add(path);
                }
            }

            Debug.Log(nestString + "Adding Build " + assetbundle.File);

            buildMap[position].assetBundleName = assetbundle.File;
            Debug.Log("There're " + files.ToArray().Length + " file in " + assetbundle.File + " bundle. Created in " + assetbundle.Directory);
            buildMap[position].assetNames = files.ToArray();
        }
        // Check if assets of assetbundle is updated
        static bool CheckUpdateOfBundleAssets(AssetBundleManageData data, AssetBundleData assetbundle)
        {
            if (assetbundle.GetAllContents().Count <= 0)
            {
                return(false);
            }
            List <string> files = new List <string>();

            foreach (var path in assetbundle.GetAllContentsPath())
            {
                if (File.Exists(path))
                {
                    files.Add(path);
                }
            }
            var targets = new BuildTarget[] { EditorUserBuildSettings.activeBuildTarget };

#if !DLL
            if (assetbundle.PlatformFolder && data.multiPlatform && 0 < data.targets.Count)
            {
                targets = data.targets.ToArray();
            }
#endif
            List <string> platformList = new List <string>();
            foreach (BuildTarget target in targets)
            {
                var path = assetbundle.Path;
#if !DLL
                if (assetbundle.PlatformFolder)
                {
                    var platformFolder = AssetBundleManager.GetPlatformFolder(target);
                    if (platformList.Contains(platformFolder))
                    {
                        continue;
                    }
                    platformList.Add(platformFolder);
                    path = GetFullPath(assetbundle, target);
                }
#endif
                if (AssetBundleUtility.CheckUpdateOfBundleAssets(files.ToArray(), path, (BuildAssetBundleOptions)assetbundle.Options))
                {
                    return(true);
                }
            }
            return(false);
        }
        static bool CreateAssetBundle(AssetBundleManageData data, AssetBundleData assetbundle, bool rebuild, bool dependency)
        {
            if (assetbundle.GetAllContents().Count <= 0)
            {
                return(false);
            }
            // add all path to list
            List <string> files = new List <string>();

            foreach (var path in assetbundle.GetAllContentsPath())
            {
                if (File.Exists(path))
                {
                    files.Add(path);
                }
            }
            // add special list asset for system
            BundleAssetList list     = null;
            string          listpath = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(data)) + "/list/" + assetbundle.File + "/list.asset";   //Application.temporaryCachePath + "/" + "list.asset";

            if (!assetbundle.ForStreamedScene)
            {
                list        = CreateInstance <BundleAssetList>();
                list.Assets = files.Select(file => {
                    FileInfo info         = new FileInfo(file);
                    BundleAssetInfo asset = new BundleAssetInfo(info.Name);
                    return(asset);
                }).ToArray();

                var directory = System.IO.Path.GetDirectoryName(listpath).Substring("Assets".Length);
                System.IO.Directory.CreateDirectory(Application.dataPath + directory);
                AssetDatabase.CreateAsset(list, listpath);
                //files.Add(listpath);
                AssetBundleUtility.AssetList = list;
                // BundleAssetList.cs(not exist file "BundleAssetList.cs" with DLL)
                //string bundleAssetsListPath = "Assets/" + Path.GetDirectoryName(AssetBundleManager.SettingDataPath) + "/Scripts/BundleAssetList.cs";
                //files.Add(bundleAssetsListPath);
            }
            var targets = new BuildTarget[] { EditorUserBuildSettings.activeBuildTarget };

#if !DLL
            if (assetbundle.PlatformFolder && data.multiPlatform && 0 < data.targets.Count)
            {
                targets = data.targets.ToArray();
            }
#endif

            bool          ret          = false;
            List <string> platformList = new List <string>();
            foreach (BuildTarget target in targets)
            {
                var path = assetbundle.Path.Replace(AssetBundleManager.PlatformFolder, AssetBundleManager.GetPlatformFolder(Application.platform));
#if !DLL
                if (assetbundle.PlatformFolder)
                {
                    var platformFolder = AssetBundleManager.GetPlatformFolder(target);
                    if (platformList.Contains(platformFolder))
                    {
                        continue;
                    }
                    platformList.Add(platformFolder);
                    path = GetFullPath(assetbundle, target);
                }
#endif
                var dir       = Path.GetDirectoryName(path);
                var assetName = Path.GetFileName(path);
                if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);                    //AssetDatabase.CreateFolder(Path.GetDirectoryName(dir), Path.GetFileName(dir));
                }
                if (!string.IsNullOrEmpty(dir))
                {
                    dir = dir + "/";
                }

                if (!assetbundle.ForStreamedScene)
                {
                    if (!assetbundle.Separated)
                    {
                        Debug.Log(nestString + "Build " + assetbundle.File);

                        /*if( AssetBundleUtilityNew.CreateBundle(files.ToArray(), dir, assetName, (BuildAssetBundleOptions)assetbundle.Options, target, rebuild | assetbundle.Changed) )
                         * {
                         *      ret = true;
                         * }*/
                        //Hoavq change to new build system
                        AssetBundleBuild[] buildMap = new AssetBundleBuild[1];

                        /*buildMap[0].assetBundleName = assetName;
                         * Debug.Log("There're " + files.ToArray().Length + " file in " + assetName + " bundle. Created in " + dir);
                         * buildMap[0].assetNames = files.ToArray();*/

                        AddAssetBundleToBuildMap(buildMap, 0, data, assetbundle);
                        BuildPipeline.BuildAssetBundles(dir, buildMap, (BuildAssetBundleOptions)assetbundle.Options, target);
                    }
                }
            }
            assetbundle.Changed = false;
            return(ret);
        }
        static bool CreateAssetBundle(AssetBundleManageData data, AssetBundleData assetbundle, bool rebuild, bool dependency)
        {
            if (assetbundle.GetAllContents().Count <= 0)
            {
                return(false);
            }
            // add all path to list
            List <string> files = new List <string>();

            foreach (var path in assetbundle.GetAllContentsPath())
            {
                if (File.Exists(path))
                {
                    files.Add(path);
                }
            }
            // add special list asset for system
            BundleAssetList list     = null;
            string          listpath = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(data)) + "/list/" + assetbundle.File + "/list.asset";   //Application.temporaryCachePath + "/" + "list.asset";

            if (!assetbundle.ForStreamedScene)
            {
                list        = CreateInstance <BundleAssetList>();
                list.Assets = files.Select(file => {
                    FileInfo info         = new FileInfo(file);
                    BundleAssetInfo asset = new BundleAssetInfo(info.Name);
                    return(asset);
                }).ToArray();

                var directory = System.IO.Path.GetDirectoryName(listpath).Substring("Assets".Length);
                System.IO.Directory.CreateDirectory(Application.dataPath + directory);
                AssetDatabase.CreateAsset(list, listpath);
                //files.Add(listpath);
                AssetBundleUtility.AssetList = list;
                // BundleAssetList.cs(not exist file "BundleAssetList.cs" with DLL)
                //string bundleAssetsListPath = "Assets/" + Path.GetDirectoryName(AssetBundleManager.SettingDataPath) + "/Scripts/BundleAssetList.cs";
                //files.Add(bundleAssetsListPath);
            }
            var targets = new BuildTarget[] { EditorUserBuildSettings.activeBuildTarget };

#if !DLL
            if (assetbundle.PlatformFolder && data.multiPlatform && 0 < data.targets.Count)
            {
                targets = data.targets.ToArray();
            }
#endif

            bool          ret          = false;
            List <string> platformList = new List <string>();
            foreach (BuildTarget target in targets)
            {
                var path = assetbundle.Path.Replace(AssetBundleManager.PlatformFolder, AssetBundleManager.GetPlatformFolder(Application.platform));
#if !DLL
                if (assetbundle.PlatformFolder)
                {
                    var platformFolder = AssetBundleManager.GetPlatformFolder(target);
                    if (platformList.Contains(platformFolder))
                    {
                        continue;
                    }
                    platformList.Add(platformFolder);
                    path = GetFullPath(assetbundle, target);
                }
#endif
                var dir = Path.GetDirectoryName(path);
                if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);                    //AssetDatabase.CreateFolder(Path.GetDirectoryName(dir), Path.GetFileName(dir));
                }
                if (!string.IsNullOrEmpty(dir))
                {
                    dir = dir + "/";
                }

                if (!assetbundle.ForStreamedScene)
                {
                    if (!assetbundle.Separated)
                    {
                        Debug.Log(nestString + "Build " + assetbundle.File);
                        if (AssetBundleUtility.CreateBundle(files.ToArray(), path, (BuildAssetBundleOptions)assetbundle.Options, target, rebuild | assetbundle.Changed))
                        {
                            ret = true;
                        }
                    }
                    else
                    {
                        var infos = new BundleAssetInfo[] { new BundleAssetInfo("") };
                        list.Assets = infos;
                        AssetBundleUtility.AssetList = list;
                        foreach (var file in files)
                        {
                            infos[0].Name = file;
                            string name = Path.GetFileNameWithoutExtension(file) + ".unity3d";
                            Debug.Log(nestString + "Build " + name);
                            if (AssetBundleUtility.CreateBundle(file, dir + name, (BuildAssetBundleOptions)assetbundle.Options, target, rebuild | assetbundle.Changed))
                            {
                                ret = true;
                            }
                            BuildPipeline.PopAssetDependencies();
                            BuildPipeline.PushAssetDependencies();
                        }
                    }
                }
                else
                {
                    if (!assetbundle.Separated)
                    {
                        Debug.Log(nestString + "Build " + assetbundle.File);
                        if (AssetBundleUtility.CreateSceneBundle(files.ToArray(), path, (BuildAssetBundleOptions)assetbundle.Options, target, rebuild | assetbundle.Changed))
                        {
                            ret = true;
                        }
                    }
                    else
                    {
                        foreach (var file in files)
                        {
                            string name = Path.GetFileNameWithoutExtension(file) + ".unity3d";
                            Debug.Log(nestString + "Build " + name);
                            if (AssetBundleUtility.CreateSceneBundle(file, dir + name, (BuildAssetBundleOptions)assetbundle.Options, target, rebuild | assetbundle.Changed))
                            {
                                ret = true;
                            }
                            BuildPipeline.PopAssetDependencies();
                            BuildPipeline.PushAssetDependencies();
                        }
                    }
                }
            }
            assetbundle.Changed = false;
            //AssetDatabase.DeleteAsset(listpath);	Child assetbundle require list.asset of parent assetbundle.
            //AssetDatabase.Refresh();
            return(ret);
        }