Пример #1
0
        protected virtual IBundleFileManifest Build(IBundleBuildConfig config, IBundleGroup group, BundlePackRule rule)
        {
            var data = new BundleBuildData
            {
                TopDirectoryPath = config.TargetDirPath,
                Identifier       = group.Identifier,
                ABName           = config.GetBundleName(group.Identifier),
                Assets           = group.Assets,
                Labels           = rule.Labels,
            };

            data.CalcAddress();
            return(data);
        }
Пример #2
0
        /// <summary>
        /// 単一データ作成
        /// </summary>
        private BundleBuildData CreateBuildData(IAccessLocation file, IBundleFileManifest buildFileData, IReadOnlyDictionary <string, string> table, AssetBundleManifest manifest)
        {
            var identifier   = buildFileData?.Identifier;
            var abName       = buildFileData?.ABName;
            var crc          = FsUtillity.TryGetCrc(file.FullPath);
            var hash         = manifest.TryGetHashString(abName);
            var dependencies = manifest.TryGetDependencies(abName).Select(c => table[c]).ToArray();
            var size         = FsUtillity.TryGetFileSize(file.FullPath);

            var d = new BundleBuildData
            {
                Path         = abName,
                Identifier   = identifier,
                Assets       = buildFileData?.Address,
                Hash         = hash,
                Crc          = crc,
                Dependencies = dependencies,
                FileSize     = size,
                Labels       = buildFileData?.Labels,
            };

            return(d);
        }
Пример #3
0
        public static void BuildAndEmbedAssetBundles(FileInfo modDll, FileInfo weaverCoreDLL, MethodInfo OnComplete)
        {
            Data = new BundleBuildData
            {
                ModDLL             = modDll == null ? "" : modDll.FullName,
                ModName            = modDll == null ? "" : modDll.Name.Replace(".dll", ""),
                WeaverCoreOnly     = modDll == null,
                WeaverCoreDLL      = weaverCoreDLL.FullName,
                PreBuildInfo       = ScriptFinder.GetProjectScriptInfo(),
                ExcludedAssemblies = new List <ExcludedAssembly>(),
                OnComplete         = new SerializedMethod(OnComplete),
                BundlingSuccessful = false
            };
            /**/
            PrepareForAssetBundling(new List <string> {
                "WeaverCore.Editor"
            }, typeof(BundleTools).GetMethod(nameof(BeginBundleProcess), BindingFlags.Static | BindingFlags.NonPublic));
        }

        static bool IsFileLocked(FileInfo file)
        {
            try
            {
                using (FileStream stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.None))
                {
                    stream.Close();
                }
            }
            catch (IOException)
            {
                //the file is unavailable because it is:
                //still being written to
                //or being processed by another thread
                //or does not exist (has already been processed)
                return(true);
            }

            //file is not locked
            return(false);
        }

        static void PrepareForAssetBundling(List <string> ExcludedAssemblies, MethodInfo whenReady)
        {
            //AssetDatabase.DisallowAutoRefresh();
            Debug.Log("Preparing Assets for Bundling");
            //UnboundCoroutine.Start(Delay());
            //IEnumerator Delay()
            //{

            /*yield return new WaitForSeconds(0.5f);
             * foreach (var registry in RegistryChecker.LoadAllRegistries())
             * {
             *      registry.ReplaceAssemblyName("Assembly-CSharp", Data.ModName);
             *      registry.ApplyChanges();
             * }*/
            //Debug.Log("A_Editor File Locked = " + IsFileLocked(new FileInfo("Library\\ScriptAssemblies\\WeaverCore.Editor.dll")));

            /*var buildCache = new DirectoryInfo("Library\\BuildCache");
             * if (buildCache.Exists)
             * {
             *      buildCache.Delete(true);
             * }*/
            //yield return new WaitForSeconds(0.5f);
            //Debug.Log("B_Editor File Locked = " + IsFileLocked(new FileInfo("Library\\ScriptAssemblies\\WeaverCore.Editor.dll")));
            //yield return new WaitUntil(() => !EditorApplication.isCompiling);
            //AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
            //yield return new WaitForSeconds(0.5f);
            //Debug.Log("C_Editor File Locked = " + IsFileLocked(new FileInfo("Library\\ScriptAssemblies\\WeaverCore.Editor.dll")));
            //yield return new WaitUntil(() => !EditorApplication.isCompiling);
#if REWRITE_REGISTRIES
            foreach (var registry in RegistryChecker.LoadAllRegistries())
            {
                registry.ReplaceAssemblyName("Assembly-CSharp", Data.ModName);
                registry.ApplyChanges();
            }
#endif
            Data.Registries = new List <RegistryInfo>();
            var registryIDs = AssetDatabase.FindAssets($"t:{nameof(Registry)}");
            foreach (var id in registryIDs)
            {
                var path     = AssetDatabase.GUIDToAssetPath(id);
                var registry = AssetDatabase.LoadAssetAtPath <Registry>(path);
                Data.Registries.Add(new RegistryInfo
                {
                    AssemblyName    = registry.ModAssemblyName,
                    AssetBundleName = GetAssetBundleName(registry),
                    ModTypeName     = registry.ModName,
                    RegistryName    = registry.RegistryName,
                    Path            = path
                });
            }
            //yield return new WaitForSeconds(0.5f);
            //Debug.Log("D_Editor File Locked = " + IsFileLocked(new FileInfo("Library\\ScriptAssemblies\\WeaverCore.Editor.dll")));
            //yield return new WaitUntil(() => !EditorApplication.isCompiling);
            bool assetsChanged = false;
            try
            {
                AssetDatabase.StartAssetEditing();
                foreach (var asm in Data.PreBuildInfo.Where(i => ExcludedAssemblies.Contains(i.AssemblyName)))
                {
                    if (asm.Definition.includePlatforms.Count == 1 && asm.Definition.includePlatforms[0] == "Editor")
                    {
                        continue;
                    }
                    Data.ExcludedAssemblies.Add(new ExcludedAssembly()
                    {
                        AssemblyName = asm.AssemblyName,
                        OriginalExcludedPlatforms = asm.Definition.excludePlatforms,
                        OriginalIncludedPlatforms = asm.Definition.includePlatforms
                    });
                    asm.Definition.excludePlatforms = new List <string>();
                    asm.Definition.includePlatforms = new List <string>
                    {
                        "Editor"
                    };
                    //Debug.Log("Asm Definition Path = " + asm.AssemblyDefinitionPath);
                    //Debug.Log("Importing Asset = " + asm.AssemblyDefinitionPath);
                    asm.Save();
                    AssetDatabase.ImportAsset(asm.AssemblyDefinitionPath, ImportAssetOptions.ForceUpdate);
                    assetsChanged = true;
                }
                if (assetsChanged)
                {
                    Data.NextMethod = new SerializedMethod(whenReady);
                }
                else
                {
                    Data.NextMethod = default;
                }
                PersistentData.StoreData(Data);
                PersistentData.SaveData();

                if (!assetsChanged && whenReady != null)
                {
                    whenReady.Invoke(null, null);
                }
            }
            catch (Exception e)
            {
                Debug.LogError("Exception occured" + e);
            }
            finally
            {
                AssetDatabase.StopAssetEditing();
                //if (assetsChanged)
                //{
                //AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
                //}
            }
            //}
        }