Пример #1
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();
        }
    }
Пример #2
0
    internal static void UpdateAllBundleChangeTime()
    {
        foreach (BundleData bundle in bundles)
        {
            UpdateBundleChangeTime(bundle.name);
        }

        BMDataAccessor.SaveBundleBuildeStates();
    }
Пример #3
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();
    }
Пример #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);
    }
Пример #5
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);
    }
Пример #6
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);
    }
Пример #7
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);
    }
Пример #8
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);
    }
Пример #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 (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);
    }
Пример #10
0
    private static void BuildAll()
    {
        InitState();

        LoadShaderList();

        List <string> buildList = GetObjectPathByConfig();

        List <BundleData> bundles = new List <BundleData>();

        for (int i = 0; i < buildList.Count; i++)
        {
            bundles.Add(AddRootBundleData(buildList[i]));
        }


        for (int i = 0; i < bundles.Count; i++)
        {
            if (BuildHelp.BuildRootBundle(bundles[i]))
            {
                DependsData.Add(CreateDependsData(bundles[i]));
            }
        }
        //BuildPipeline.BuildAssetBundles()
        //
        if (DependsData.Count > 0)
        {
            string dependsConfigPath = BuildHelp.GenerateOutputDependsPath();
            BMDataAccessor.SaveBundleBuildeStates();
            BMDataAccessor.SaveObjectToJsonFile <List <BundleDependsData> >(DependsData, dependsConfigPath);
            BMDataAccessor.SaveReleaseDependsData(DependsData, BundleSetting.PlatformOutputPath + "/DependsData.release");
            BMDataAccessor.ClearBundleBuildStates(DependsData);
            DependsData.Clear();
        }
        else
        {
            Debug.Log("There is no written DependsData.txt!");
        }
    }
Пример #11
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);
    }
Пример #12
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);
    }