Ejemplo n.º 1
0
    private static string GetBundleAssetsListMD5(BundleData bundle)
    {
        var str = string.Join(string.Empty, bundle.includeGUIDs.ToArray()) +
                  string.Join(string.Empty, bundle.GetExtraData().dependGUIDs.ToArray());

        return(ZipFile.md5.getMd5Hash(System.Text.Encoding.ASCII.GetBytes(str)));
    }
Ejemplo n.º 2
0
    /**
     * Remove the bundle by the given name.
     * @Return Return false if no such bundle.
     */
    static public bool RemoveBundle(string name)
    {
        var bundleDict     = getInstance().bundleDict;
        var bundlelist     = BMDataAccessor.Bundles;
        var dependRefDict  = getInstance().dependRefDict;
        var includeRefDict = getInstance().includeRefDict;
        var statesDict     = getInstance().statesDict;

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

        BundleData bundle = bundleDict[name];

        bundlelist.Remove(bundle);
        bundleDict.Remove(name);

        var buildStatesDict = getInstance().statesDict;

        BMDataAccessor.BuildStates.Remove(buildStatesDict[name]);
        buildStatesDict.Remove(name);

        // Remove parent ref
        if (bundle.parent != "" && bundleDict.ContainsKey(bundle.parent))
        {
            bundleDict[bundle.parent].GetChildren().Remove(name);
        }

        // Remove include ref
        foreach (string guid in bundle.includeGUIDs)
        {
            if (includeRefDict.ContainsKey(guid))
            {
                includeRefDict[guid].Remove(bundle);
            }
        }

        // Remove depend asssets ref
        foreach (string guid in bundle.GetExtraData().dependGUIDs)
        {
            dependRefDict[guid].Remove(bundle);
        }

        // Delete children recursively
        foreach (string childName in bundle.GetChildren())
        {
            RemoveBundle(childName);
        }

        //Remove buildState
        if (statesDict.ContainsKey(name))
        {
            statesDict.Remove(name);
        }

        return(true);
    }
Ejemplo n.º 3
0
    public static void MarkParentsNeedBuild(BundleData bundle)
    {
        var extra = bundle.GetExtraData();

        extra.needBuild = true;
        var parentBundle = BundleManager.GetBundleData(bundle.parent);

        if (parentBundle != null)
        {
            MarkParentsNeedBuild(parentBundle);
        }
    }
Ejemplo n.º 4
0
 internal static void AddDependRefs(BundleData bundle)
 {
     foreach (string guid in bundle.GetExtraData().dependGUIDs)
     {
         if (!getInstance().dependRefDict.ContainsKey(guid))
         {
             List <BundleData> sharedBundleList = new List <BundleData>();
             sharedBundleList.Add(bundle);
             getInstance().dependRefDict.Add(guid, sharedBundleList);
         }
         else
         {
             getInstance().dependRefDict[guid].Add(bundle);
         }
     }
 }
Ejemplo n.º 5
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);
    }
Ejemplo n.º 6
0
    /**
     * Refresh bundle dependencies
     */
    public static void RefreshBundleDependencies(BundleData bundle)
    {
        //// Remove the old refs
        //foreach(string guid in bundle.dependGUIDs)
        //{
        //    if(getInstance().dependRefDict.ContainsKey(guid))
        //        getInstance().dependRefDict[guid].Remove(bundle);
        //}

        //// Get all the includes files path
        //string[] files = BuildHelper.GetAssetsFromPaths( GUIDsToPaths(bundle.includeGUIDs).ToArray(), bundle.sceneBundle );
        //string[] dependGUIDs = PathsToGUIDs( AssetDatabase.GetDependencies(files) );

        //// New refs
        //bundle.dependGUIDs = new List<string>(dependGUIDs);
        //bundle.dependGUIDs.RemoveAll(x=>bundle.includeGUIDs.Contains(x));

        //AddDependRefs(bundle);

        var extra = bundle.GetExtraData();

        foreach (string guid in extra.dependGUIDs)
        {
            if (getInstance().dependRefDict.ContainsKey(guid))
            {
                getInstance().dependRefDict[guid].Remove(bundle);
            }
        }

        extra.includePaths = GUIDsToPaths(bundle.includeGUIDs);

        string[] files = BuildHelper.GetAssetsFromPaths(extra.includeAssetPaths.ToArray(), bundle.bundleType);
        extra.includeAssetPaths = new List <string>(files);
        extra.includeAssetGUIDs = PathsToGUIDs(extra.includeAssetPaths);

        extra.dependPaths = new List <string>(AssetDatabase.GetDependencies(files));
        extra.dependPaths.RemoveAll(path => path.EndsWith(".cs"));
        extra.dependPaths.RemoveAll(x => extra.includePaths.Contains(x));

        extra.dependGUIDs = new List <string>(PathsToGUIDs(extra.dependPaths.ToArray()));

        AddDependRefs(bundle);
    }
Ejemplo 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);
    }
Ejemplo n.º 8
0
    static void GUI_DependencyList()
    {
        var extra = currentBundle.GetExtraData();

        if (!BMDataAccessor.DependencyUpdated)
        {
            GUILayout.Label("DEPEND", BMGUIStyles.GetStyle("UnfoldableTitle"));
            EditorGUILayout.HelpBox("Need Update Dependencies", MessageType.Info);
            return;
        }

        if (extra.dependGUIDs.Count > 0)
        {
#if !(UNITY_4_2 || UNITY_4_1 || UNITY_4_0)
            m_FoldoutMetaFiles = EditorGUILayout.Foldout(m_FoldoutMetaFiles, "DEPEND", BMGUIStyles.GetStyle("CFoldout"));
#else
            m_FoldoutMetaFiles = EditorGUILayout.Foldout(m_FoldoutMetaFiles, "DEPEND");
#endif
        }
        else
        {
            GUILayout.Label("DEPEND", BMGUIStyles.GetStyle("UnfoldableTitle"));
            return;
        }

        if (m_FoldoutMetaFiles)
        {
            EditorGUILayout.BeginVertical();
            {
                foreach (string guid in extra.dependGUIDs)
                {
                    string assetPath           = AssetDatabase.GUIDToAssetPath(guid);
                    bool   isCurrentPathSelect = m_CurSelectAsset == guid && m_IsMetaListSelect;
                    var    iconTexture         = GetSharedIconOfDepend(guid);
                    if (m_HideGreenDependencies && iconTexture && iconTexture.name == "sharedAsset")
                    {
                        continue;
                    }
                    if (GUI_AssetItem(assetPath, isCurrentPathSelect, iconTexture) != AssetItemState.None)
                    {
                        if (!isCurrentPathSelect)
                        {
                            m_IsMetaListSelect = true;
                            m_CurSelectAsset   = guid;
                        }
                        else
                        {
                            if (EditorApplication.timeSinceStartup - m_LastClickTime < 2f)
                            {
                                // Double clicked
                                EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath(assetPath, typeof(Object)));
                            }
                            else
                            {
                                m_CurSelectAsset = "";
                            }
                        }

                        m_LastClickTime = EditorApplication.timeSinceStartup;
                        Refresh();
                    }
                }
            } EditorGUILayout.EndVertical();
        }
    }
Ejemplo n.º 9
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);
    }