void GUIDrawItemDesc(GM.BundleInfo itemDesc)
    {
        bool     isReceiving       = mCurrentRecieving == itemDesc;
        bool     isSelecting       = mSelections.Contains(itemDesc);
        GUIStyle currentLabelStyle = BMGUIStyles.GetStyle("TreeItemUnSelect");

        if (isReceiving)
        {
            currentLabelStyle = BMGUIStyles.GetStyle("receivingLable");
        }
        else if (isSelecting)
        {
            currentLabelStyle = HasFocus() ? BMGUIStyles.GetStyle("TreeItemSelectBlue") : BMGUIStyles.GetStyle("TreeItemSelectGray");
        }

        Rect itemRect = EditorGUILayout.BeginHorizontal(currentLabelStyle);

        GUILayout.Label(BMGUIStyles.GetIcon("assetBundleIcon"), BMGUIStyles.GetStyle("BItemLabelNormal"), GUILayout.ExpandWidth(false));

        GUILayout.Label(new GUIContent(itemDesc.BundleName), isSelecting ? BMGUIStyles.GetStyle("BItemLabelActive") : BMGUIStyles.GetStyle("BItemLabelNormal"), GUILayout.ExpandWidth(true));

        EditorGUILayout.EndHorizontal();

        if (DragProcess(itemRect, itemDesc))
        {
            return;
        }

        SelectProcess(itemRect, itemDesc);
    }
    void OnRecieve(GUIDragHandler.DragDatas recieverData, GUIDragHandler.DragDatas dragData)
    {
        try
        {
            GM.BundleInfo recieverItem = mCurrentRecieving;
            if (recieverItem == null)
            {
                return;
            }

            List <GM.BundleInfo> dragItems = dragData.customDragData as List <GM.BundleInfo>;

            List <GM.BundleInfo> tmpList = mCurrentEditItems;
            mCurrentEditItems = null;
            foreach (GM.BundleInfo _desc in dragItems)
            {
                tmpList.Remove(_desc);
            }

            int _idx = tmpList.IndexOf(recieverItem);
            tmpList.InsertRange(_idx, dragItems);
            mCurrentEditItems = tmpList;
            tmpList           = null;

            mCurrentEditItemsChanged = true;

            //SaveBundleShipInfoFile();

            Repaint();
        }
        catch (System.Exception ex)
        {
            Debug.LogError(ex.ToString());
        }
    }
    void SelectProcess(Rect itemRect, GM.BundleInfo itemDesc)
    {
        if (IsRectClicked(itemRect) && !Event.current.alt)
        {
            if (Control())
            {
                if (mSelections.Contains(itemDesc))
                {
                    mSelections.Remove(itemDesc);
                }
                else
                {
                    mSelections.Add(itemDesc);
                }
            }
            else if (Event.current.shift)
            {
                ShiftSelection(itemDesc);
            }
            else if (Event.current.button == 0 || !mSelections.Contains(itemDesc))
            {
                mSelections.Clear();
                mSelections.Add(itemDesc);
            }

            Repaint();
        }
    }
Beispiel #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);
    }
    void ShiftSelection(GM.BundleInfo newSelect)
    {
        if (mSelections.Count == 0)
        {
            mSelections.Add(newSelect);
            return;
        }

        int _min = System.Int32.MaxValue;
        int _max = System.Int32.MinValue;

        foreach (GM.BundleInfo _desc in mSelections)
        {
            int _idx = mCurrentEditItems.IndexOf(_desc);
            if (_min > _idx)
            {
                _min = _idx;
            }

            if (_max < _idx)
            {
                _max = _idx;
            }
        }

        int _newIdx = mCurrentEditItems.IndexOf(newSelect);

        if (_newIdx < _min)
        {
            _min = _newIdx;
        }

        if (_newIdx > _max)
        {
            _max = _newIdx;
        }

        if (_min < 0)
        {
            _min = 0;
        }
        if (_max >= mCurrentEditItems.Count)
        {
            _max = mCurrentEditItems.Count - 1;
        }

        mSelections.Clear();
        mSelections.AddRange(mCurrentEditItems.GetRange(_min, _max - _min + 1));
    }
Beispiel #6
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();
    }
    bool DragProcess(Rect itemRect, GM.BundleInfo itemDesc)
    {
        if (Event.current.type == EventType.Repaint || itemRect.height <= 0)
        {
            return(false);
        }

        if (!IsMouseOn(itemRect))
        {
            if (mCurrentRecieving != null && mCurrentRecieving == itemDesc)
            {
                mCurrentRecieving = null;
                Repaint();
            }

            return(false);
        }

        mDragHandler.detectRect = itemRect;
        mDragHandler.dragData.customDragData = (object)mSelections;
        mDragHandler.dragAble = (mSelections != null && mSelections.Count > 0);

        GUIDragHandler.DragState dragState = mDragHandler.GUIDragUpdate();
        if (dragState == GUIDragHandler.DragState.Receiving)
        {
            mCurrentRecieving = itemDesc;
            Repaint();
        }
        else if (dragState == GUIDragHandler.DragState.Received)
        {
            mCurrentRecieving = null;
        }
        else if (mCurrentRecieving == itemDesc)
        {
            mCurrentRecieving = null;
            Repaint();
        }

        return(dragState == GUIDragHandler.DragState.Received);
    }
Beispiel #8
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);
    }
Beispiel #9
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);
    }
Beispiel #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();

        GM.BundleInfo bundleInfo = BMDataAccessor.BundleShipInfos.Find(item => item.BundleName == name);
        if (bundleInfo != null)
        {
            BMDataAccessor.BundleShipInfos.Remove(bundleInfo);
            BMDataAccessor.SaveBundleShipInfoFile();
        }

        return(true);
    }