Exemplo n.º 1
0
    public static void RefreshBundleChanged(BundleData bundle)
    {
        var state = BundleManager.GetBuildStateOfBundle(bundle.name);

        if (!state.changed)
        {
            if (IsBundleChanged(bundle))
            {
                state.changed = true;
                BundleManager.MarkParentsNeedBuild(bundle);
                BMDataAccessor.ShouldSaveBundleStates = true;
            }
        }
    }
Exemplo n.º 2
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.º 3
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 (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;
            FileInfo bundleFileInfo = new FileInfo(outputPath);
            buildState.size = bundleFileInfo.Length;
        }
        else
        {
            buildState.lastBuildDependencies = null;
        }

        BMDataAccessor.SaveBundleBuildeStates();
        return(succeed);
    }
Exemplo n.º 4
0
    private static bool IsBundleChanged(BundleData bundle)
    {
        var state = BundleManager.GetBuildStateOfBundle(bundle.name);

        if (state.changed)
        {
            return(true);
        }
        var extra = bundle.GetExtraData();

        if (bundle.bundleType == BundleType.Text)
        {
            //HACK:文本bundles中往往包含大量文件,所以永远重新打包
            return(true);
        }

        if (GetBundleAssetsListMD5(bundle) != state.assetListMd5)
        {
            return(true);
        }

        //判断所有涉及的文件是否有变化,如有,则需要重新打包
        foreach (var guid in extra.includeAssetGUIDs)
        {
            if (!state.assetStates.ContainsKey(guid))
            {
                return(true);
            }
            else if (BundleManager.CheckAssetModified(state.assetStates[guid]))
            {
                return(true);
            }
        }
        foreach (var guid in extra.dependGUIDs)
        {
            if (!state.assetStates.ContainsKey(guid))
            {
                return(true);
            }
            else if (BundleManager.CheckAssetModified(state.assetStates[guid]))
            {
                return(true);
            }
        }
        return(false);
    }
Exemplo n.º 5
0
    public static void SaveBundleVersionInfo()
    {
        var bundleVersionInfos = BMDataAccessor.Bundles.Select(data =>
        {
            var state = BundleManager.GetBuildStateOfBundle(data.name);
            return(new BundleVersionInfo()
            {
                name = data.name,
                parent = data.parent,
                requestString = state.requestString,
                crc = state.crc,
                size = state.size,
                priority = data.priority,
            });
        }).ToList();

        saveObjectToJsonFile(bundleVersionInfos, BundleVersionInfoPath);
    }
Exemplo n.º 6
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.GetBuildinStyle("BoldLabel"));
                GUILayout.FlexibleSpace();
                GUILayout.Label("Version " + buildStates.version, BMGUIStyles.GetBuildinStyle("BoldLabel"));
            }
            EditorGUILayout.EndHorizontal();

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

            GUILayout.Space(5);

            EditorGUILayout.BeginVertical(BMGUIStyles.GetBuildinStyle("Wizard Box"));
            {
                GUI_Inlcudes();
                GUI_DependencyList();
            }
            EditorGUILayout.EndVertical();
        }
        EditorGUILayout.EndScrollView();
    }
Exemplo n.º 7
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.º 8
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.º 9
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.º 10
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);

            //������ӵ�UI
            currentBundle.bundleRelativePath = EditorGUILayout.TextField("��Դ�����·��", currentBundle.bundleRelativePath);

            //������ӵ�UI

            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);
                currentBundle.priority = EditorGUILayout.Popup(currentBundle.priority, new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }, GUILayout.MaxWidth(40));
            }
            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();

        if (GUI.changed)
        {
            BundleManager.RefreshBundleDependencies(currentBundle);
            BMDataAccessor.SaveBundleData();
        }
    }
Exemplo n.º 11
0
    Rect GUI_DrawItem(BundleData bundle, int indent)
    {
        var extra = bundle.GetExtraData();
        var state = BundleManager.GetBuildStateOfBundle(bundle.name);

        bool isEditing   = m_CurrentEditing == bundle.name;
        bool isRecieving = m_CurrentRecieving == bundle.name;
        bool isSelected  = m_Selections.Contains(bundle.name);

        GUIStyle currentLableStyle = BMGUIStyles.GetStyle("TreeItemUnSelect");

        if (isRecieving)
        {
            currentLableStyle = BMGUIStyles.GetStyle("receivingLable");
        }
        else if (isSelected && !isEditing)
        {
            currentLableStyle = HasFocuse() ? BMGUIStyles.GetStyle("TreeItemSelectBlue") : BMGUIStyles.GetStyle("TreeItemSelectGray");
        }

        Rect itemRect = EditorGUILayout.BeginHorizontal(currentLableStyle);

        if (bundle.GetChildren().Count == 0)
        {
            GUILayout.Space(m_IndentWidth * indent + m_NoToggleIndent);
        }
        else
        {
            GUILayout.Space(m_IndentWidth * indent);
            bool fold = !GUILayout.Toggle(!IsFold(bundle.name), "", BMGUIStyles.GetStyle("Foldout"));
            SetFold(bundle.name, fold);
        }

        Texture2D bundleIcon = null;

        switch (bundle.bundleType)
        {
        case BundleType.Scene:
            bundleIcon = BMGUIStyles.GetIcon("sceneBundleIcon");
            break;

        case BundleType.Text:
            bundleIcon = BMGUIStyles.GetIcon("textBundleIcon");
            break;

        default:
            bundleIcon = BMGUIStyles.GetIcon("assetBundleIcon");
            break;
        }
        GUILayout.Label(bundleIcon, BMGUIStyles.GetStyle("BItemLabelNormal"), GUILayout.ExpandWidth(false));
        //GUILayout.Label(bundle.sceneBundle ? BMGUIStyles.GetIcon("sceneBundleIcon") : BMGUIStyles.GetIcon("assetBundleIcon"), BMGUIStyles.GetStyle("BItemLabelNormal"), GUILayout.ExpandWidth(false));

        if (!isEditing)
        {
            GUILayout.Label(bundle.name, isSelected ? BMGUIStyles.GetStyle("BItemLabelActive") : BMGUIStyles.GetStyle("BItemLabelNormal"));
        }
        else
        {
            GUI.SetNextControlName(m_EditTextFeildName);
            m_EditString = GUILayout.TextField(m_EditString, BMGUIStyles.GetStyle("TreeEditField"));
        }

        var r = GUILayoutUtility.GetLastRect();

        r.x      = r.xMax - 20;
        r.height = 20;
        if (state.changed)
        {
            GUI.Label(r, m_WarnIcon);
        }
        else if (extra.needBuild)
        {
            GUI.Label(r, m_InfoIcon);
        }

        EditorGUILayout.EndHorizontal();

        return(itemRect);
    }