Skip to content

Instantly share code, notes, and snippets.

@9Hamza
9Hamza / EventBus.cs
Created October 28, 2025 07:02
A message bus that follows the observer pattern with an example of an event and a script that shows how to use the EventBus.
using System;
using System.Collections.Generic;
using UnityEngine;
public static class EventBus
{
private static readonly Dictionary<Type, List<Delegate>> _eventHandlers = new Dictionary<Type, List<Delegate>>();
// Subscribe to an event
public static void Subscribe<T>(Action<T> handler)
@9Hamza
9Hamza / GameManager.cs
Created March 8, 2023 22:23
Simple C# Singleton Example for Unity
public class GameManager : MonoBehaviour
{
public static GameManager Instance;
private void Awake()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);