Exemple #1
0
    /**
     * Add a path to bundle's include list.
     * @param path The path must be a path under Asset. Can be path of diretory or file.
     * @param bundleName The bundle's name.
     */
    public static void AddPathToBundle(string path, string bundleName)
    {
        BundleData bundle = GetBundleData(bundleName);

        //������ӵĴ���
        if (bundle.bundleRelativePath == "" || bundle == null)
        {
            bundle.bundleRelativePath = path.Substring(0, path.LastIndexOf("/"));
        }
        //������ӵĴ���


        if (IsNameDuplicatedAsset(bundle, path))
        {
            Debug.LogWarning("Name of new add asset will be duplicate with asset in bundle " + bundleName + ". This may cause problem when you trying to load them.");
        }

        string guid = AssetDatabase.AssetPathToGUID(path);

        bundle.includeGUIDs.Add(guid);

        AddIncludeRef(guid, bundle);
        RefreshBundleDependencies(bundle);
        UpdateBundleChangeTime(bundle.name);

        BMDataAccessor.SaveBundleData();
    }
Exemple #2
0
    void Update()
    {
        if (lastTimeSelection != LastSelection())
        {
            lastTimeSelection = LastSelection();
            BundleEditorDrawer.ShowBundle(BundleManager.GetBundleData(lastTimeSelection));
        }

        if (m_EditWaitBundle != "" && m_EditWaitStartTime > 0)
        {
            // See if we can start edit
            if (EditorApplication.timeSinceStartup - m_EditWaitStartTime > 0.6)
            {
                StartEditBundleName(m_EditWaitBundle);
            }
        }

        if (BMDataAccessor.ShouldSaveBundleData)
        {
            BMDataAccessor.ShouldSaveBundleData = false;
            BMDataAccessor.SaveBundleData();
        }
        if (BMDataAccessor.ShouldSaveBundleStates)
        {
            BMDataAccessor.ShouldSaveBundleStates = false;
            BMDataAccessor.SaveBundleBuildeStates();
        }
    }
    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();
    }
Exemple #4
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);
    }
Exemple #5
0
    //remove all bundle
    static public void RemoveAllBundles()
    {
        List <string> allBundleName = new List <string>();

        foreach (var bundleName in getInstance().bundleDict.Keys)
        {
            allBundleName.Add(bundleName);
        }

        foreach (var bundleName in allBundleName)
        {
            var bundleDict     = getInstance().bundleDict;
            var bundlelist     = BMDataAccessor.Bundles;
            var dependRefDict  = getInstance().dependRefDict;
            var includeRefDict = getInstance().includeRefDict;

            if (!bundleDict.ContainsKey(bundleName))
            {
                continue;
            }

            BundleData bundle = bundleDict[bundleName];
            bundlelist.Remove(bundle);
            bundleDict.Remove(bundleName);

            var buildStatesDict = getInstance().statesDict;
            BMDataAccessor.BuildStates.Remove(buildStatesDict[bundleName]);
            buildStatesDict.Remove(bundleName);

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

            // Remove include ref
            foreach (string assetPath in bundle.includs)
            {
                includeRefDict[assetPath].Remove(bundle);
            }

            // Remove depend asssets ref
            foreach (string assetPath in bundle.dependAssets)
            {
                dependRefDict[assetPath].Remove(bundle);
            }

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

        BMDataAccessor.SaveBundleData();
        BMDataAccessor.SaveBundleBuildeStates();
    }
Exemple #6
0
    void RefreshAllBundle()
    {
        for (int i = 0; i < BundleManager.bundles.Length; i++)
        {
            BundleManager.RefreshBundleDependencies(BundleManager.bundles[i]);
        }

        BundleManager.RefreshExInclude();

        BMDataAccessor.SaveBundleData();
    }
Exemple #7
0
    void GUI_DeleteMenuCallback()
    {
        foreach (string bundle in m_Selections)
        {
            BundleManager.RemoveBundle(bundle);
        }

        BMDataAccessor.SaveBundleData();
        m_Selections.Clear();
        Repaint();
    }
Exemple #8
0
    /**
     * Remove path from bundle's include list.
     */
    public static void RemovePathFromBundle(string path, string bundleName)
    {
        BundleData bundle = GetBundleData(bundleName);

        bundle.includs.Remove(path);

        getInstance().includeRefDict[path].Remove(bundle);
        RefreshBundleDependencies(bundle);
        UpdateBundleChangeTime(bundle.name);

        BMDataAccessor.SaveBundleData();
    }
Exemple #9
0
    /**
     * Remove asset from bundle's include list by guid.
     */
    public static void RemoveAssetFromBundle(string guid, string bundleName)
    {
        BundleData bundle = GetBundleData(bundleName);

        bundle.includeGUIDs.Remove(guid);

        RemoveIncludeRef(guid, bundle);
        RefreshBundleDependencies(bundle);
        UpdateBundleChangeTime(bundle.name);

        BMDataAccessor.SaveBundleData();
    }
Exemple #10
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;

        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].children.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.dependGUIDs)
        {
            dependRefDict[guid].Remove(bundle);
        }

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

        BMDataAccessor.SaveBundleData();
        BMDataAccessor.SaveBundleBuildeStates();
        return(true);
    }
    static void OnPostprocessAllAssets(string[] importAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromPathes)
    {
#if IIPS
        List <string> changedAssets = new List <string>();
        changedAssets.AddRange(importAssets);
        changedAssets.AddRange(deletedAssets);
        changedAssets.AddRange(movedFromPathes);

        List <string> createdAssets = new List <string>();
        createdAssets.AddRange(importAssets);
        createdAssets.AddRange(movedAssets);

        bool dataChanged = false;
        foreach (string assetPath in changedAssets)
        {
            List <BundleData> bundles = BundleManager.GetRelatedBundles(assetPath);
            if (bundles == null)
            {
                continue;
            }

            foreach (BundleData bundle in bundles.ToArray())            // Use ToArray to make a copy to prevent change the org bundle list.
            {
                BundleManager.RefreshBundleDependencies(bundle);
                dataChanged = true;
            }
        }

        foreach (string assetPath in createdAssets)
        {
            foreach (BundleData bundle in BundleManager.bundles)
            {
                foreach (string include in bundle.includs)
                {
                    if (assetPath.Contains(include))
                    {
                        BundleManager.RefreshBundleDependencies(bundle);
                        dataChanged = true;
                    }
                }
            }
        }

        if (dataChanged)
        {
            BMDataAccessor.SaveBundleData();
        }
#endif
    }
Exemple #12
0
    /**
     * Set the parent of the bundle.
     * @param parent New parent bundle's name. Set the parent to empty if you want the childe bundle become a root bundle.
     */
    static public void SetParent(string childe, string parent)
    {
        if (!CanBundleParentTo(childe, parent))
        {
            return;
        }

        var bundleDict = getInstance().bundleDict;

        if (!bundleDict.ContainsKey(childe) || (parent != "" && !bundleDict.ContainsKey(parent)))
        {
            return;
        }

        BundleData childeBundle = bundleDict[childe];

        if (bundleDict.ContainsKey(childeBundle.parent))
        {
            bundleDict[childeBundle.parent].children.Remove(childe);
        }

        string origParent = childeBundle.parent;

        childeBundle.parent = parent;

        if (parent != "")
        {
            BundleData newParentBundle = bundleDict[parent];
            newParentBundle.children.Add(childe);
            newParentBundle.children.Sort();
        }

        if (parent == "" || origParent == "")
        {
            BMDataAccessor.Bundles.Remove(childeBundle);
            InsertBundleToBundleList(childeBundle);
        }

        UpdateBundleChangeTime(childeBundle.name);
        BMDataAccessor.SaveBundleData();

        GM.BundleInfo bundleInfo = BMDataAccessor.BundleShipInfos.Find(item => item.BundleName == childe);
        if (bundleInfo != null)
        {
            bundleInfo.Parent = parent.StartsWith("+") ? "" : parent;
        }
        BMDataAccessor.SaveBundleShipInfoFile();
    }
Exemple #13
0
    /**
     * Add a path to bundle's include list.
     * @param path The path must be a path under Asset. Can be path of diretory or file.
     * @param bundleName The bundle's name.
     */
    public static void AddPathToBundle(string path, string bundleName)
    {
        BundleData bundle = GetBundleData(bundleName);

        if (IsNameDuplicatedAsset(bundle, path))
        {
            UnityEngine.Debug.LogWarning("Name of new add asset will be duplicate with asset in bundle " + bundleName + ". This may cause problem when you trying to load them.");
        }

        bundle.includs.Add(path);

        AddIncludeRef(path, bundle);
        RefreshBundleDependencies(bundle);
        UpdateBundleChangeTime(bundle.name);

        BMDataAccessor.SaveBundleData();
    }
Exemple #14
0
    private static void checkOldVersion()
    {
        if (BMDataAccessor.BMConfiger.bmVersion == 0)
        {
            EditorUtility.DisplayDialog("Bundle Manager Upgrade",
                                        "Welcome to new version. Bundle Manager will upgrade your Bundle Data files to new version.",
                                        "OK");
            BMDataAccessor.BMConfiger.bmVersion = 1;
            foreach (BundleData bundle in BMDataAccessor.Bundles)
            {
                bundle.includeGUIDs = PathsToGUIDs(bundle.includs);
                bundle.dependGUIDs  = PathsToGUIDs(bundle.dependAssets);
            }

            BMDataAccessor.SaveBundleData();
            BMDataAccessor.SaveBMConfiger();
        }
    }
Exemple #15
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);
    }
Exemple #16
0
    /**
     * Add a path to bundle's include list.
     * @param path The path must be a path under Asset. Can be path of diretory or file.
     * @param bundleName The bundle's name.
     */
    public static void AddPathToBundle(string path, string bundleName)
    {
        BundleData bundle = GetBundleData(bundleName);

        if (IsNameDuplicatedAsset(bundle, path))
        {
            EB.Debug.LogWarning("Name of new add asset will be duplicate with asset in bundle {0}. This may cause problem when you trying to load them.", bundleName);
        }

        string guid = AssetDatabase.AssetPathToGUID(path);

        bundle.includeGUIDs.Add(guid);

        AddIncludeRef(guid, bundle);
        RefreshBundleDependencies(bundle);
        UpdateBundleChangeTime(bundle.name);

        BMDataAccessor.SaveBundleData();
    }
Exemple #17
0
    /**
     * Set the parent of the bundle.
     * @param parent New parent bundle's name. Set the parent to empty if you want the childe bundle become a root bundle.
     */
    static public void SetParent(string childe, string parent)
    {
        if (!CanBundleParentTo(childe, parent))
        {
            return;
        }

        var bundleDict = getInstance().bundleDict;

        if (!bundleDict.ContainsKey(childe) || (parent != "" && !bundleDict.ContainsKey(parent)))
        {
            return;
        }

        BundleData childeBundle = bundleDict[childe];

        if (bundleDict.ContainsKey(childeBundle.parent))
        {
            bundleDict[childeBundle.parent].children.Remove(childe);
        }

        string origParent = childeBundle.parent;

        childeBundle.parent = parent;

        if (parent != "")
        {
            BundleData newParentBundle = bundleDict[parent];
            newParentBundle.children.Add(childe);
            newParentBundle.children.Sort();
        }

        if (parent == "" || origParent == "")
        {
            BMDataAccessor.Bundles.Remove(childeBundle);
            InsertBundleToBundleList(childeBundle);
        }

        UpdateBundleChangeTime(childeBundle.name);
        BMDataAccessor.SaveBundleData();
    }
Exemple #18
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);
    }
Exemple #19
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();
    }
Exemple #20
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);
    }