Ejemplo n.º 1
0
 protected override void OnUnload()
 {
     if (request != null)
     {
         DLCAssetMgr.UnloadBundle(request);
     }
 }
Ejemplo n.º 2
0
        static void BuildManifestInternel(DLCItem dlcItem)
        {
            var    builds       = AssetBundleBuildsCache = BuildBuildRules(dlcItem);
            string dlcName      = dlcItem.Name;
            string manifestPath = DLCAssetMgr.GetDLCManifestPath(dlcName);
            string dlcItemPath  = DLCAssetMgr.GetDLCItemPath(dlcName);

            List <string> bundles = new List <string>();
            List <string> assets  = new List <string>();

            if (builds.Count > 0)
            {
                foreach (var item in builds)
                {
                    bundles.Add(item.assetBundleName);
                    foreach (var assetPath in item.assetNames)
                    {
                        assets.Add(assetPath + ":" + (bundles.Count - 1));
                    }
                }
            }

            #region 创建Manifest文件
            if (File.Exists(manifestPath))
            {
                File.Delete(manifestPath);
            }
            DLCManifest dlcManifest = new DLCManifest();
            foreach (var item in builds)
            {
                BundleData tempData = new BundleData();
                tempData.DLCName    = dlcItem.Name;
                tempData.BundleName = item.assetBundleName;
                foreach (var asset in item.assetNames)
                {
                    AssetPathData pathData = new AssetPathData();
                    pathData.FullPath = asset;
                    pathData.FileName = Path.GetFileNameWithoutExtension(asset);
                    if (AllAssets.ContainsKey(asset))
                    {
                        pathData.SourceBundleName = AllAssets[asset];
                    }
                    tempData.AssetFullPaths.Add(pathData);
                }
                dlcManifest.Data.Add(tempData);
            }
            BaseFileUtils.SaveJson(manifestPath, dlcManifest, true);
            #endregion

            #region dlcitem
            if (File.Exists(dlcItemPath))
            {
                File.Delete(dlcItemPath);
            }
            BaseFileUtils.SaveJson(dlcItemPath, dlcItem, true);
            #endregion

            CLog.Debug("[BuildScript] BuildManifest with " + assets.Count + " assets and " + bundles.Count + " bundels.");
        }
Ejemplo n.º 3
0
 internal Asset(string bundleName, string assetName, System.Type type)
 {
     this.assetName      = assetName;
     this.bundleName     = bundleName;
     this.assetFullPath  = DLCAssetMgr.GetAssetPath(bundleName, assetName);
     this.mapkey         = bundleName + assetName;
     this.realBundleName = DLCAssetMgr.GetBundleName(assetFullPath);
     this.dlcName        = DLCAssetMgr.GetDLCName(bundleName, assetName);
     assetType           = type;
 }
Ejemplo n.º 4
0
        protected override void OnLoad()
        {
#if UNITY_EDITOR
            if (DLCConfig.Ins.IsEditorMode)
            {
                asset = UnityEditor.AssetDatabase.LoadAssetAtPath(assetFullPath, assetType);
                return;
            }
#endif
            {
                request   = DLCAssetMgr.LoadBundle(realBundleName, dlcName, true);
                loadState = LoadStateType.Loading;
                loadCount = 0;
            }
        }
Ejemplo n.º 5
0
        protected override void OnLoad()
        {
#if UNITY_EDITOR
            if (DLCConfig.Ins.IsEditorMode)
            {
                asyncOperation = EditorSceneManager.LoadSceneAsyncInPlayMode(assetFullPath, new LoadSceneParameters(LoadSceneMode.Additive, LocalPhysicsMode.None));
                // UnityEditor.EditorApplication.LoadLevelAdditiveAsyncInPlayMode(assetFullPath);
                loadState = LoadStateType.Loading;
                loadCount = 0;
                return;
            }
#endif
            {
                request   = DLCAssetMgr.LoadBundle(realBundleName, dlcName, true);
                loadState = LoadStateType.Loading;
                loadCount = 0;
            }
        }
Ejemplo n.º 6
0
        protected override void OnLoad()
        {
#if UNITY_EDITOR
            if (DLCConfig.Ins.IsEditorMode)
            {
                asset = UnityEditor.AssetDatabase.LoadAssetAtPath(assetFullPath, assetType);
                return;
            }
#endif
            {
                request = DLCAssetMgr.LoadBundle(realBundleName, dlcName);
                if (request == null)
                {
                    if (DLCAssetMgr.IsNextLogError)
                    {
                        CLog.Error("错误:realBundleName:{0} dlcName:{1}", realBundleName, dlcName);
                    }
                    return;
                }
                asset = request.LoadAsset(assetName, assetType);
            }
        }
Ejemplo n.º 7
0
 static void Initialize()
 {
     Ins = BaseUtils.CreateGlobalObj <DLCAssetMgr>("DLCAssetMgr");
 }
Ejemplo n.º 8
0
        /// <summary>
        /// 导出的初始化
        /// </summary>
        void Init()
        {
            //计算DLC的跟目录
            RootPath = DLCAssetMgr.GetDLCRootPath(Name);
            //计算出绝对路径(拷贝文件使用)
            AbsRootPath = Path.Combine(BaseConstMgr.Path_Project, RootPath.Replace("Assets/", ""));
            //计算出目标路径
            TargetPath = Path.Combine(BaseConstMgr.Path_StreamingAssets, Name);

            //计算语言包路径
            if (DLCConfig.IsEditorMode)
            {
                LanguagePath = Path.Combine(RootPath, BaseConstMgr.Dir_Language);
            }
            else
            {
                LanguagePath = Path.Combine(TargetPath, BaseConstMgr.Dir_Language);
            }
            //计算lua路径
            if (DLCConfig.IsEditorMode)
            {
                LuaPath = Path.Combine(RootPath, BaseConstMgr.Dir_Lua);
            }
            else
            {
                LuaPath = Path.Combine(TargetPath, BaseConstMgr.Dir_Lua);
            }

            #region func
            EnsureDirectories();
            GenerateCopyPath();
            GeneralPath();
            //确保DLC相关路径存在
            void EnsureDirectories()
            {
                if (DLCConfig.IsEditorMode)
                {
                    BaseFileUtils.EnsureDirectory(AbsRootPath);
                    foreach (var item in Data)
                    {
                        BaseFileUtils.EnsureDirectory(Path.Combine(AbsRootPath, item.SearchPath));
                    }
                    foreach (var item in CopyDirectory)
                    {
                        BaseFileUtils.EnsureDirectory(Path.Combine(AbsRootPath, item));
                    }
                }
            }

            //建立拷贝路径
            void GenerateCopyPath()
            {
                AbsCopyDirectory.Clear();
                if (CopyDirectory != null)
                {
                    for (int i = 0; i < CopyDirectory.Count; ++i)
                    {
                        AbsCopyDirectory.Add(Path.Combine(AbsRootPath, CopyDirectory[i]));
                    }
                }
            }

            //建立打包路径
            void GeneralPath()
            {
                foreach (var item in Data)
                {
                    var vals  = item.SearchPath.Replace('\\', '/');
                    var temps = vals.Split('/');
                    if (temps == null || temps.Length == 0)
                    {
                        CLog.Error("路径错误:{0}", item.SearchPath);
                    }
                    item.FinalDirectory = temps[temps.Length - 1];
                    if (item.FinalDirectory == null)
                    {
                        CLog.Error("错误");
                    }

                    string tempRootPath = RootPath;
                    if (!item.CustomRootPath.IsInvStr())
                    {
                        tempRootPath = item.CustomRootPath;
                    }
                    item.FullSearchPath = tempRootPath + "/" + item.SearchPath;
                }
            }

            #endregion
        }