Example #1
0
    public void Start()
    {
        //如果是编辑器模式,可以选择是否选择使用本地脚本和使用本地打包的bundle
#if (UNITY_EDITOR_OSX || UNITY_EDITOR)
        if (UseResourceScriptLoad)
        {
            GameUtils.ScriptLoad = true;       //使用本地的脚本
        }
        else
        {
            GameUtils.ScriptLoad = false;      //使用bundle的脚本
        }
#else
        GameUtils.ScriptLoad = false;
#endif

        ABPathHelper.InitCachePath();

        //此处要先读取本地的AssetManageConfig资源
        AssetManageConfigManager.Instance.Load();
        PoolManager.Instance.Init();
        ResourceManager.Instance.Init();

        //initial all system
        mSystems = mConfig.mInitialDelegate(this.transform);

        foreach (CGameSystem gameSys in mSystems)
        {
            mSystemMap.Add(gameSys.GetType(), gameSys);
        }
        foreach (CGameSystem gameSys in mSystems)
        {
            gameSys.SysInitial();
        }

        if (mFirstState != EStateType.None)
        {
            SwitchToState(mFirstState);
        }
        else
        {
            _SwitchToState(EStateType.Root);
        }
    }
    //跟包用的AB打包-打包到LocalAB目录下
    private static void BuildBundleNameMenu_WithPak_Version()
    {
        menuStart("跟包AB打包", sw);

        //1.跟包的AB的打包命名
        BuildStrategy.BuildBundleName_WithPak_Version();

        //2.开始打包需要跟包的非压缩AB包
        BuildAssetBundles(outputLocalABPath);

        //3.清除所有的BundleName
        ClearAllBundleNameMenu();

        //4.将非压缩的AB压缩存放到StreamingAssets目录下
        VersionManager.CopyDir(ABPathHelper.GetAddPrefixPath(outputLocalABPath), ABPathHelper.GetAddPrefixPath(outputStreamingAssetsPath));
        ////5.生成标记文件
        SaveOrCreateDecompressSuccess();

        menuEnd("跟包AB打包", sw);
    }
    /// <summary>
    /// 生成目录下所有AssertBundle信息文件的MD5信息
    /// </summary>
    /// <param name="abPath"></param>
    public static void BuildBundleMD5Files(string abPath)
    {
        string assetBundlePath = abPath;// Path.Combine(abPath, ABPathHelper.platformFolder);

        if (!Directory.Exists(assetBundlePath))
        {
            return;
        }

        //先删除AllGameConfig文件
        string config_path = ABPathHelper.GetCombinePath(assetBundlePath, ABPathHelper.localVerMD5File);

        if (File.Exists(config_path))
        {
            File.Delete(config_path);
        }

        Dictionary <string, string> newFileMD5Map = new Dictionary <string, string>();

        string[]   files = Directory.GetFiles(assetBundlePath, "*", SearchOption.AllDirectories);
        FileStream fs    = new FileStream(assetBundlePath + "/" + ABPathHelper.localVerMD5File, FileMode.OpenOrCreate);

        using (StreamWriter sw = new StreamWriter(fs))
        {
            string filePath = "";
            string fileMd5  = string.Empty;
            string fileExt  = "";
            string fileName = "";
            long   fileSize = 0;
            foreach (string file in files)
            {
#if UNITY_EDITOR_OSX
                filePath = file.Replace(assetBundlePath + "/", "");
#else
                filePath = file.Replace(assetBundlePath + "\\", "");
#endif
                if (filePath.Contains(ABPathHelper.localVerMD5File))
                {
                    continue;
                }
                fileExt  = Path.GetExtension(filePath);
                fileName = Path.GetFileNameWithoutExtension(filePath);
                if (!fileExt.Equals(ABPathHelper.Unity3dSuffix) && !fileExt.Equals(ABPathHelper.MP4Suffix))
                {
                    continue;
                }
                //判断是否与空格
                if (filePath.Contains(" "))
                {
                    Debug.Log("<color=red>有问题资源:</color>" + filePath);
                    continue;
                }

                CUtility.MD5Hash(file, ref fileMd5, ref fileSize);

                sw.WriteLine(string.Format("{0}*{1}*{2}", filePath, fileMd5, fileSize));
            }
        }
        fs.Close();
        fs.Dispose();
    }