Skip to content

Commit

Permalink
Design Doc || Bug Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminPricee committed Apr 22, 2024
1 parent 185c375 commit 4e03667
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 27 deletions.
8 changes: 8 additions & 0 deletions Achievements(package)/Assets/Scripts.meta

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

63 changes: 63 additions & 0 deletions Achievements(package)/Assets/Scripts/EventManager.cs
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);
}
}
}

11 changes: 11 additions & 0 deletions Achievements(package)/Assets/Scripts/EventManager.cs.meta

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

12 changes: 12 additions & 0 deletions Achievements(package)/Assets/Scripts/GameEvent.cs
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";
}
11 changes: 11 additions & 0 deletions Achievements(package)/Assets/Scripts/GameEvent.cs.meta

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

Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ public class Achievements : MonoBehaviour

public static Achievements _instance;

private int QuestionCorrectByCurrentPlayer = 0;

public static Achievements Instance
{
get
{
if (_instance == null)
{
// Check if an existing GameManager is present in the scene
// Check if an existing achievemnts is present in the scene
_instance = FindObjectOfType<Achievements>();

if (_instance == null)
{
// No existing GameManager found, so create a new GameObject and add this script
// No existing achievemnts found, so create a new achievemnts and add this script
GameObject a = new GameObject("Achievemnts");
_instance = a.AddComponent<Achievements>();

Expand All @@ -32,32 +34,9 @@ public static Achievements 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)
public static void recordEvent(int i)
{
if (eventDictionary.ContainsKey(eventType))
{
eventDictionary[eventType] -= listener;
}
}

public void RaiseEvent(string eventType, int param)
{
if (eventDictionary.ContainsKey(eventType))
{
eventDictionary[eventType]?.Invoke(param);
}
Debug.Log("Hey");
}
}

1 change: 1 addition & 0 deletions Achievements(package)/Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"com.unity.timeline": "1.6.5",
"com.unity.ugui": "1.0.0",
"com.unity.visualscripting": "1.9.2",
"ie.setu.eventmanager": "https://github.com/itcOnlineGaming/EventManager.git?path=/Packages/ie.setu.eventManager#v1.0.2",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.animation": "1.0.0",
Expand Down
7 changes: 7 additions & 0 deletions Achievements(package)/Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@
"source": "embedded",
"dependencies": {}
},
"ie.setu.eventmanager": {
"version": "https://github.com/itcOnlineGaming/EventManager.git?path=/Packages/ie.setu.eventManager#v1.0.2",
"depth": 0,
"source": "git",
"dependencies": {},
"hash": "2f8c82a32f8a4ca5f332d42b4fd0779e25165c9b"
},
"com.unity.modules.ai": {
"version": "1.0.0",
"depth": 0,
Expand Down
Binary file added Design Doc.docx
Binary file not shown.

0 comments on commit 4e03667

Please sign in to comment.