Ejemplo n.º 1
0
        static void Init()
        {
            //BuildWeaverCoreGameAsm();
            bool ranMethod = false;

            if (PersistentData.ContainsData <BundleTools.BundleBuildData>())
            {
                var bundleData = BundleTools.Data;
                if (bundleData?.NextMethod.Method != null)
                {
                    ranMethod = true;
                    var method = bundleData.NextMethod.Method;
                    bundleData.NextMethod = default;

                    PersistentData.StoreData(bundleData);
                    PersistentData.SaveData();

                    UnboundCoroutine.Start(Delay());

                    IEnumerator Delay()
                    {
                        yield return(new WaitForSeconds(0.5f));

                        method.Invoke(null, null);
                    }
                }
            }


            if (!ranMethod)
            {
                UnboundCoroutine.Start(BuildPartialWeaverCoreRoutine(WeaverCoreBuildLocation, null));
            }

            UnboundCoroutine.Start(RunEnvironmentCheck());
        }
Ejemplo n.º 2
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);
                //}
            }
            //}
        }
Ejemplo n.º 3
0
        static void DoneWithAssetBundling(MethodInfo whenFinished)
        {
            //Debug.Log("Done with Asset Bundling");
            //UnboundCoroutine.Start(Routine());
            //IEnumerator Routine()
            //{

            /*yield return new WaitForSeconds(0.5f);
             * foreach (var registry in RegistryChecker.LoadAllRegistries())
             * {
             *      registry.ReplaceAssemblyName(Data.ModName, "Assembly-CSharp");
             *      registry.ApplyChanges();
             * }*/
            //Debug.Log("G_Editor File Locked = " + IsFileLocked(new FileInfo("Library\\ScriptAssemblies\\WeaverCore.Editor.dll")));
            //yield return new WaitForSeconds(0.5f);
            //yield return new WaitUntil(() => !EditorApplication.isCompiling);
            //Debug.Log("H_Editor File Locked = " + IsFileLocked(new FileInfo("Library\\ScriptAssemblies\\WeaverCore.Editor.dll")));
            //AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport);
            //Debug.Log("I_Editor File Locked = " + IsFileLocked(new FileInfo("Library\\ScriptAssemblies\\WeaverCore.Editor.dll")));
            //yield return new WaitForSeconds(0.5f);
            //Debug.Log("J_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(Data.ModName, "Assembly-CSharp");
                registry.ApplyChanges();
            }
#endif
            //yield return new WaitForSeconds(0.5f);
            //Debug.Log("K_Editor File Locked = " + IsFileLocked(new FileInfo("Library\\ScriptAssemblies\\WeaverCore.Editor.dll")));
            //yield return new WaitUntil(() => !EditorApplication.isCompiling);
            bool assetsChanged = false;
            try
            {
                AssetDatabase.StartAssetEditing();
                if (Data.ExcludedAssemblies != null)
                {
                    foreach (var exclusion in Data.ExcludedAssemblies)
                    {
                        var asmDef = Data.PreBuildInfo.FirstOrDefault(a => a.AssemblyName == exclusion.AssemblyName);
                        if (asmDef != null)
                        {
                            asmDef.Definition.includePlatforms = exclusion.OriginalIncludedPlatforms;
                            asmDef.Definition.excludePlatforms = exclusion.OriginalExcludedPlatforms;
                            asmDef.Save();
                            assetsChanged = true;
                            AssetDatabase.ImportAsset(asmDef.AssemblyDefinitionPath, ImportAssetOptions.ForceUpdate);
                        }
                    }
                }
                if (assetsChanged)
                {
                    Data.NextMethod = new SerializedMethod(whenFinished);
                }
                else
                {
                    Data.NextMethod = default;
                }
                PersistentData.StoreData(Data);
                PersistentData.SaveData();

                if (!assetsChanged && whenFinished != null)
                {
                    whenFinished.Invoke(null, null);
                }
            }
            finally
            {
                //if (assetsChanged)
                //{
                //	AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
                //}
                //Debug.Log("L_Editor File Locked = " + IsFileLocked(new FileInfo("Library\\ScriptAssemblies\\WeaverCore.Editor.dll")));
                //AssetDatabase.AllowAutoRefresh();
                AssetDatabase.StopAssetEditing();
            }
            //}
        }