private void Update() { if (HighLogic.LoadedScene == GameScenes.LOADING || HighLogic.LoadedScene == GameScenes.MAINMENU) { List <AvailablePart> parts = PartLoader.LoadedPartsList; int i = partLoadedIndex; for (; parts != null && i < parts.Count; i++) { AvailablePart ap = parts[i]; if (ap.partUrl != null && ap.partUrl != "" && ap.TechRequired != "Unresearcheable") { Part part = ap.partPrefab; TextureUnloaderPartModule module = (TextureUnloaderPartModule)part.AddModule(typeof(TextureUnloaderPartModule).Name); MethodInfo mI = typeof(PartModule).GetMethod("Awake", BindingFlags.NonPublic | BindingFlags.Instance); mI.Invoke(module, null); module.Load(moduleNode); module.Unload(true, false); } else { Log(ap.name + " Not unloaded."); } } partLoadedIndex = i; } }
private void Start() { Assembly assembly = Assembly.GetExecutingAssembly(); if (HighLogic.LoadedScene == GameScenes.LOADING && !loaded) { Log("Version: " + assembly.GetName().Version); loaded = true; _MainTex = Shader.PropertyToID("_MainTex"); _BumpMap = Shader.PropertyToID("_BumpMap"); _Emissive = Shader.PropertyToID("_Emissive"); moduleNode = new ConfigNode("MODULE"); moduleNode.SetValue("name", typeof(TextureUnloaderPartModule).Name, true); Type gdType = typeof(GameDatabase); List <DatabaseLoader <GameDatabase.TextureInfo> > textureLoaders = (from fld in gdType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic) where fld.FieldType == typeof(List <DatabaseLoader <GameDatabase.TextureInfo> >) select(List <DatabaseLoader <GameDatabase.TextureInfo> >) fld.GetValue(GameDatabase.Instance)).FirstOrDefault(); DatabaseLoaderAttrib loaderAttrib = (DatabaseLoaderAttrib)Attribute.GetCustomAttribute(typeof(DatabaseLoaderTexture_DTL), typeof(DatabaseLoaderAttrib)); foreach (var textureLoader in textureLoaders) { if (textureLoader.GetType().Name != "DatabaseLoaderTexture_DTL") { Log("Disabling " + textureLoader.GetType().Name); textureLoader.extensions.RemoveAll(i => loaderAttrib.extensions.Contains(i)); Log(textureLoader.GetType().Name + " now has extensions: " + String.Join(", ", textureLoader.extensions.ToArray())); } } } //unload any materials added by mods. if (HighLogic.LoadedScene == GameScenes.SPACECENTER && !unloaded) { foreach (AvailablePart ap in PartLoader.LoadedPartsList) { if (ap.partUrl != null && ap.partUrl != "") { Part part = ap.partPrefab; TextureUnloaderPartModule module = (TextureUnloaderPartModule)part.FindModuleImplementing <TextureUnloaderPartModule>(); module.Unload(true); } } unloaded = true; } System.GC.Collect(); Resources.UnloadUnusedAssets(); }
private void Start() { Assembly assembly = Assembly.GetExecutingAssembly(); if (HighLogic.LoadedScene == GameScenes.LOADING && !loaded) { Log("Version: " + assembly.GetName().Version); loaded = true; _MainTex = Shader.PropertyToID("_MainTex"); _BumpMap = Shader.PropertyToID("_BumpMap"); _Emissive = Shader.PropertyToID("_Emissive"); moduleNode = new ConfigNode("MODULE"); moduleNode.SetValue("name", typeof(TextureUnloaderPartModule).Name, true); Type gdType = typeof(GameDatabase); List <DatabaseLoader <GameDatabase.TextureInfo> > textureLoaders = (from fld in gdType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic) where fld.FieldType == typeof(List <DatabaseLoader <GameDatabase.TextureInfo> >) select(List <DatabaseLoader <GameDatabase.TextureInfo> >) fld.GetValue(GameDatabase.Instance)).FirstOrDefault(); DatabaseLoaderTexture_DTL textureLoaderDTL = (DatabaseLoaderTexture_DTL)textureLoaders.First(t => t.GetType() == typeof(DatabaseLoaderTexture_DTL)); DatabaseLoaderAttrib loaderAttrib = (DatabaseLoaderAttrib)Attribute.GetCustomAttribute(typeof(DatabaseLoaderTexture_DTL), typeof(DatabaseLoaderAttrib)); foreach (var textureLoader in textureLoaders) { if (textureLoader.GetType() != typeof(DatabaseLoaderTexture_DTL)) { Log("Disabling " + textureLoader.GetType().Name); textureLoaderDTL.setLoader(textureLoader); textureLoader.extensions.RemoveAll(i => loaderAttrib.extensions.Contains(i)); Log(textureLoader.GetType().Name + " now has extensions: " + String.Join(", ", textureLoader.extensions.ToArray())); } else { ((DatabaseLoaderTexture_DTL)textureLoader).fixExtensions(loaderAttrib.extensions.ToList()); } } /* * List<LoadingSystem> list = LoadingScreen.Instance.loaders; * * if (list != null) * { * * GameObject aGameObject = new GameObject("ModuleManager"); * TexPatchLoader loader = aGameObject.AddComponent<TexPatchLoader>(); * int index = list.FindIndex(l => l.GetType() == typeof(PartLoader)); * list.Insert(index, loader); * //list.Insert(2, loader); * } */ } //unload any materials added by mods. if (HighLogic.LoadedScene == GameScenes.SPACECENTER && !unloaded) { foreach (AvailablePart ap in PartLoader.LoadedPartsList) { Part part = ap.partPrefab; if (part != null) { TextureUnloaderPartModule module = (TextureUnloaderPartModule)part.FindModuleImplementing <TextureUnloaderPartModule>(); if (module != null) { module.Unload(true); } } } unloaded = true; } System.GC.Collect(); //Resources.UnloadUnusedAssets(); }