Exemplo n.º 1
0
 private void OnEvent(MonoBehaviour behaviour, Common.Events ev)
 {
     if (behaviour.GetType() == typeof(TitleScreenManager) && ev == Common.Events.AfterStart)
     {
         _updateInputsNext = true;
     }
 }
Exemplo n.º 2
0
 private void OnEvent(MonoBehaviour behaviour, Common.Events ev)
 {
     if (behaviour.GetType() == typeof(PlayerSpawner) && ev == Common.Events.AfterAwake)
     {
         _playerSpawner = (PlayerSpawner)behaviour;
         _isStarted     = true;
     }
 }
Exemplo n.º 3
0
 private void OnEvent(MonoBehaviour behaviour, Common.Events ev)
 {
     if (behaviour.GetType() == typeof(Flashlight) && ev == Common.Events.AfterStart)
     {
         _playerTransform = Locator.GetPlayerTransform();
         _playerBody      = _playerTransform.GetAttachedOWRigidbody();
         _isStarted       = true;
     }
 }
Exemplo n.º 4
0
        private void SubscribeToEvent <T>(Common.Events ev)
        {
            var type = typeof(T);

            if (IsSubscribedTo(type, ev))
            {
                _console.WriteLine($"Warning: already subscribed to {ev} of {type.Name}");
                return;
            }
            AddToEventList(_subscribedEvents, type, ev);
        }
Exemplo n.º 5
0
        private void PatchEvent <T>(Common.Events ev)
        {
            var type = typeof(T);

            if (InEventList(PatchedEvents, type, ev))
            {
                _logger.Log($"Event is already patched: {ev} of {type.Name}");
                return;
            }
            AddToEventList(PatchedEvents, type, ev);

            switch (ev)
            {
            case Common.Events.BeforeAwake:
                _harmonyHelper.AddPrefix <T>("Awake", typeof(Patches), nameof(Patches.BeforeAwake));
                break;

            case Common.Events.AfterAwake:
                _harmonyHelper.AddPostfix <T>("Awake", typeof(Patches), nameof(Patches.AfterAwake));
                break;

            case Common.Events.BeforeStart:
                _harmonyHelper.AddPrefix <T>("Start", typeof(Patches), nameof(Patches.BeforeStart));
                break;

            case Common.Events.AfterStart:
                _harmonyHelper.AddPostfix <T>("Start", typeof(Patches), nameof(Patches.AfterStart));
                break;

            case Common.Events.BeforeEnable:
                _harmonyHelper.AddPrefix <T>("OnEnable", typeof(Patches), nameof(Patches.BeforeEnable));
                break;

            case Common.Events.AfterEnable:
                _harmonyHelper.AddPostfix <T>("OnEnable", typeof(Patches), nameof(Patches.AfterEnable));
                break;

            case Common.Events.BeforeDisable:
                _harmonyHelper.AddPrefix <T>("OnDisable", typeof(Patches), nameof(Patches.BeforeDisable));
                break;

            case Common.Events.AfterDisable:
                _harmonyHelper.AddPostfix <T>("OnDisable", typeof(Patches), nameof(Patches.AfterDisable));
                break;

            default:
                _console.WriteLine("Error: unrecognized event: " + ev);
                throw new ArgumentOutOfRangeException(nameof(ev), ev, null);
            }
        }
Exemplo n.º 6
0
        private void OnPatchEvent(MonoBehaviour behaviour, Common.Events ev)
        {
            var type = behaviour.GetType();

            if (IsSubscribedTo(type, ev))
            {
                _logger.Log($"Got subscribed event: {ev} of {type.Name}");
                OnEvent?.Invoke(behaviour, ev);
            }
            else
            {
                _logger.Log($"Not subscribed to: {ev} of {type.Name}");
            }
        }
Exemplo n.º 7
0
 private void OnEvent(MonoBehaviour behaviour, Common.Events ev)
 {
     if (behaviour.GetType() == typeof(SettingsManager) && ev == Common.Events.AfterStart && behaviour.name == "PauseMenuManagers")
     {
         var settingsManager = (SettingsManager)behaviour;
         PauseMenu.Initialize(settingsManager);
         ModsMenu.Initialize(PauseMenu);
     }
     else if (behaviour.GetType() == typeof(TitleScreenManager) && ev == Common.Events.AfterStart)
     {
         var titleScreenManager = (TitleScreenManager)behaviour;
         MainMenu.Initialize(titleScreenManager);
         var inputMenu = titleScreenManager.GetComponent <ProfileMenuManager>().GetValue <PopupInputMenu>("_createProfileConfirmPopup");
         InputMenu.Initialize(inputMenu);
         ModsMenu.Initialize(MainMenu);
     }
 }
Exemplo n.º 8
0
 public void AddEvent <T>(Common.Events ev) where T : MonoBehaviour
 {
     Subscribe <T>(ev);
 }
Exemplo n.º 9
0
 /// <summary>Subscribe to the given event.</summary>
 /// <typeparam name="T">The type of the event.</typeparam>
 /// <param name="ev">The event to subscribe to.</param>
 public void Subscribe <T>(Common.Events ev) where T : MonoBehaviour
 {
     SubscribeToEvent <T>(ev);
     PatchEvent <T>(ev);
 }
Exemplo n.º 10
0
 private void AddToEventList(List <KeyValuePair <Type, Common.Events> > events, Type type, Common.Events ev)
 {
     events.Add(new KeyValuePair <Type, Common.Events>(type, ev));
 }
Exemplo n.º 11
0
 private bool InEventList(List <KeyValuePair <Type, Common.Events> > events, Type type, Common.Events ev)
 {
     return(events.Any(pair => type == pair.Key && pair.Value == ev));
 }
Exemplo n.º 12
0
 private bool IsSubscribedTo(Type type, Common.Events ev)
 {
     return(_subscribedEvents.Any(pair => (type == pair.Key || type.IsSubclassOf(pair.Key)) && pair.Value == ev));
 }