|
|
- using System;
- using System.Collections.Generic;
- using System.Text;
- using UnityEngine;
- using UnityEngine.SceneManagement;
-
- namespace IllusionInjector
- {
- public class PluginComponent : MonoBehaviour
- {
- private CompositePlugin plugins;
- private bool quitting = false;
-
- public static PluginComponent Create()
- {
- return new GameObject("IPA_PluginManager").AddComponent<PluginComponent>();
- }
-
- void Awake()
- {
- DontDestroyOnLoad(gameObject);
-
- plugins = new CompositePlugin(PluginManager.Plugins);
- plugins.OnApplicationStart();
-
- SceneManager.activeSceneChanged += OnActiveSceneChanged;
- SceneManager.sceneLoaded += OnSceneLoaded;
- SceneManager.sceneUnloaded += OnSceneUnloaded;
- }
-
- void Update()
- {
- plugins.OnUpdate();
- }
-
- void LateUpdate()
- {
- plugins.OnLateUpdate();
- }
-
- void FixedUpdate()
- {
- plugins.OnFixedUpdate();
- }
-
- void OnDestroy()
- {
- if (!quitting)
- {
- Create();
- }
- }
-
- void OnApplicationQuit()
- {
- SceneManager.activeSceneChanged += OnActiveSceneChanged;
- SceneManager.sceneLoaded += OnSceneLoaded;
- SceneManager.sceneUnloaded += OnSceneUnloaded;
-
- plugins.OnApplicationQuit();
-
- quitting = true;
- }
-
- void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode)
- {
- plugins.OnSceneLoaded(scene, sceneMode);
- }
-
- private void OnSceneUnloaded(Scene scene) {
- plugins.OnSceneUnloaded(scene);
- }
-
- private void OnActiveSceneChanged(Scene prevScene, Scene nextScene) {
- plugins.OnActiveSceneChanged(prevScene, nextScene);
- }
-
- }
- }
|