CLIPA/IllusionInjector/CompositePlugin.cs

183 lines
6.8 KiB
C#

using IllusionPlugin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace IllusionInjector
{
public class CompositePlugin : IPlugin
{
IEnumerable<IPlugin> plugins;
private delegate void CompositeCall(IPlugin plugin);
public CompositePlugin(IEnumerable<IPlugin> plugins)
{
this.plugins = plugins;
}
public void OnApplicationStart()
{
Debug.LogWarning($"OnApplicationStart Test Warning");
Invoke(plugin => plugin.OnApplicationStart(), "OnApplicationStart");
}
public void OnApplicationQuit()
{
Invoke(plugin => plugin.OnApplicationQuit());
}
private void Invoke(CompositeCall callback, string name = null)
{
foreach (var plugin in plugins)
{
try
{
callback(plugin);
if (!string.IsNullOrEmpty(name))
Debug.LogWarning($"Executed {name} for plugin {plugin.Name}");
}
catch (Exception ex)
{
Console.WriteLine("{0}: {1}", plugin.Name, ex);
}
}
}
public void OnUpdate()
{
Invoke(plugin => plugin.OnUpdate());
}
public void OnFixedUpdate()
{
Invoke(plugin => plugin.OnFixedUpdate());
}
public void OnAnimatorIK(int layerIndex) { Invoke(plugin => plugin.OnAnimatorIK(layerIndex)); }
public void OnAnimatorMove() { Invoke(plugin => plugin.OnAnimatorMove()); }
public void OnApplicationFocus(bool hasFocus) { Invoke(plugin => plugin.OnApplicationFocus(hasFocus)); }
public void OnApplicationPause(bool pauseStatus) { Invoke(plugin => plugin.OnApplicationPause(pauseStatus)); }
public void OnAudioFilterRead(float[] data, int channels) { Invoke(plugin => plugin.OnAudioFilterRead(data, channels)); }
public void OnBecameInvisible() { Invoke(plugin => plugin.OnBecameInvisible()); }
public void OnBecameVisible() { Invoke(plugin => plugin.OnBecameVisible()); }
public void OnBeforeTransformParentChanged() { Invoke(plugin => plugin.OnBeforeTransformParentChanged()); }
public void OnCanvasGroupChanged() { Invoke(plugin => plugin.OnCanvasGroupChanged()); }
public void OnCanvasHierarchyChanged() { Invoke(plugin => plugin.OnCanvasHierarchyChanged()); }
public void OnCollisionEnter(Collision other) { Invoke(plugin => plugin.OnCollisionEnter(other)); }
public void OnCollisionEnter2D(Collision2D other) { Invoke(plugin => plugin.OnCollisionEnter2D(other)); }
public void OnCollisionExit(Collision other) { Invoke(plugin => plugin.OnCollisionExit(other)); }
public void OnCollisionExit2D(Collision2D other) { Invoke(plugin => plugin.OnCollisionExit2D(other)); }
public void OnCollisionStay(Collision other) { Invoke(plugin => plugin.OnCollisionStay(other)); }
public void OnCollisionStay2D(Collision2D other) { Invoke(plugin => plugin.OnCollisionStay2D(other)); }
public void OnConnectedToServer() { Invoke(plugin => plugin.OnConnectedToServer()); }
public void OnControllerColliderHit(ControllerColliderHit hit) { Invoke(plugin => plugin.OnControllerColliderHit(hit)); }
public void OnDidApplyAnimationProperties() { Invoke(plugin => plugin.OnDidApplyAnimationProperties()); }
public void OnDisable() { Invoke(plugin => plugin.OnDisable()); }
public void OnDrawGizmos() { Invoke(plugin => plugin.OnDrawGizmos()); }
public void OnDrawGizmosSelected() { Invoke(plugin => plugin.OnDrawGizmosSelected()); }
public void OnEnable() { Invoke(plugin => plugin.OnEnable()); }
public void OnGUI() { Invoke(plugin => plugin.OnGUI()); }
public void OnJointBreak(float breakForce) { Invoke(plugin => plugin.OnJointBreak(breakForce)); }
public void OnMouseDown() { Invoke(plugin => plugin.OnMouseDown()); }
public void OnMouseDrag() { Invoke(plugin => plugin.OnMouseDrag()); }
public void OnMouseEnter() { Invoke(plugin => plugin.OnMouseEnter()); }
public void OnMouseExit() { Invoke(plugin => plugin.OnMouseExit()); }
public void OnMouseOver() { Invoke(plugin => plugin.OnMouseOver()); }
public void OnMouseUp() { Invoke(plugin => plugin.OnMouseUp()); }
public void OnMouseUpAsButton() { Invoke(plugin => plugin.OnMouseUpAsButton()); }
public void OnParticleCollision(GameObject other) { Invoke(plugin => plugin.OnParticleCollision(other)); }
public void OnPostRender() { Invoke(plugin => plugin.OnPostRender()); }
public void OnPreCull() { Invoke(plugin => plugin.OnPreCull()); }
public void OnPreRender() { Invoke(plugin => plugin.OnPreRender()); }
public void OnRectTransformDimensionsChange() { Invoke(plugin => plugin.OnRectTransformDimensionsChange()); }
public void OnRenderImage(RenderTexture src, RenderTexture dest) { Invoke(plugin => plugin.OnRenderImage(src, dest)); }
public void OnRenderObject() { Invoke(plugin => plugin.OnRenderObject()); }
public void OnServerInitialized() { Invoke(plugin => plugin.OnServerInitialized()); }
public void OnTransformChildrenChanged() { Invoke(plugin => plugin.OnTransformChildrenChanged()); }
public void OnTransformParentChanged() { Invoke(plugin => plugin.OnTransformParentChanged()); }
public void OnTriggerEnter(Collider other) { Invoke(plugin => plugin.OnTriggerEnter(other)); }
public void OnTriggerEnter2D(Collider2D other) { Invoke(plugin => plugin.OnTriggerEnter2D(other)); }
public void OnTriggerExit(Collider other) { Invoke(plugin => plugin.OnTriggerExit(other)); }
public void OnTriggerExit2D(Collider2D other) { Invoke(plugin => plugin.OnTriggerExit2D(other)); }
public void OnTriggerStay(Collider other) { Invoke(plugin => plugin.OnTriggerStay(other)); }
public void OnTriggerStay2D(Collider2D other) { Invoke(plugin => plugin.OnTriggerStay2D(other)); }
public void OnValidate() { Invoke(plugin => plugin.OnValidate()); }
public void OnWillRenderObject() { Invoke(plugin => plugin.OnWillRenderObject()); }
public void Reset() { Invoke(plugin => plugin.Reset()); }
public string Name
{
get { throw new NotImplementedException(); }
}
public string Version
{
get { throw new NotImplementedException(); }
}
public void OnLateUpdate()
{
Invoke(plugin =>
{
if (plugin is IEnhancedPlugin)
((IEnhancedPlugin)plugin).OnLateUpdate();
});
}
}
}