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
7 changes: 7 additions & 0 deletions Assets/Scripts/Events/EventController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@ public class EventController
public void RemoveListener(Action listener) => baseEvent -= listener;
public void InvokeEvent() => baseEvent?.Invoke();
}
public class EventController<T>
{
public Action<T> baseEvent;
public void AddListener(Action<T> listener) => baseEvent += listener;
public void RemoveListener(Action<T> listener) => baseEvent -= listener;
public void InvokeEvent(T type) => baseEvent?.Invoke(type);
}

6 changes: 5 additions & 1 deletion Assets/Scripts/Interactables/KeyView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ public class KeyView : MonoBehaviour, IInteractable
[SerializeField] GameUIView gameUIView;
public void Interact()
{
int currentKeys = GameService.Instance.GetPlayerController().KeysEquipped;

GameService.Instance.GetInstructionView().HideInstruction();
GameService.Instance.GetSoundView().PlaySoundEffects(SoundType.KeyPickUp);
GameService.Instance.GetPlayerController().KeysEquipped++;
gameUIView.UpdateKeyText();

currentKeys++;

EventService.Instance.OnKeyPickedUp.InvokeEvent(currentKeys);
gameObject.SetActive(false);
}
}
7 changes: 7 additions & 0 deletions Assets/Scripts/Player/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ public PlayerController(PlayerView playerView, PlayerScriptableObject playerScri
playerState = PlayerState.InDark;

EventService.Instance.OnLightSwitchToggled.AddListener(onLightSwitch);
EventService.Instance.OnKeyPickedUp.AddListener(onkeyPickedUp);
}

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

Expand Down Expand Up @@ -85,4 +87,9 @@ private void onLightSwitch()
else
PlayerState = PlayerState.InDark;
}

private void onkeyPickedUp(int keys)
{
KeysEquipped = keys;
}
}
3 changes: 2 additions & 1 deletion Assets/Scripts/Service/EventService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

public class EventService
{
private static EventService instance;
Expand All @@ -15,9 +14,11 @@ public static EventService Instance
}

public EventController OnLightSwitchToggled { get; private set; }
public EventController<int> OnKeyPickedUp { get; private set; }

public EventService()
{
OnLightSwitchToggled = new EventController();
OnKeyPickedUp = new EventController<int>();
}
}
14 changes: 8 additions & 6 deletions Assets/Scripts/UI/GameUIView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ public class GameUIView : MonoBehaviour

private void OnEnable()
{
tryAgainButton.onClick.AddListener(OnTryAgainButtonClicked);
quitButton.onClick.AddListener(OnQuitButtonClicked);
tryAgainButton.onClick.AddListener(onTryAgainButtonClicked);
quitButton.onClick.AddListener(onQuitButtonClicked);
EventService.Instance.OnKeyPickedUp.AddListener(updateKeyText);
}
public void UpdateInsanity(float playerSanity) => insanityImage.rectTransform.localScale = new Vector3(1, playerSanity, 1);
public void UpdateKeyText() => keysFoundText.SetText($"Keys Found: {GameService.Instance.GetPlayerController().KeysEquipped}/3");

private void OnQuitButtonClicked() => Application.Quit();
private void OnTryAgainButtonClicked() => SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
private void OnDisable() => EventService.Instance.OnKeyPickedUp.RemoveListener(updateKeyText);
public void UpdateInsanity(float playerSanity) => insanityImage.rectTransform.localScale = new Vector3(1, playerSanity, 1);
private void updateKeyText(int keys) => keysFoundText.SetText($"Keys Found: {keys}/3");
private void onQuitButtonClicked() => Application.Quit();
private void onTryAgainButtonClicked() => SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}

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
4 changes: 2 additions & 2 deletions ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 2021.3.21f1
m_EditorVersionWithRevision: 2021.3.21f1 (1b156197d683)
m_EditorVersion: 2021.3.10f1
m_EditorVersionWithRevision: 2021.3.10f1 (1c7d0df0160b)