Exemplo n.º 1
0
    /**
     * Get cache state of the Bundle.
     * Before use this, please make sure ConfigLoaded is true.
     * BM cannot cache any bundle download by absolute url or build out of the bundles set.
     */
    public bool IsBundleCached(string url)
    {
        if (!ConfigLoaded)
        {
            Debug.LogError("Cannot get bundle cache state before initialization finished.");
            return(false);
        }

        if (isAbsoluteUrl(url))
        {
            Debug.LogWarning("BM cannot cache files downloaded by absolute url.");
            return(false);
        }

        string bundleName = stripBundleSuffix(url);

        if (!bundleDict.ContainsKey(bundleName))
        {
            Debug.LogWarning("BM cannot cache files out of the bundle list.");
            return(false);
        }

        BundleBuildState bbs = buildStatesDict [bundleName];

        url = formatUrl(url);
        return(Caching.IsVersionCached(url, bbs.version));
    }
Exemplo n.º 2
0
    static public BundleBuildState GetBuildState(string bundlePath)
    {
        BundleBuildState result = null;

        Instance.mBuildStates.TryGetValue(bundlePath, out result);
        return(result);
    }
Exemplo n.º 3
0
    public static bool BuildSingleBundle(BundleData bundle)
    {
        UnityEngine.Object assetObj   = null;
        string             outputPath = GenerateOutputBundlePath(bundle.name);

        if (!LoadAssetObjectByAssetPath(bundle.assetPath, out assetObj))
        {
            return(false);
        }

        uint crc       = 0;
        long changTime = DateTime.Now.ToBinary();

        bool succeed = BuildAssetBundle(assetObj, outputPath, out crc);

        BundleBuildState bundleState = BundleManager.GetBuildStateNoNull(bundle.assetPath);

        if (succeed)
        {
            bundleState.crc = crc;
            bundleState.lastDependencies = bundle.depends.ToArray();
            FileInfo info = new FileInfo(outputPath);
            bundleState.size       = info.Length;
            bundleState.changeTime = changTime;
        }
        else
        {
            bundleState.lastDependencies = null;
        }

        //  每次写入,文件过多会有性能问题
        //BMDataAccessor.SaveBundleBuildeStates();
        return(succeed);
    }
Exemplo n.º 4
0
    public static void DrawInspector()
    {
        if (currentBundle == null)
        {
            GUILayout.FlexibleSpace();
            GUILayout.Label("Select bundle to check its content.");
            GUILayout.FlexibleSpace();
            return;
        }

        m_ScrollViewPosition = EditorGUILayout.BeginScrollView(m_ScrollViewPosition);
        {
            // Bundle type and version
            BundleBuildState buildStates = BundleManager.GetBuildStateOfBundle(currentBundle.name);
            EditorGUILayout.BeginHorizontal();
            {
                GUILayout.Label(currentBundle.sceneBundle ? "Scene bundle" : "Asset bundle", BMGUIStyles.GetStyle("BoldLabel"));
                GUILayout.FlexibleSpace();
                GUILayout.Label("Version " + buildStates.version, BMGUIStyles.GetStyle("BoldLabel"));
            }
            EditorGUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                string sizeStr = "Build Size " + (buildStates.size == -1 ? "Unkown" : Mathf.CeilToInt(buildStates.size / 1024f) + " KB");
                GUILayout.Label(sizeStr, BMGUIStyles.GetStyle("BoldLabel"));
                GUILayout.FlexibleSpace();
                GUILayout.Label("Priority", EditorStyles.boldLabel);
                int opriority = currentBundle.priority;
                currentBundle.priority = EditorGUILayout.Popup(currentBundle.priority, new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }, GUILayout.MaxWidth(40));
                if (opriority != currentBundle.priority)
                {
                    BMDataAccessor.SaveBundleData();
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(5);

            EditorGUILayout.BeginVertical(BMGUIStyles.GetStyle("Wizard Box"));
            {
                GUI_Inlcudes();
                GUI_DependencyList();
            }
            EditorGUILayout.EndVertical();
        }
        EditorGUILayout.EndScrollView();

        GUILayout.BeginHorizontal();
        {
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Refresh") && currentBundle != null)
            {
                BundleManager.RefreshBundleDependencies(currentBundle);
                BMDataAccessor.SaveBundleData();
            }
        }
        GUILayout.EndHorizontal();
    }
Exemplo n.º 5
0
    /// <summary>
    /// Create a new bundle.
    /// 创建一个新的资源包
    /// </summary>
    /// <param name="name">资源包名称_Name of the bundle name.</param>
    /// <param name="parent">资源包的父级资源包_New parent's name. Set the parent to empty string if you want create a new root bundle.</param>
    /// <param name="sceneBundle">是否为场景资源包_Is the bundle a scene bundle? </param>
    /// <returns></returns>
    static public bool CreateNewBundle(string name, string parent, bool sceneBundle)
    {
        var bundleDict = getInstance().bundleDict;

        if (bundleDict.ContainsKey(name))
        {
            return(false);
        }

        BundleData newBundle = new BundleData();

        newBundle.name        = name;
        newBundle.sceneBundle = sceneBundle;

        if (parent != "")
        {
            if (!bundleDict.ContainsKey(parent))
            {
                return(false);
            }
            else
            {
                bundleDict[parent].children.Add(name);
            }

            newBundle.parent = parent;
        }

        bundleDict.Add(name, newBundle);
        InsertBundleToBundleList(newBundle);

        BundleBuildState newBuildState = new BundleBuildState();

        newBuildState.bundleName = name;
        getInstance().statesDict.Add(name, newBuildState);
        BMDataAccessor.BuildStates.Add(newBuildState);

        UpdateBundleChangeTime(newBundle.name);

        BMDataAccessor.SaveBundleData();
        BMDataAccessor.SaveBundleBuildeStates();

        if (!name.StartsWith("+"))
        {
            GM.BundleInfo newBundleInfo = new GM.BundleInfo();
            newBundleInfo.BundleName = name;
            newBundleInfo.Parent     = parent.StartsWith("+") ? "" : parent;
            newBundleInfo.Paths      = new List <string>();
            newBundleInfo.Includes   = new List <string>();
            newBundleInfo.Version    = -1;
            BMDataAccessor.BundleShipInfos.Add(newBundleInfo);

            BMDataAccessor.SaveBundleShipInfoFile();
        }

        return(true);
    }
Exemplo n.º 6
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);
    }
Exemplo n.º 7
0
    void RebuildSelection()
    {
        foreach (string bundleName in m_Selections)
        {
            BundleBuildState buildState = BundleManager.GetBuildStateOfBundle(bundleName);
            buildState.lastBuildDependencies = null;
        }

        BuildHelper.BuildBundles(m_Selections.ToArray());
        BuildHelper.ExportBMDatasToOutput();
    }
Exemplo n.º 8
0
    private static SingleBundleEnd 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[] assetPathes = GetAssetsFromPaths(bundle.includs.ToArray(), bundle.sceneBundle);

        //如果无资源,并且不是common,则说明是一个废弃包
        if (assetPathes.Length == 0)
        {
            return(SingleBundleEnd.eEmptyRemove);
        }

        bool succeed = false;

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

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

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

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

        BMDataAccessor.SaveBundleBuildeStates();
        return(succeed ? SingleBundleEnd.eSucc : SingleBundleEnd.eFail);
    }
Exemplo n.º 9
0
    /// <summary>
    /// ��ʽ��Url
    /// </summary>
    /// <param name="urlstr"></param>
    /// <returns></returns>
    string formatUrl(string urlstr, bool onlyServer)
    {
        Uri url;

        if (!isAbsoluteUrl(urlstr) || !Path.IsPathRooted(urlstr))
        {
            //urlstr = urlstr.Substring(urlstr.LastIndexOf("/") + 1, urlstr.Length - urlstr.LastIndexOf("/") - 1);
            urlstr = Path.GetFileName(urlstr);
            string[] bundleNmaeAndExtension = urlstr.Split('.');
            string   bundleName             = bundleNmaeAndExtension[0];
            if (bundleNmaeAndExtension.Length < 2)
            {
                urlstr = urlstr + "." + bmConfiger.bundleSuffix;
            }
            if (buildStatesDict.ContainsKey(bundleName))
            {
                BundleBuildState bundleState = buildStatesDict[bundleName];
                BundleData       bd          = bundleDict[bundleName];
#if UNITY_STANDALONE_WIN
                if (!onlyServer && LoadBundleManager.getInstace().isExistsForConfiger(bundleState.bundleName, bundleState.version, bundleState.crc))
                {
                    string rootpath = downloadLoadRootUrl + "/" + bd.bundleRelativePath;
                    url = new Uri(new Uri(rootpath + '/'), urlstr);
                    if (!File.Exists(url.AbsoluteUri))
                    {
                        rootpath = downloadRootUrl + "/" + bd.bundleRelativePath;
                        url      = new Uri(new Uri(rootpath + '/'), urlstr);
                    }
                }
                else
                {
                    string rootpath = downloadRootUrl + "/" + bd.bundleRelativePath;
                    url = new Uri(new Uri(rootpath + '/'), urlstr);
                }
#else
                string rootpath = downloadRootUrl + "/" + bd.bundleRelativePath;
                url = new Uri(new Uri(rootpath + '/'), urlstr);
#endif
            }
            else
            {
                url = new Uri(new Uri(downloadRootUrl + "/"), urlstr);
            }
        }
        else
        {
            url = new Uri(urlstr);
        }

        return(url.AbsoluteUri);
    }
Exemplo n.º 10
0
        public bool isExistsForConfiger(string bundleName, int version, uint crc)
        {
            if (!bundleDataDict.ContainsKey(bundleName))
            {
                return(false);
            }
            BundleBuildState bundleState = buildStatesDict[bundleName];

            if (bundleState.crc == crc && bundleState.version == version)
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 11
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);
    }
Exemplo n.º 12
0
    /**
     * Get the build state by bundle's name. Method will return null if there's no such bundle.
     */
    static public BundleBuildState GetBuildStateOfBundle(string name)
    {
        var dic = getInstance().statesDict;

        if (!dic.ContainsKey(name))
        {
            var newBuildState = new BundleBuildState();
            newBuildState.bundleName = name;
            getInstance().statesDict.Add(name, newBuildState);

            dic[name] = newBuildState;
        }
        return(dic[name]);
    }
Exemplo n.º 13
0
    static public BundleBuildState GetBuildStateNoNull(string bundlePath)
    {
        BundleBuildState bundleState = null;

        Instance.mBuildStates.TryGetValue(bundlePath, out bundleState);

        if (bundleState == null)
        {
            bundleState            = new BundleBuildState();
            bundleState.bundlePath = bundlePath;
            Instance.mBuildStates.Add(bundlePath, bundleState);
            BMDataAccessor.BuildStates.Add(bundleState);
        }

        return(bundleState);
    }
Exemplo n.º 14
0
    /**
     * Create a new bundle.
     * @param name Name of the bundle name.
     * @param parent New parent's name. Set the parent to empty string if you want create a new root bundle.
     * @param sceneBundle Is the bundle a scene bundle?
     */
    static public bool CreateNewBundle(string name, string parent, BundleType bundleType)
    {
        var bundleDict = getInstance().bundleDict;

        if (bundleDict.ContainsKey(name))
        {
            return(false);
        }

        BundleData newBundle = new BundleData();

        newBundle.name = name;
        //newBundle.sceneBundle = sceneBundle;
        newBundle.bundleType = bundleType;

        if (parent != "")
        {
            if (!bundleDict.ContainsKey(parent))
            {
                return(false);
            }
            else
            {
                bundleDict[parent].GetChildren().Add(name);
            }

            newBundle.parent = parent;
        }

        bundleDict.Add(name, newBundle);
        InsertBundleToBundleList(newBundle);

        BundleBuildState newBuildState = new BundleBuildState();

        newBuildState.bundleName = name;
        getInstance().statesDict.Add(name, newBuildState);
        BMDataAccessor.BuildStates.Add(newBuildState);

        UpdateBundleChangeTime(newBundle.name);

        BMDataAccessor.SaveBundleData();
        BMDataAccessor.SaveBundleBuildeStates();
        return(true);
    }
Exemplo n.º 15
0
    /**
     * Rename the bundle.
     * @Return Return false if there's no such bundle, or the new name is used.
     */
    static public bool RenameBundle(string origName, string newName)
    {
        if (newName == "" || origName == newName || getInstance().bundleDict.ContainsKey(newName) || !getInstance().bundleDict.ContainsKey(origName))
        {
            return(false);
        }

        BundleData bundle = getInstance().bundleDict[origName];

        bundle.name = newName;

        Dictionary <string, BundleData> bundleDict = getInstance().bundleDict;

        bundleDict.Remove(origName);
        bundleDict.Add(newName, bundle);

        if (bundle.parent != "")
        {
            BundleData parentBundle = bundleDict[bundle.parent];
            parentBundle.children.Remove(origName);
            parentBundle.children.Add(newName);
        }

        foreach (string childName in bundle.children)
        {
            getInstance().bundleDict[childName].parent = newName;
        }

        var buildStatesDic          = getInstance().statesDict;
        BundleBuildState buildState = buildStatesDic[origName];

        buildState.bundleName = newName;
        buildStatesDic.Remove(origName);
        buildStatesDic.Add(newName, buildState);

        BMDataAccessor.SaveBundleData();
        BMDataAccessor.SaveBundleBuildeStates();
        return(true);
    }
Exemplo n.º 16
0
    /**
     * Create a new bundle.
     * @param name Name of the bundle name.
     * @param parent New parent's name. Set the parent to empty string if you want create a new root bundle.
     * @param sceneBundle Is the bundle a scene bundle?  
     */
    static public bool CreateNewBundle(string name, string parent, bool sceneBundle, string path = "")
    {
        var bundleDict = getInstance().bundleDict;

        if (bundleDict.ContainsKey(name))
            return false;

        BundleData newBundle = new BundleData();
        newBundle.name = name;
        newBundle.sceneBundle = sceneBundle;
        newBundle.path = path;
        if (parent != "")
        {
            if (!bundleDict.ContainsKey(parent))
                return false;
            else
                bundleDict[parent].children.Add(name);

            newBundle.parent = parent;
            newBundle.path = bundleDict[parent].path;
        }

        bundleDict.Add(name, newBundle);
        InsertBundleToBundleList(newBundle);

        BundleBuildState newBuildState = new BundleBuildState();
        newBuildState.bundleName = name;
        getInstance().statesDict.Add(name, newBuildState);
        BMDataAccessor.BuildStates.Add(newBuildState);

        UpdateBundleChangeTime(newBundle.name);

        BMDataAccessor.SaveBundleData();
        BMDataAccessor.SaveBundleBuildeStates();
        return true;
    }
Exemplo n.º 17
0
    public static bool IsNeedBuild(BundleData bundle)
    {
        if (BuildManager.IsIgnoreState)
        {
            return(true);
        }

        string outputPath = GenerateOutputBundlePath(bundle.name);

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

        BundleBuildState bundleBuildState = BundleManager.GetBuildState(bundle.assetPath);

        if (bundleBuildState == null)
        {
            return(true);
        }

        //  输出文件是否被修改
        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);
        }

        if (DateTime.Compare(lastBuildTime, File.GetLastWriteTime(bundle.assetPath)) < 0)
        {
            return(true);
        }

        //  依赖是否改变
        if (!EqualStrArray(bundle.depends, bundleBuildState.lastDependencies))
        {
            return(true);
        }


        string[] allResDepends = GetFilterCsDepends(bundle.assetPath);
        for (int i = 0; i < allResDepends.Length; i++)
        {
            var fullPaht = BundleHelp.AssetPath2FullPath(ref allResDepends[i]);

            DateTime test = File.GetLastWriteTime(fullPaht);

            if (DateTime.Compare(lastBuildTime, File.GetLastWriteTime(fullPaht)) < 0)
            {
                return(true);
            }

            if (DateTime.Compare(lastBuildTime, File.GetLastWriteTime(fullPaht + ".meta")) < 0)
            {
                return(true);
            }
        }

        //  依赖文件是否被改变
        //for (int i = 0; i < bundle.depends.Count; i++)
        //{

        //    //  TODO:没有检测纹理之内的资源是否变化

        //    if (!File.Exists(GenerateOutputBundlePath(Path.GetFileNameWithoutExtension(bundle.depends[i]))))
        //        return true;

        //    if (DateTime.Compare(lastBuildTime, File.GetLastWriteTime(bundle.depends[i])) < 0)
        //    {
        //        return true;
        //    }

        //    //  meta change
        //    //  Texture Format Change
        //    if (DateTime.Compare(lastBuildTime, File.GetLastWriteTime(bundle.depends[i] + ".meta")) < 0)
        //    {
        //        return true;
        //    }
        //}

        return(false);
    }
Exemplo n.º 18
0
    private static bool BuildSingleBundle(BundleData bundle)
    {
        var extra = bundle.GetExtraData();

        // Prepare bundle output dictionary
        string outputPath     = GenerateOutputPathForBundle(bundle.name);
        string bundleStoreDir = Path.GetDirectoryName(outputPath);

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

        if (extra.includeAssetPaths.Count == 0)
        {
            BundleManager.RefreshBundleDependencies(bundle);
        }

        // Start build
        string[] assetPaths = extra.includeAssetPaths.ToArray();
        bool     succeed    = false;
        uint     crc        = 0;

        switch (bundle.bundleType)
        {
        case BundleType.Normal:
            succeed = BuildSceneBundle(assetPaths, outputPath, out crc);
            break;

        case BundleType.Scene:
            succeed = BuildSceneBundle(assetPaths, outputPath, out crc);
            break;

        case BundleType.Text:
            succeed = BuildSceneBundle(assetPaths, outputPath, out crc);
            break;

        default:
            throw new NotImplementedException();
        }

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

        if (succeed)
        {
            foreach (var guid in extra.includeAssetGUIDs)
            {
                buildState.assetStates[guid] = BundleManager.GetAssetState(guid);
            }
            foreach (var guid in extra.dependGUIDs)
            {
                buildState.assetStates[guid] = BundleManager.GetAssetState(guid);
            }

            buildState.assetListMd5 = GetBundleAssetsListMD5(bundle);

            buildState.crc           = crc;
            buildState.changed       = true;
            buildState.requestString = bundle.name + "." + BuildConfiger.BundleSuffix;
            FileInfo bundleFileInfo = new FileInfo(outputPath);
            buildState.size = bundleFileInfo.Length;
            extra.needBuild = false;
            m_BuiltCount++;

            BMDataAccessor.ShouldSaveBundleStates = true;
        }
        return(succeed);
    }
Exemplo n.º 19
0
    /// <summary>
    /// load buildstate from output path with different platform
    /// </summary>
    public static bool RefreshBuildStateFromOutputPath()
    {
        bool exeu = true;
        List<BundleBuildState> list = null;
        try
        {
            list = BMDataAccessor.BuildStatesFromOutputPath;
        }
        catch (Exception e)
        {
            Debug.LogError(e.Message);
            Debug.LogError("RefreshBuildStateFromOutputPath Failed!");

            exeu = EditorUtility.DisplayDialog("打包记录文件读取失败,", BuildConfiger.InterpretedOutputPath + "/BuildStates.txt ,全部覆盖?",
                "yes", "no");
        }
        if (!exeu)
            return exeu;

        int i = 0;
        int cout = list.Count + getInstance().statesDict.Count;


        Dictionary<string, BundleBuildState> newdic = new Dictionary<string, BundleBuildState>();

        //对比local和文件夹以local有更新被忽略
        foreach (BundleBuildState buildState in list)
        {
            EditorUtility.DisplayProgressBar("RefreshBuildState",
                BuildConfiger.InterpretedOutputPath + "/BuildStates.txt", (float)i / cout);
            //            if (getInstance().statesDict.ContainsKey(buildState.bundleName))
            //            {
            //                BundleBuildState sb = getInstance().statesDict[buildState.bundleName];
            //                DateTime bundleChangeTime = buildState.changeTime == -1
            //                    ? DateTime.MaxValue
            //                    : DateTime.FromBinary(buildState.changeTime);
            //                DateTime localBundleChangeTime = sb.changeTime == -1
            //                    ? DateTime.MaxValue
            //                    : DateTime.FromBinary(sb.changeTime);
            //                if (System.DateTime.Compare(bundleChangeTime, localBundleChangeTime) < 0)
            //                {
            //                    Debug.LogError("local buildState changed [" + buildState.bundleName + "]");
            //                    buildState.changeTime = sb.changeTime;
            //                }
            //            }
            if (buildState.bundleName.Trim() != "" && !newdic.ContainsKey(buildState.bundleName))
                newdic.Add(buildState.bundleName, buildState);
            i++;
        }

        foreach (BundleData bundata in BMDataAccessor.Bundles)
        {
            EditorUtility.DisplayProgressBar("RefreshBuildState", bundata.path + "/" + bundata.name, (float)i / cout);

            if (!newdic.ContainsKey(bundata.name))
            {
                Debug.LogError("new BundleData not in Last BuildState [" + bundata.name + "]");

                if (getInstance().statesDict.ContainsKey(bundata.name))
                {
                    newdic.Add(bundata.name, getInstance().statesDict[bundata.name]);
                    newdic[bundata.name].bundleName = bundata.name;
                }
                else
                {
                    BundleBuildState bbs = new BundleBuildState();
                    bbs.bundleName = bundata.name;
                    bbs.changeTime = DateTime.Now.ToBinary();
                    newdic.Add(bundata.name, bbs);
                }
            }
            i++;

        }

        getInstance().statesDict.Clear();
        getInstance().statesDict = newdic;
        BMDataAccessor.BuildStatesFromOutputPath = newdic.Values.ToList();
        BMDataAccessor.SaveBundleBuildeStates();
        BMDataAccessor.SaveBundleData();
        EditorUtility.ClearProgressBar();
        return true;
    }
Exemplo n.º 20
0
 private Dictionary<string, List<BundleData>> includeRefDict = new Dictionary<string, List<BundleData>>();// key: asset path, value: bundles include this asset
 static public BundleBuildState GetOrAddBuildStateOfBundle(string name)
 {
     if (getInstance().statesDict.ContainsKey(name))
         return getInstance().statesDict[name];
     else
     {
         BundleBuildState buildState = new BundleBuildState();
         buildState.bundleName = name;
         buildState.changeTime = DateTime.Now.ToBinary();
         getInstance().statesDict.Add(name, buildState);
         BMDataAccessor.BuildStates.Add(buildState);
         return buildState;
     }
 }
Exemplo n.º 21
0
    /**
     * Rename the bundle.
     * @Return Return false if there's no such bundle, or the new name is used.
     */
    static public bool RenameBundle(string origName, string newName)
    {
        if (origName.StartsWith("+") && !newName.StartsWith("+"))
        {
            UnityEditor.EditorUtility.DisplayDialog("Message", "You can not rename a folder node to a normal bundle node", "OK");
            return(false);
        }
        else if (!origName.StartsWith("+") && newName.StartsWith("+"))
        {
            UnityEditor.EditorUtility.DisplayDialog("Message", "You can not rename a normal bundle node to a folder node", "OK");
            return(false);
        }

        if (newName == "" || origName == newName || getInstance().bundleDict.ContainsKey(newName) || !getInstance().bundleDict.ContainsKey(origName))
        {
            return(false);
        }

        BundleData bundle = getInstance().bundleDict[origName];

        bundle.name = newName;

        Dictionary <string, BundleData> bundleDict = getInstance().bundleDict;

        bundleDict.Remove(origName);
        bundleDict.Add(newName, bundle);

        if (bundle.parent != "")
        {
            BundleData parentBundle = bundleDict[bundle.parent];
            parentBundle.children.Remove(origName);
            parentBundle.children.Add(newName);
        }

        foreach (string childName in bundle.children)
        {
            getInstance().bundleDict[childName].parent = newName;
        }

        var buildStatesDic          = getInstance().statesDict;
        BundleBuildState buildState = buildStatesDic[origName];

        buildState.bundleName = newName;
        buildStatesDic.Remove(origName);
        buildStatesDic.Add(newName, buildState);

        BMDataAccessor.SaveBundleData();
        BMDataAccessor.SaveBundleBuildeStates();

        List <GM.BundleInfo> childBundleInfo = BMDataAccessor.BundleShipInfos.FindAll(item => item.Parent == origName);

        GM.BundleInfo bundleInfo = BMDataAccessor.BundleShipInfos.Find(item => item.BundleName == origName);
        if (bundleInfo != null)
        {
            bundleInfo.BundleName = newName;

            foreach (GM.BundleInfo _child in childBundleInfo)
            {
                _child.Parent = newName;
            }

            BMDataAccessor.SaveBundleShipInfoFile();
        }

        return(true);
    }
Exemplo n.º 22
0
    public void Init()
    {
        EditorUtility.DisplayProgressBar("BundleManager Init...", "statesDict....", 0.1f);
        BMDataAccessor.Refresh();

        statesDict.Clear();
        includeRefDict.Clear();
        dependRefDict.Clear();

        foreach (BundleBuildState buildState in BMDataAccessor.BuildStates)
        {
            if (!statesDict.ContainsKey(buildState.bundleName))
                statesDict.Add(buildState.bundleName, buildState);
            else
                Debug.LogError("Bundle manger -- Cannot have two build states with same name [" + buildState.bundleName + "]");
        }
        EditorUtility.DisplayProgressBar("BundleManager Init...", "bundleDict....", 0.6f);
        bundleDict.Clear();

        foreach (BundleData bundle in BMDataAccessor.Bundles)
        {
            if (!bundleDict.ContainsKey(bundle.name))
                bundleDict.Add(bundle.name, bundle);
            else
                Debug.LogError("Bundle manger -- Cannot have two bundle with same name [" + bundle.name + "]");

            if (!statesDict.ContainsKey(bundle.name))
            {
                BundleBuildState bd = new BundleBuildState();
                bd.bundleName = bundle.name;
                bd.changeTime = DateTime.Now.ToBinary();
                statesDict.Add(bundle.name, bd); // Don't have build state of the this bundle. Add a new one.
            }

            foreach (string guid in bundle.includeGUIDs)
                AddIncludeRef(guid, bundle);

            RefreshBundleDependencies(bundle);
        }
        EditorUtility.ClearProgressBar();

    }
Exemplo n.º 23
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);
    }
Exemplo n.º 24
0
    public static void DrawInspector()
    {
        if (currentBundle == null)
        {
            GUILayout.FlexibleSpace();
            GUILayout.Label("Select bundle to check its content.");
            GUILayout.FlexibleSpace();
            return;
        }

        m_ScrollViewPosition = EditorGUILayout.BeginScrollView(m_ScrollViewPosition);
        {
            // Bundle type and version
            BundleBuildState buildStates = BundleManager.GetBuildStateOfBundle(currentBundle.name);
            EditorGUILayout.BeginHorizontal();
            {
                string label = "";
                switch (currentBundle.bundleType)
                {
                case BundleType.Normal:
                    label = "Asset bundle";
                    break;

                case BundleType.Scene:
                    label = "Scene bundle";
                    break;

                case BundleType.Text:
                    label = "Text bundle";
                    break;

                default:
                    throw new System.NotImplementedException();
                }

                GUILayout.Label(label, BMGUIStyles.GetStyle("BoldLabel"));
                GUILayout.FlexibleSpace();
                //GUILayout.Label("Version " + buildStates.version, BMGUIStyles.GetStyle("BoldLabel"));
            }
            EditorGUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                string sizeStr = "Build Size " + (buildStates.size == -1 ? "Unkown" : Mathf.CeilToInt(buildStates.size / 1024f) + " KB");
                GUILayout.Label(sizeStr, BMGUIStyles.GetStyle("BoldLabel"));
                GUILayout.FlexibleSpace();
                GUILayout.Label("Priority", EditorStyles.boldLabel);
                var priorityIndex = currentBundle.priority + 5;
                priorityIndex          = EditorGUILayout.Popup(priorityIndex, PriorityNameList, GUILayout.MaxWidth(70));
                currentBundle.priority = priorityIndex - 5;
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(5);

            EditorGUILayout.BeginVertical(BMGUIStyles.GetStyle("Wizard Box"));
            {
                GUI_Inlcudes();
                GUI_DependencyList();
            }
            EditorGUILayout.EndVertical();
        }
        EditorGUILayout.EndScrollView();

        GUILayout.BeginHorizontal();
        {
            GUILayout.FlexibleSpace();
            m_HideGreenDependencies = GUILayout.Toggle(m_HideGreenDependencies, "Hide Green", "button");
            if (GUILayout.Button("Refresh") && currentBundle != null)
            {
                BundleManager.RefreshBundleDependencies(currentBundle);
                BMDataAccessor.SaveBundleData();
            }
        }
        GUILayout.EndHorizontal();
    }
Exemplo n.º 25
0
    static public BundleBuildState GetBuildStateNoNull(string bundlePath)
    {
        BundleBuildState bundleState = null;
        Instance.mBuildStates.TryGetValue(bundlePath, out bundleState);

        if (bundleState == null)
        {
            bundleState = new BundleBuildState();
            bundleState.bundlePath = bundlePath;
            Instance.mBuildStates.Add(bundlePath, bundleState);
            BMDataAccessor.BuildStates.Add(bundleState);
        }

        return bundleState;
    }