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: 6 additions & 2 deletions Assets/Scripts/Camera/CameraView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ public class CameraView : MonoBehaviour
private void OnEnable()
{
EventService.Instance.OnLightsOffByGhostEvent.AddListener(Shake);
EventService.Instance.PlayerDeathEvent.AddListener(Shake);
EventService.Instance.OnPlayerDeathEvent.AddListener(Shake);
EventService.Instance.OnRatRush.AddListener(Shake);
EventService.Instance.OnSkullDrop.AddListener(Shake);
}

private void OnDisable()
{
EventService.Instance.OnLightsOffByGhostEvent.RemoveListener(Shake);
EventService.Instance.PlayerDeathEvent.RemoveListener(Shake);
EventService.Instance.OnPlayerDeathEvent.RemoveListener(Shake);
EventService.Instance.OnRatRush.RemoveListener(Shake);
EventService.Instance.OnSkullDrop.RemoveListener(Shake);
}

private void Start()
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Events/PlayerEscapedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ private void OnTriggerEnter(Collider other)
if (other.GetComponent<PlayerView>() != null)
{
GameService.Instance.GetSoundView().PlaySoundEffects(soundToPlay);
EventService.Instance.PlayerEscapedEvent.InvokeEvent();
EventService.Instance.OnPlayerEscapedEvent.InvokeEvent();
}
}
}
1 change: 1 addition & 0 deletions Assets/Scripts/Events/RatRushEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ private void OnTriggerEnter(Collider other)
if (other.GetComponent<PlayerView>() != null)
{
onRatRush();
EventService.Instance.OnRatRush.InvokeEvent();
GameService.Instance.GetSoundView().PlaySoundEffects(soundToPlay);
GetComponent<Collider>().enabled = false;
}
Expand Down
5 changes: 3 additions & 2 deletions Assets/Scripts/Events/SkullDropEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ private void OnTriggerEnter(Collider other)
{
if (other.GetComponent<PlayerView>() != null && GameService.Instance.GetPlayerController().KeysEquipped >= keysRequiredToTrigger)
{
OnSkullDrop();
onSkullDrop();
GameService.Instance.GetSoundView().PlaySoundEffects(soundToPlay);
EventService.Instance.OnSkullDrop.AddListener(onSkullDrop);
GetComponent<Collider>().enabled = false;
}
}

private void OnSkullDrop()
private void onSkullDrop()
{
skulls.gameObject.SetActive(true);
}
Expand Down
1 change: 1 addition & 0 deletions Assets/Scripts/Interactables/PotionView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public void Interact()
{
GameService.Instance.GetInstructionView().HideInstruction();
GameService.Instance.GetSoundView().PlaySoundEffects(soundType);
EventService.Instance.OnPotionDrink.InvokeEvent(potionEffect);
gameObject.SetActive(false);
}
}
6 changes: 3 additions & 3 deletions Assets/Scripts/Player/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public PlayerController(PlayerView playerView, PlayerScriptableObject playerScri
EventService.Instance.OnLightsOffByGhostEvent.AddListener(onLightsOffByGhost);
EventService.Instance.OnLightSwitchToggled.AddListener(onLightsToggled);
EventService.Instance.OnKeyPickedUp.AddListener(OnKeyPickedUp);
EventService.Instance.PlayerEscapedEvent.AddListener(DisableControls);
EventService.Instance.OnPlayerEscapedEvent.AddListener(DisableControls);
}
~PlayerController()
{
EventService.Instance.OnLightsOffByGhostEvent.RemoveListener(onLightsOffByGhost);
EventService.Instance.OnLightSwitchToggled.RemoveListener(onLightsToggled);
EventService.Instance.OnKeyPickedUp.RemoveListener(OnKeyPickedUp);
EventService.Instance.PlayerEscapedEvent.RemoveListener(DisableControls);
EventService.Instance.OnPlayerEscapedEvent.RemoveListener(DisableControls);
}
public void Interact() => IsInteracted = Input.GetKeyDown(KeyCode.E) ? true : (Input.GetKeyUp(KeyCode.E) ? false : IsInteracted);

Expand Down Expand Up @@ -60,7 +60,7 @@ public void Move(Rigidbody playerRigidbody, Transform transform)
public void KillPlayer()
{
PlayerState = PlayerState.Dead;
EventService.Instance.PlayerDeathEvent.InvokeEvent();
EventService.Instance.OnPlayerDeathEvent.InvokeEvent();
}

private void onLightsOffByGhost() => PlayerState = PlayerState.InDark;
Expand Down
14 changes: 14 additions & 0 deletions Assets/Scripts/Player/PlayerSanity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ public class PlayerSanity : MonoBehaviour
private float maxSanity;
private PlayerController playerController;

private void OnEnable()
{
EventService.Instance.OnRatRush.AddListener(OnSupernaturalEvent);
EventService.Instance.OnSkullDrop.AddListener(OnSupernaturalEvent);
EventService.Instance.OnPotionDrink.AddListener(OnDrankPotion);
}

private void OnDisable()
{
EventService.Instance.OnRatRush.RemoveListener(OnSupernaturalEvent);
EventService.Instance.OnSkullDrop.RemoveListener(OnSupernaturalEvent);
EventService.Instance.OnPotionDrink.RemoveListener(OnDrankPotion);
}

private void Start()
{
maxSanity = sanityLevel;
Expand Down
14 changes: 10 additions & 4 deletions Assets/Scripts/Service/EventService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,22 @@ public static EventService Instance
public EventController<int> OnKeyPickedUp { get; private set; }
public EventController OnLightsOffByGhostEvent { get; private set; }

public EventController PlayerEscapedEvent { get; private set; }
public EventController PlayerDeathEvent { get; private set; }
public EventController OnPlayerEscapedEvent { get; private set; }
public EventController OnPlayerDeathEvent { get; private set; }
public EventController OnRatRush { get; private set; }
public EventController OnSkullDrop { get; private set; }
public EventController<int> OnPotionDrink { get; private set; }

public EventService()
{
OnLightSwitchToggled = new EventController();
OnKeyPickedUp = new EventController<int>();
OnLightsOffByGhostEvent = new EventController();
OnRatRush = new EventController();
OnSkullDrop = new EventController();
OnPotionDrink = new EventController<int>();

PlayerEscapedEvent = new EventController();
PlayerDeathEvent = new EventController();
OnPlayerEscapedEvent = new EventController();
OnPlayerDeathEvent = new EventController();
}
}
16 changes: 10 additions & 6 deletions Assets/Scripts/UI/GameUIView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ private void OnEnable()
{
EventService.Instance.OnKeyPickedUp.AddListener(OnKeyEquipped);
EventService.Instance.OnLightsOffByGhostEvent.AddListener(SetRedVignette);
EventService.Instance.PlayerEscapedEvent.AddListener(OnPlayerEscaped);
EventService.Instance.PlayerDeathEvent.AddListener(SetRedVignette);
EventService.Instance.PlayerDeathEvent.AddListener(OnPlayerDeath);
EventService.Instance.OnPlayerEscapedEvent.AddListener(OnPlayerEscaped);
EventService.Instance.OnPlayerDeathEvent.AddListener(SetRedVignette);
EventService.Instance.OnPlayerDeathEvent.AddListener(OnPlayerDeath);
EventService.Instance.OnRatRush.AddListener(SetRedVignette);
EventService.Instance.OnSkullDrop.AddListener(SetRedVignette);

tryAgainButton.onClick.AddListener(OnTryAgainButtonClicked);
quitButton.onClick.AddListener(OnQuitButtonClicked);
Expand All @@ -35,9 +37,11 @@ private void OnDisable()
{
EventService.Instance.OnKeyPickedUp.RemoveListener(OnKeyEquipped);
EventService.Instance.OnLightsOffByGhostEvent.RemoveListener(SetRedVignette);
EventService.Instance.PlayerEscapedEvent.RemoveListener(OnPlayerEscaped);
EventService.Instance.PlayerDeathEvent.RemoveListener(SetRedVignette);
EventService.Instance.PlayerDeathEvent.RemoveListener(OnPlayerDeath);
EventService.Instance.OnPlayerEscapedEvent.RemoveListener(OnPlayerEscaped);
EventService.Instance.OnPlayerDeathEvent.RemoveListener(SetRedVignette);
EventService.Instance.OnPlayerDeathEvent.RemoveListener(OnPlayerDeath);
EventService.Instance.OnRatRush.RemoveListener(SetRedVignette);
EventService.Instance.OnSkullDrop.RemoveListener(SetRedVignette);
}

public void UpdateInsanity(float playerSanity) => insanityImage.rectTransform.localScale = new Vector3(1, playerSanity, 1);
Expand Down