Пример #1
0
 public void InitCollectDepData(AssetUnit unit)
 {
     if (!this.mDicCollectDepResourceData.ContainsKey(unit.mName))
     {
         List <string> deps = unit.mAllDependencies;
         List <string> temp = new List <string>();
         foreach (var dep in deps)
         {
             string name = BuildCommon.GetLevelABPathName(dep);
             temp.Add(name);
         }
         this.mDicCollectDepResourceData.Add(unit.mName, new CollectDepResourceData(unit.mName, temp));
     }
 }
Пример #2
0
    /// <summary>
    /// 打包资源为AssetBundle
    /// </summary>
    private static void BuildResource()
    {
        AssetDatabase.Refresh();
        int maxLevel = allLevelAssets.Count;

        if (maxLevel == 0)
        {
            return;
        }
        for (int level = 1; level <= maxLevel; level++)
        {
            BuildPipeline.PushAssetDependencies();
            Dictionary <string, AssetUnit> levelAssets = allLevelAssets[level];
            foreach (var pair in levelAssets)
            {
                UnityEngine.Object asset    = AssetDatabase.LoadMainAssetAtPath(pair.Value.mPath);
                string             savePath = "";
                pair.Value.mName = BuildCommon.GetLevelABPathName(pair.Value.mPath);
                if (null == asset)
                {
                    Debug.LogError("Load :" + pair.Value.mPath + "failed");
                }
                Debug.Log(pair.Value.mSuffix);
                if (pair.Value.mSuffix.Equals("shader"))
                {
                    savePath         = "Assets/bin/data/shader/" + BuildCommon.GetLevelABPath(pair.Value.mPath);
                    pair.Value.mPath = "data/shader/" + BuildCommon.GetLevelABPath(pair.Value.mPath);
                }
                else if (pair.Value.mSuffix.Equals("mat"))
                {
                    savePath         = "Assets/bin/data/atlas/" + BuildCommon.GetLevelABPath(pair.Value.mPath);
                    pair.Value.mPath = "data/atlas/" + BuildCommon.GetLevelABPath(pair.Value.mPath);
                }
                else if (pair.Value.mSuffix.Equals("prefab"))
                {
                    if (pair.Value.mName.Contains("atla"))
                    {
                        savePath         = "Assets/bin/data/atlas/" + BuildCommon.GetLevelABPath(pair.Value.mPath);
                        pair.Value.mPath = "data/atlas/" + BuildCommon.GetLevelABPath(pair.Value.mPath);
                    }
                    else
                    {
                        savePath         = "Assets/bin/data/ui/" + BuildCommon.GetLevelABPath(pair.Value.mPath);
                        pair.Value.mPath = "data/ui/" + BuildCommon.GetLevelABPath(pair.Value.mPath);
                    }
                }
                else if (pair.Value.mSuffix.Equals("ttf"))
                {
                    savePath         = "Assets/bin/data/font/" + BuildCommon.GetLevelABPath(pair.Value.mPath);
                    pair.Value.mPath = "data/font/" + BuildCommon.GetLevelABPath(pair.Value.mPath);
                }
                else if (pair.Value.mSuffix.Equals("png") || pair.Value.mSuffix.Equals("psd") || pair.Value.mSuffix.Equals("dds"))
                {
                    savePath         = "Assets/bin/data/texture/" + BuildCommon.GetLevelABPath(pair.Value.mPath);
                    pair.Value.mPath = "data/texture/" + BuildCommon.GetLevelABPath(pair.Value.mPath);
                }
                else if (pair.Value.mSuffix.Equals("mp4"))
                {
                    savePath         = "Assets/bin/data/audio/" + BuildCommon.GetLevelABPath(pair.Value.mPath);
                    pair.Value.mPath = "data/audio/" + BuildCommon.GetLevelABPath(pair.Value.mPath);
                }
                else if (pair.Value.mSuffix.Equals("unity"))
                {
                    //pair.Value.mPath = "data/scene/" + BuildCommon.GetLevelABPath(pair.Value.mPath);
                    savePath = "Assets/bin/data/scene/" + BuildCommon.GetLevelABPath(pair.Value.mPath);
                }
                BuildCommon.CheckFolder(BuildCommon.getPath(savePath));
                //普通资源
                if (pair.Value.mSuffix != "unity")
                {
                    string assetName = pair.Value.mPath.Replace("Assets/", "");
                    uint   ver;
                    if (!BuildPipeline.BuildAssetBundle(asset, null, savePath, out ver, options, buildPlatform))
                    {
                        Debug.LogError("Build Assetbundle:" + savePath + " Failed");
                    }
                }
                //场景资源
                else
                {
                    AssetDatabase.Refresh();
                    BuildPipeline.PushAssetDependencies();
                    string error = BuildPipeline.BuildStreamedSceneAssetBundle(new string[] { pair.Value.mPath }, savePath, buildPlatform);
                    if (!string.IsNullOrEmpty(error))
                    {
                        Debug.LogError(error);
                    }
                    BuildPipeline.PopAssetDependencies();
                }
            }
        }
        for (int level = 1; level <= maxLevel; level++)
        {
            BuildPipeline.PopAssetDependencies();
        }
    }