Skip to content

Instantly share code, notes, and snippets.

View nonathaj's full-sized avatar

Jon Kenkel nonathaj

View GitHub Profile
@nonathaj
nonathaj / propgetc.snippet
Created March 11, 2016 17:02
Code Snippets to quickly fill out Unity serialization or GetComponent properties
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>propgetc</Title>
<Shortcut>propgetc</Shortcut>
<Description>Unity Code snippet for property and backing field with lazy GetComponent call</Description>
<Author>Jon Kenkel</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
@nonathaj
nonathaj / EnumMask.h
Last active February 1, 2016 21:56
C++ Enum Mask template class
#ifndef _ENUM_MASK
#define _ENUM_MASK
#include <cstddef>
#include <bitset>
//struct for ensuring an enum has a count element.
//this does NOT validate that the count element is the last element
template<class T>
struct has_enum_count {
@nonathaj
nonathaj / HashedString.cpp
Created November 19, 2015 22:10
C++ Hashed String - Allows fast comparison of strings in a small storage type (when you do NOT need to know the value of the string)
#include "HashedString.h"
namespace Engine
{
unsigned int HashedString::Hash(const char * i_string)
{
assert(i_string);
return Hash(reinterpret_cast<void *>(const_cast<char *>(i_string)), strlen(i_string));
@nonathaj
nonathaj / AssetDefinePostprocessor.cs
Last active October 9, 2023 18:29
A script for creating and removing defines in Unity with C# along with certain files.
using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
[InitializeOnLoad]
public class AssetDefinePostprocessor : AssetPostprocessor
{
@nonathaj
nonathaj / IPoolable.cs
Created October 23, 2015 01:44
Poolable and Pool wrapper for Unity that stores a list of items that are checked out or released from the pool. Can be used for pooling of bullets, or storing groups of items together, such as respawn points or collectibles.
/// <summary>
/// Interface for objects that can be inserted into a Pool.
/// These objects should use the Poolable attribute to define their spawn behaviour
/// </summary>
/// <example>
/// public class TestObject : MonoBehaviour, IPoolable
/// {
/// public void OnGenerate() { }
/// public void OnCheckout() { }
@nonathaj
nonathaj / Trigger3D.cs
Last active June 7, 2020 12:32
Trigger activator/handler for Unity3D
using UnityEngine;
using UnityEngine.Events;
using System;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// Trigger3D class
///
/// A trigger is considered ACTIVE when there is at least one object inside of it.
@nonathaj
nonathaj / DestroyWhenDead.cs
Created August 19, 2015 21:51
Health script and DestroyWhenDead
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(HasHealth))]
public class DestroyWhenDead : MonoBehaviour
{
HasHealth health;
///Lazy getter is safe here, because we used RequireComponent
public HasHealth Health {
get {
using UnityEngine;
using System.Collections;
/// <summary>
/// Camera Follower
///
/// Causes a camera to follow the position of a provided transform, and optionally it's x/y/z rotatations.
/// The camera can zoom out, in either orthographic or perspective mode and is limited on both ends.
///
/// Do NOT parent this component's gameobject to the follow transform. It must be at the same transform level, or higher.
@nonathaj
nonathaj / UnitySingleton.cs
Last active May 28, 2020 19:55
Generic UnitySingleton class for creating different types of singletons in Unity
using UnityEngine;
using System;
using System.Collections;
/// <summary>
/// Class for holding singleton component instances in Unity.
/// </summary>
/// <example>
/// [UnitySingleton(UnitySingletonAttribute.Type.LoadedFromResources, false, "test")]
/// public class MyClass : UnitySingleton&lt;MyClass&gt; { }
@nonathaj
nonathaj / CatchEvent
Last active September 8, 2023 22:30
Unity Event System for Designers
using UnityEngine;
using UnityEngine.Events;
using System.Collections;
/*
Event class for catching Unity Message Events that are sent to the GameObject's attached components.
Events that are captured here are sent from the GameObjectHelper class
*/
[AddComponentMenu("Event/Catch Event")]