Esempio n. 1
0
        public void InitResMgr()
        {
#if UNITY_EDITOR
            if (AssetBundleSettings.SimulateAssetBundleInEditor)
            {
                AssetBundleSettings.AssetBundleConfigFile = EditorRuntimeAssetDataCollector.BuildDataTable();
            }
            else
#endif
            {
                AssetBundleSettings.AssetBundleConfigFile.Reset();

                var outResult = new List <string>();

                // 未进行过热更
                if (ResKit.LoadResFromStreammingAssetsPath)
                {
                    FileMgr.Instance.GetFileInInner(AssetBundleSettings.AssetBundleConfigFile.FileName, outResult);
                }
                // 进行过热更
                else
                {
                    FilePath.GetFileInFolder(FilePath.PersistentDataPath, AssetBundleSettings.AssetBundleConfigFile.FileName, outResult);
                }

                foreach (var outRes in outResult)
                {
                    Debug.Log(outRes);
                    AssetBundleSettings.AssetBundleConfigFile.LoadFromFile(outRes);
                }
            }
        }
Esempio n. 2
0
        public void InitResMgr()
        {
#if UNITY_EDITOR
            if (Res.SimulateAssetBundleInEditor)
            {
                EditorRuntimeAssetDataCollector.BuildDataTable();
            }
            else
#endif
            {
                ResDatas.Instance.Reset();
                var outResult = new List <string>();

                // 未进行过热更
                if (ResKit.LoadResFromStreammingAssetsPath)
                {
                    QFramework.FileMgr.Instance.GetFileInInner("asset_bindle_config.bin", outResult);
                }
                // 进行过热更
                else
                {
                    FilePath.GetFileInFolder(FilePath.PersistentDataPath, "asset_bindle_config.bin", outResult);
                }

                foreach (var outRes in outResult)
                {
                    Debug.Log(outRes);
                    ResDatas.Instance.LoadFromFile(outRes);
                }
            }

            ResDatas.Instance.SwitchLanguage("cn");
        }
Esempio n. 3
0
        public static void BuildDataTable()
        {
            //Log.I("Start BuildAssetDataTable!");
            ResDatas table = new ResDatas();

            EditorRuntimeAssetDataCollector.AddABInfo2ResDatas(table);

            var filePath =
                (FilePath.StreamingAssetsPath + ResKitUtil.RELATIVE_AB_ROOT_FOLDER).CreateDirIfNotExists() +
                table.FileName;

            table.Save(filePath);
            AssetDatabase.Refresh();
        }
Esempio n. 4
0
        public IEnumerator InitResMgrAsync()
        {
#if UNITY_EDITOR
            if (AssetBundleSettings.SimulateAssetBundleInEditor)
            {
                ResKit.ResData = EditorRuntimeAssetDataCollector.BuildDataTable();
                yield return(null);
            }
            else
#endif
            {
                ResKit.ResData.Reset();

                var    outResult  = new List <string>();
                string pathPrefix = "";
#if UNITY_EDITOR || UNITY_IOS
                pathPrefix = "file://";
#endif
                // 未进行过热更
                if (ResKit.LoadResFromStreammingAssetsPath)
                {
                    string streamingPath = Application.streamingAssetsPath + "/AssetBundles/" +
                                           AssetBundleSettings.GetPlatformName() + "/" + ResKit.ResData.FileName;
                    outResult.Add(pathPrefix + streamingPath);
                }
                // 进行过热更
                else
                {
                    string persistenPath = Application.persistentDataPath + "/AssetBundles/" +
                                           AssetBundleSettings.GetPlatformName() + "/" + ResKit.ResData.FileName;
                    outResult.Add(pathPrefix + persistenPath);
                }

                foreach (var outRes in outResult)
                {
                    Debug.Log(outRes);
                    yield return(ResKit.ResData.LoadFromFileAsync(outRes));
                }

                yield return(null);
            }
        }
Esempio n. 5
0
        public void InitResMgr()
        {
#if UNITY_EDITOR
            if (AbstractRes.SimulateAssetBundleInEditor)
            {
                EditorRuntimeAssetDataCollector.BuildDataTable();
            }
            else
#endif
            {
                ResDatas.Instance.Reset();
                var outResult = new List <string>();
                FileMgr.Instance.GetFileInInner("asset_bindle_config.bin", outResult);
                foreach (var outRes in outResult)
                {
                    ResDatas.Instance.LoadFromFile(outRes);
                }
            }

            ResDatas.Instance.SwitchLanguage("cn");
        }
Esempio n. 6
0
        public IEnumerator InitResMgrAsync()
        {
#if UNITY_EDITOR
            if (Res.SimulateAssetBundleInEditor)
            {
                EditorRuntimeAssetDataCollector.BuildDataTable();
                yield return(null);
            }
            else
#endif
            {
                ResDatas.Instance.Reset();

                var outResult = new List <string>();

                // 未进行过热更
                if (ResKit.LoadResFromStreammingAssetsPath)
                {
                    outResult.Add(Application.streamingAssetsPath + "/AssetBundles/" + ResKitUtil.GetPlatformName() + "/asset_bindle_config.bin");
                }
                // 进行过热更
                else
                {
                    outResult.Add(Application.persistentDataPath + "/AssetBundles/" + ResKitUtil.GetPlatformName() + "/asset_bindle_config.bin");
                }

                foreach (var outRes in outResult)
                {
                    Debug.Log(outRes);
                    yield return(ResDatas.Instance.LoadFromFileAsync(outRes));
                }

                yield return(null);
            }

            ResDatas.Instance.SwitchLanguage("cn");
        }
Esempio n. 7
0
        public static void WriteClass(TextWriter writer, string ns)
        {
            EditorRuntimeAssetDataCollector.BuildDataTable();
            var allAssetDataGroups = ResDatas.Instance.AllAssetDataGroups;

            var assetBundleInfos = new List <AssetBundleInfo>();

            allAssetDataGroups.ForEach(assetDataGroup =>
            {
                var assetDatas = assetDataGroup.AssetBundleDatas;

                assetDatas.ForEach(abUnit =>
                {
                    assetBundleInfos.Add(new AssetBundleInfo(abUnit.abName)
                    {
                        assets = assetDataGroup.AssetDatas
                                 .Where(assetData => assetData.OwnerBundleName == abUnit.abName)
                                 .Select(assetData => assetData.AssetName)
                                 .ToArray()
                    });
                });
            });

            var compileUnit   = new CodeCompileUnit();
            var codeNamespace = new CodeNamespace(ns);

            compileUnit.Namespaces.Add(codeNamespace);

            foreach (var assetBundleInfo in assetBundleInfos)
            {
                var className  = assetBundleInfo.Name;
                var bundleName = className.Substring(0, 1).ToLower() + className.Substring(1);
                int firstNumber;
                if (int.TryParse(bundleName[0].ToString(), out firstNumber))
                {
                    continue;
                }

                className = className.Substring(0, 1).ToUpper() +
                            className.Substring(1).Replace("/", "_").Replace("@", "_").Replace("!", "_");

                var codeType = new CodeTypeDeclaration(className);
                codeNamespace.Types.Add(codeType);

                var bundleNameField = new CodeMemberField
                {
                    Attributes = MemberAttributes.Public | MemberAttributes.Const,
                    Name       = "BundleName",
                    Type       = new CodeTypeReference(typeof(System.String))
                };
                codeType.Members.Add(bundleNameField);
                bundleNameField.InitExpression = new CodePrimitiveExpression(bundleName.ToLowerInvariant());

                var checkRepeatDict = new Dictionary <string, string>();
                foreach (var asset in assetBundleInfo.assets)
                {
                    var assetField = new CodeMemberField {
                        Attributes = MemberAttributes.Public | MemberAttributes.Const
                    };

                    var content = Path.GetFileNameWithoutExtension(asset);
                    assetField.Name = content.ToUpperInvariant().Replace("@", "_").Replace("!", "_");
                    assetField.Type = new CodeTypeReference(typeof(System.String));
                    if (!assetField.Name.StartsWith("[") && !assetField.Name.StartsWith(" [") &&
                        !checkRepeatDict.ContainsKey(assetField.Name))
                    {
                        checkRepeatDict.Add(assetField.Name, asset);
                        codeType.Members.Add(assetField);
                    }

                    assetField.InitExpression = new CodePrimitiveExpression(content);
                }

                checkRepeatDict.Clear();
            }

            var provider = new CSharpCodeProvider();
            var options  = new CodeGeneratorOptions
            {
                BlankLinesBetweenMembers = false,
                BracingStyle             = "C"
            };

            provider.GenerateCodeFromCompileUnit(compileUnit, writer, options);
        }