Skip to content

Instantly share code, notes, and snippets.

@schraf
schraf / Projectile.cs
Created February 14, 2023 23:22
Simple Projectile component for Unity
// Copyright 2023 Marc Schraffenberger
// This code is licensed under the terms of the MIT license
using UnityEngine;
using UnityEngine.Events;
public class Projectile : MonoBehaviour
{
[SerializeField]
private UnityEvent endOfLifeEvent;
@schraf
schraf / ObjectPoolSource.cs
Created February 14, 2023 23:18
Unity ObjectPool components for generic prefabs.
// Copyright 2023 Marc Schraffenberger
// This code is licensed under the terms of the MIT license
using UnityEngine;
using UnityEngine.Pool;
public class ObjectPoolSource : MonoBehaviour
{
[SerializeField]
private GameObject prefab;
@schraf
schraf / ItemPickup.cs
Last active February 14, 2023 23:20
Simple item pickup component for Unity.
// Copyright 2023 Marc Schraffenberger
// This code is licensed under the terms of the MIT license
using UnityEngine;
using UnityEngine.Events;
public class ItemPickup : MonoBehaviour
{
[SerializeField]
private UnityEvent<GameObject> pickupEvent;
@schraf
schraf / GameplayAttribute.cs
Created February 14, 2023 21:34
A gameplay attribute system based on Unity ScriptableObjects.
// Copyright 2023 Marc Schraffenberger
// This code is licensed under the terms of the MIT license
using UnityEngine;
[CreateAssetMenuAttribute(fileName="GameplayAttribute", menuName="AttributeSystem/Gameplay Attribute")]
public class GameplayAttribute : ScriptableObject
{
[UniqueIdentifier]
public string id;
@schraf
schraf / Checksum.cs
Created October 12, 2022 17:11
Adler32 checksum implementation in C#
// Copyright 2022 Marc Schraffenberger
// This code is licensed under the terms of the MIT license
public class Checksum
{
private uint A = 1;
private uint B = 0;
public void Append(byte value)
{
@schraf
schraf / FileManager.cs
Created October 8, 2022 22:01
Unity file manager class that holds file information from recursing file directories
// Copyright 2022 Marc Schraffenberger
// This code is licensed under the terms of the MIT license
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public class FileManager
{
@schraf
schraf / UniqueIdentifierAttribute.cs
Created September 3, 2022 20:41
Attribute for a Unity property that will create a unique id
// Copyright 2022 Marc Schraffenberger
// This code is licensed under the terms of the MIT license
using System;
using UnityEngine;
using UnityEditor;
public class UniqueIdentifierAttribute : PropertyAttribute { }
#if UNITY_EDITOR
@schraf
schraf / Manager.cs
Last active October 8, 2022 22:01
Unity base manager class to facilitate a singleton pattern
// Copyright 2022 Marc Schraffenberger
// This code is licensed under the terms of the MIT license
using UnityEngine;
using UnityEngine.Assertions;
// Unity base manager class to facilitate a singleton pattern
public abstract class Manager<T> : MonoBehaviour where T : Component
{
public static T Instance { get; private set; }
@schraf
schraf / Log.cs
Created September 3, 2022 17:53
Unity wrapper class around Debug logger calls to support stripping logs from release builds
// Copyright 2022 Marc Schraffenberger
// This code is licensed under the terms of the MIT license
using System.Diagnostics;
using UnityEngine;
// Unity wrapper class around Debug logger calls to support stripping logs from release builds
public class Log
{
[Conditional("DEVELOPMENT_BUILD"), Conditional("UNITY_EDITOR")]
@schraf
schraf / UpdateManager.cs
Created September 3, 2022 17:36
Unity update manager that manages update calls to IUpdatable objects are variable intervals
// Copyright 2022 Marc Schraffenberger
// This code is licensed under the terms of the MIT license
using System.Collections.Generic;
using Unity.Profiling;
using UnityEngine;
public interface IUpdatable
{
// time in seconds between update calls