-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
185c375
commit 4e03667
Showing
9 changed files
with
119 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class EventManager : MonoBehaviour | ||
{ | ||
private Dictionary<string, Action<int>> eventDictionary = new Dictionary<string, Action<int>>(); | ||
|
||
public static EventManager _instance; | ||
|
||
public static EventManager Instance | ||
{ | ||
get | ||
{ | ||
if (_instance == null) | ||
{ | ||
// Check if an existing GameManager is present in the scene | ||
_instance = FindObjectOfType<EventManager>(); | ||
|
||
if (_instance == null) | ||
{ | ||
// No existing GameManager found, so create a new GameObject and add this script | ||
GameObject em = new GameObject("EventManager"); | ||
_instance = em.AddComponent<EventManager>(); | ||
|
||
// Optionally, make this object persistent | ||
DontDestroyOnLoad(em); | ||
} | ||
} | ||
return _instance; | ||
} | ||
} | ||
|
||
public void Subscribe(string eventType, Action<int> listener) | ||
{ | ||
if (!eventDictionary.ContainsKey(eventType)) | ||
{ | ||
eventDictionary.Add(eventType, listener); | ||
} | ||
else | ||
{ | ||
eventDictionary[eventType] += listener; | ||
} | ||
} | ||
|
||
public void Unsubscribe(string eventType, Action<int> listener) | ||
{ | ||
if (eventDictionary.ContainsKey(eventType)) | ||
{ | ||
eventDictionary[eventType] -= listener; | ||
} | ||
} | ||
|
||
public void RaiseEvent(string eventType, int param) | ||
{ | ||
if (eventDictionary.ContainsKey(eventType)) | ||
{ | ||
eventDictionary[eventType]?.Invoke(param); | ||
} | ||
} | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
public static class GameEvent | ||
{ | ||
public static string QuestionTimerElapsed = "QuestionTimerElapsed"; | ||
public static string GameOverTrigger = "GameOver"; | ||
public static string MoveToSeptember = "MoveToSeptember"; | ||
public static string MoveToStart = "MoveToStart"; | ||
public static string SwitchPositionWithOnePlayer = "SwitchPositionWithOnePlayer"; | ||
public static string PickTwoPlayerToSwitchPosition = "PickTwoPlayerToSwitchPosition"; | ||
public static string PickOnePlayerToMissTurn = "PickOnePlayerToMissTurn"; | ||
public static string PickPlayersToMonth = "PickPlayersToMonth"; | ||
public static string QuestionCorrect = "QuestionCorrect"; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.