Ejemplo n.º 1
0
    private static bool BuildSingleBundle(BundleData bundle)
    {
        // Prepare bundle output dictionary
        string outputPath     = GenerateOutputPathForBundle(bundle.name);
        string bundleStoreDir = Path.GetDirectoryName(outputPath);

        if (!Directory.Exists(bundleStoreDir))
        {
            Directory.CreateDirectory(bundleStoreDir);
        }

        // Start build
        string[] assetPaths = GetAssetsFromPaths(BundleManager.GUIDsToPaths(bundle.includeGUIDs.ToArray()), bundle.sceneBundle);
        bool     succeed    = false;
        uint     crc        = 0;

        if (assetPaths.Length == 0)
        {
            Debug.LogError("No asset included in bundle " + bundle.name);
        }
        else
        {
            if (bundle.sceneBundle)
            {
                succeed = BuildSceneBundle(assetPaths, outputPath, out crc);
            }
            else
            {
                succeed = BuildAssetBundle(assetPaths, outputPath, out crc);
            }
        }

        // Remember the assets for next time build test
        BundleBuildState buildState = BundleManager.GetBuildStateOfBundle(bundle.name);

        if (succeed)
        {
            buildState.lastBuildDependencies = AssetDatabase.GetDependencies(assetPaths);
            buildState.version++;
            if (buildState.version == int.MaxValue)
            {
                buildState.version = 0;
            }

            buildState.crc = crc;
            System.IO.FileInfo bundleFileInfo = new System.IO.FileInfo(outputPath);
            buildState.size = bundleFileInfo.Length;
        }
        else
        {
            buildState.lastBuildDependencies = null;
        }

        BMDataAccessor.SaveBundleBuildeStates();
        return(succeed);
    }
Ejemplo n.º 2
0
    static public void SaveBundleData()
    {
        foreach (BundleData bundle in Bundles)
        {
            bundle.includeGUIDs.Sort(guidComp);
            bundle.includs = BundleManager.GUIDsToPaths(bundle.includeGUIDs);

            bundle.dependGUIDs.Sort(guidComp);
            bundle.dependAssets = BundleManager.GUIDsToPaths(bundle.dependGUIDs);
        }
        saveObjectToJsonFile(Bundles, BundleDataPath);
    }
Ejemplo n.º 3
0
    /**
     * Detect if the bundle need update.
     */
    public static bool IsBundleNeedBunild(BundleData bundle)
    {
        string outputPath = GenerateOutputPathForBundle(bundle.name);

        if (!File.Exists(outputPath))
        {
            return(true);
        }

        BundleBuildState bundleBuildState = BundleManager.GetBuildStateOfBundle(bundle.name);
        DateTime         lastBuildTime    = File.GetLastWriteTime(outputPath);
        DateTime         bundleChangeTime = bundleBuildState.changeTime == -1 ? DateTime.MaxValue : DateTime.FromBinary(bundleBuildState.changeTime);

        if (System.DateTime.Compare(lastBuildTime, bundleChangeTime) < 0)
        {
            return(true);
        }

        string[] assetPaths   = GetAssetsFromPaths(BundleManager.GUIDsToPaths(bundle.includeGUIDs.ToArray()), bundle.sceneBundle);
        string[] dependencies = AssetDatabase.GetDependencies(assetPaths);
        if (!EqualStrArray(dependencies, bundleBuildState.lastBuildDependencies))
        {
            return(true);            // Build depenedencies list changed.
        }
        foreach (string file in dependencies)
        {
            if (DateTime.Compare(lastBuildTime, File.GetLastWriteTime(file)) < 0)
            {
                return(true);
            }
        }

        if (bundle.parent != "")
        {
            BundleData parentBundle = BundleManager.GetBundleData(bundle.parent);
            if (parentBundle != null)
            {
                if (IsBundleNeedBunild(parentBundle))
                {
                    return(true);
                }
            }
            else
            {
                Debug.LogError("Cannot find bundle");
            }
        }

        return(false);
    }
Ejemplo n.º 4
0
    /// <summary>
    /// 根据数据生成对应的Bundle压缩文件
    /// </summary>
    /// <param name="bundle"></param>
    /// <returns></returns>
    private static bool BuildSingleBundle(BundleData bundle)
    {
        // Prepare bundle output dictionary
        string outputPath     = GenerateOutputPathForBundle(bundle.name);
        string bundleStoreDir = Path.GetDirectoryName(outputPath);

        if (!Directory.Exists(bundleStoreDir))
        {
            Directory.CreateDirectory(bundleStoreDir);
        }
        if (File.Exists(outputPath))
        {
            File.Delete(outputPath);
        }

        // Start build
        string[] assetPaths = GetAssetsFromPaths(BundleManager.GUIDsToPaths(bundle.includeGUIDs.ToArray().Concat(bundle.exIncludeGUIDs.ToArray()).ToArray()), bundle.sceneBundle);
        bool     succeed    = false;
        uint     crc        = 0;

        if (bundle.sceneBundle)
        {
            succeed = BuildSceneBundle(assetPaths, outputPath, out crc);
        }
        else
        {
            succeed = BuildAssetBundle(assetPaths, outputPath, out crc);
        }

        if (succeed /* && !BMDataAccessor.BMConfiger.compress*/)
        {
            succeed = CompressBundle(ref outputPath, true);
        }

        // Remember the assets for next time build test
        BundleBuildState buildState = BundleManager.GetBuildStateOfBundle(bundle.name);

        if (succeed)
        {
            buildState.lastBuildDependencies = AssetDatabase.GetDependencies(assetPaths);
            FileInfo bundleFileInfo = new FileInfo(outputPath);

            //Only has bundle real change will change version
            if (buildState.crc != crc || buildState.size != bundleFileInfo.Length)
            {
                buildState.version++;
                buildState.crc  = crc;
                buildState.size = bundleFileInfo.Length;
            }

            if (buildState.version == int.MaxValue)
            {
                buildState.version = 0;
            }

            // refresh depends
            //BundleManager.RefreshBundleDependencies(bundle);
            //BMDataAccessor.SaveBundleData();

            // fix build state
            if (buildState.changeTime == -1)
            {
                buildState.changeTime = bundleFileInfo.LastWriteTime.ToBinary();
            }
            if (string.IsNullOrEmpty(buildState.bundleName))
            {
                buildState.bundleName = bundle.name;
            }
            if (BMDataAccessor.BuildStates.Find(x => x.bundleName == bundle.name) == null)
            {
                BMDataAccessor.BuildStates.Add(buildState);
            }

            // generate bundle ship info
            if (BMDataAccessor.BundleShipInfos.Find(item => item.BundleName == bundle.name) == null)
            {
                GM.BundleInfo _tmp = new GM.BundleInfo();
                _tmp.BundleName = bundle.name;
                _tmp.Paths      = new List <string>();
                _tmp.Includes   = new List <string>();
                BMDataAccessor.BundleShipInfos.Add(_tmp);
            }
            GM.BundleInfo _shipinfo = BMDataAccessor.BundleShipInfos.Find(item => item.BundleName == bundle.name);
            _shipinfo.Paths.Clear();
            _shipinfo.Includes.Clear();
            foreach (string _i in bundle.includs.ToArray().Concat(bundle.exIncludes.ToArray()))
            {
                if (string.IsNullOrEmpty(_i) || string.IsNullOrEmpty(Path.GetExtension(_i)))
                {
                    _shipinfo.Paths.Add(_i);
                }
                else
                {
                    _shipinfo.Paths.Add(_i.Replace(Path.GetExtension(_i), string.Empty));
                }
                _shipinfo.Includes.Add(Path.GetFileNameWithoutExtension(_i));
            }
            _shipinfo.Parent  = bundle.parent.StartsWith("+") ? string.Empty : bundle.parent;
            _shipinfo.Version = buildState.version;
            _shipinfo.MD5     = S3Utils.CalculateMD5(System.Text.Encoding.Default.GetBytes(buildState.size.ToString() + buildState.crc.ToString()));
            _shipinfo.Size    = buildState.size;

            BMDataAccessor.SaveBundleShipInfoFile();
        }
        else
        {
            buildState.lastBuildDependencies = null;
        }

        BMDataAccessor.SaveBundleBuildeStates();
        return(succeed);
    }