Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Assets/Events.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Assets/Events/eventsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

public class eventsController
{
public Action baseEvent;

public void addListener(Action listener) => baseEvent += listener;
public void removeListener(Action listener) => baseEvent -= listener;
public void InvokeEvent() => baseEvent?.Invoke();
}
11 changes: 11 additions & 0 deletions Assets/Events/eventsController.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Assets/Scripts/Interactables/LightSwitchView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ public class LightSwitchView : MonoBehaviour, IInteractable
{
[SerializeField] private List<Light> lightsources = new List<Light>();
private SwitchState currentState;
public static event Action OnLightSwitchToggled;
// public static event Action OnLightSwitchToggled; // static used for using this event all over the code base.

private void OnEnable() => OnLightSwitchToggled += onLightSwitch;
private void OnEnable() => EventService.Instance.OnLightSwitchToggled.addListener(onLightSwitch);

private void OnDisable() => OnLightSwitchToggled -= onLightSwitch;
private void OnDisable() => EventService.Instance.OnLightSwitchToggled.removeListener(onLightSwitch);

private void Start() => currentState = SwitchState.Off;

public void Interact() => OnLightSwitchToggled?.Invoke();
public void Interact() => EventService.Instance.OnLightSwitchToggled.InvokeEvent();

private void toggleLights()
{
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Player/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public PlayerController(PlayerView playerView, PlayerScriptableObject playerScri

this.playerScriptableObject = playerScriptableObject;
this.playerScriptableObject.KeysEquipped = 0;
LightSwitchView.OnLightSwitchToggled += onLightSwitch;
EventService.Instance.OnLightSwitchToggled.addListener(onLightSwitch);
playerState = PlayerState.InDark;
}

~PlayerController()
{
LightSwitchView.OnLightSwitchToggled -= onLightSwitch;
EventService.Instance.OnLightSwitchToggled.removeListener(onLightSwitch);
}
public void Interact() => IsInteracted = Input.GetKeyDown(KeyCode.E) ? true : (Input.GetKeyUp(KeyCode.E) ? false : IsInteracted);

Expand Down
23 changes: 23 additions & 0 deletions Assets/Scripts/Service/EventService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

public class EventService
{
private static EventService instance;
public static EventService Instance
{
get
{
if (instance == null)
{
instance = new EventService();
}
return instance;
}
}

public eventsController OnLightSwitchToggled { get; private set; }

public EventService()
{
OnLightSwitchToggled = new eventsController();
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Service/EventService.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.