You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

74 lines
2.3 KiB

using System;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using Logger = IPA.Logging.Logger;
namespace IPA.Loader.Composite
{
internal class CompositeBSPlugin :
#pragma warning disable CS0618 // Type or member is obsolete
IBeatSaberPlugin,
#pragma warning restore CS0618 // Type or member is obsolete
_IPlugin
{
private readonly IEnumerable<PluginLoader.PluginInfo> plugins;
private delegate void CompositeCall(PluginLoader.PluginInfo plugin);
public CompositeBSPlugin(IEnumerable<PluginLoader.PluginInfo> plugins) {
this.plugins = plugins;
}
[Obsolete]
public void OnApplicationStart() {
Invoke(plugin => (plugin.Plugin as IBeatSaberPlugin)?.OnApplicationStart());
}
public void OnApplicationQuit() {
Invoke(plugin => plugin.Plugin.OnApplicationQuit());
}
public void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode) {
Invoke(plugin => plugin.Plugin.OnSceneLoaded(scene, sceneMode));
}
public void OnSceneUnloaded(Scene scene) {
Invoke(plugin => plugin.Plugin.OnSceneUnloaded(scene));
}
public void OnActiveSceneChanged(Scene prevScene, Scene nextScene) {
Invoke(plugin => plugin.Plugin.OnActiveSceneChanged(prevScene, nextScene));
}
private void Invoke(CompositeCall callback) {
foreach (var plugin in plugins) {
try {
if (plugin.Plugin != null)
callback(plugin);
}
catch (Exception ex) {
Logger.log.Error($"{plugin.Metadata.Name}: {ex}");
}
}
}
public void OnUpdate() {
Invoke(plugin => plugin.Plugin.OnUpdate());
}
public void OnFixedUpdate() {
Invoke(plugin => plugin.Plugin.OnFixedUpdate());
}
public string Name => throw new InvalidOperationException();
public string Version => throw new InvalidOperationException();
public void OnLateUpdate() {
Invoke(plugin => {
if (plugin.Plugin is IGenericEnhancedPlugin saberPlugin)
saberPlugin.OnLateUpdate();
});
}
}
}