Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:Added UI Effect after RatRush #23

Open
wants to merge 2 commits into
base: Creating-Horror-Events-Using-Observer-Pattern-Setup
Choose a base branch
from
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
6 changes: 4 additions & 2 deletions Assets/Scripts/Camera/CameraView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ 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);
}

private void OnDisable()
{
EventService.Instance.OnLightsOffByGhostEvent.RemoveListener(Shake);
EventService.Instance.PlayerDeathEvent.RemoveListener(Shake);
EventService.Instance.OnPlayerDeathEvent.RemoveListener(Shake);
EventService.Instance.OnRatRush.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
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
10 changes: 10 additions & 0 deletions Assets/Scripts/Player/PlayerSanity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ public class PlayerSanity : MonoBehaviour
private float maxSanity;
private PlayerController playerController;

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

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

private void Start()
{
maxSanity = sanityLevel;
Expand Down
11 changes: 7 additions & 4 deletions Assets/Scripts/Service/EventService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ 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 EventService()
{
OnLightSwitchToggled = new EventController();
OnKeyPickedUp = new EventController<int>();
OnLightsOffByGhostEvent = new EventController();
OnRatRush = new EventController();

PlayerEscapedEvent = new EventController();
PlayerDeathEvent = new EventController();
OnPlayerEscapedEvent = new EventController();
OnPlayerDeathEvent = new EventController();
}
}
14 changes: 8 additions & 6 deletions Assets/Scripts/UI/GameUIView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ 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);

tryAgainButton.onClick.AddListener(OnTryAgainButtonClicked);
quitButton.onClick.AddListener(OnQuitButtonClicked);
Expand All @@ -35,9 +36,10 @@ 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);
}

public void UpdateInsanity(float playerSanity) => insanityImage.rectTransform.localScale = new Vector3(1, playerSanity, 1);
Expand Down
12 changes: 6 additions & 6 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.ide.visualstudio": "2.0.17",
"com.unity.ide.rider": "3.0.18",
"com.unity.ide.visualstudio": "2.0.16",
"com.unity.ide.rider": "3.0.15",
"com.unity.ide.vscode": "1.2.5",
"com.unity.editorcoroutines": "1.0.0",
"com.unity.performance.profile-analyzer": "1.2.2",
"com.unity.performance.profile-analyzer": "1.1.1",
"com.unity.test-framework": "1.1.31",
"com.unity.testtools.codecoverage": "1.2.2"
"com.unity.testtools.codecoverage": "1.0.1"
}
},
"com.unity.ide.rider": {
Expand Down Expand Up @@ -114,7 +114,7 @@
"url": "https://packages.unity.com"
},
"com.unity.performance.profile-analyzer": {
"version": "1.2.2",
"version": "1.1.1",
"depth": 1,
"source": "registry",
"dependencies": {},
Expand All @@ -139,7 +139,7 @@
"url": "https://packages.unity.com"
},
"com.unity.testtools.codecoverage": {
"version": "1.2.2",
"version": "1.0.1",
"depth": 1,
"source": "registry",
"dependencies": {
Expand Down