Skip to content

Instantly share code, notes, and snippets.

@Streamweaver
Streamweaver / gist:28d5e896c039d6dea42868648661dbc2
Created January 2, 2021 05:50
Quick simulator of DnD Rolls in different conditions
import random
N = 100000 # Set this to the number of simulated rolls to aggregate
def d20():
return random.randint(1, 21)
def count_20s(lst):
@Streamweaver
Streamweaver / StaticUtils.cs
Created February 7, 2020 04:25
A simple set of static utilities I'm building up during Unity .
using UnityEngine;
namespace Streamweaver.Util
{
public static class StaticUtils
{
public static Vector3 GetRandomDir2D()
{
return new Vector3(Random.Range(-1f, 1f), Random.Range(-1f, 1f), 0).normalized;
}
@Streamweaver
Streamweaver / ActionState.cs
Last active February 7, 2020 04:21
An Action State Machine Pattern I like in Unity.
// Got this from Jason Weimann's videos. I like the pattern much better.
// from https://unity3d.college/2017/05/26/unity3d-design-patterns-state-basic-state-machine/
public class Entity: Monobehavior
{
private ActionState _currentState;
private void Update() {
_currentState.Tick();
}
@Streamweaver
Streamweaver / Singleton.cs
Created February 7, 2020 04:13
Singleton Class for Unity I like
using UnityEngine;
// Got this online and want to reuse for simple singletons.
namespace Streamweaver.Util
{
// Class taken from The Secret Labs Unity Cookbook repo
public class Singleton<T> : MonoBehaviour where T : MonoBehaviour
{
public static T instance
@Streamweaver
Streamweaver / CameraBoundaries.cs
Created January 18, 2020 04:06
This is a small utility script I use in simple 2D Unity games to world coordinates. I'd probably make this static and just pass in a cam object in the future so I can call it anytime.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Boundary : MonoBehaviour
{
Camera cam;
public float width, height;
// Start is called before the first frame update
@Streamweaver
Streamweaver / CameraShake.cs
Created January 17, 2020 13:25
Simple Camera Shake. Attach to a camera and run as a coroutine.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Simple camera shake. To call just attach to camera and from whever you want to
// call it, do something like 'StartCoroutine(_cameraShake.Shake(0.15f, 0.075f));'
public class CameraShake : MonoBehaviour
{
public IEnumerator Shake(float duration, float magnitude)
@Streamweaver
Streamweaver / SpawnManager.cs
Last active January 17, 2020 13:26
Example of a how I implemented a spawn manager for ObjectPool.cs.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Example of implementing a Spawn Manager with ObjectPool.cs from
// https://gist.github.com/Streamweaver/b9164c538e277b9ecf85e71d84e59162
public class SpawnManager : MonoBehaviour
{
[System.Serializable]
@Streamweaver
Streamweaver / ObjectPool.cs
Last active February 7, 2020 04:23
This is an objectpool class I derived from the SimplePool.cs class created by Quill18. It's refactored a bit for simplification and removing redundant calls. In particular this is a static class that can be called anywhere and allows the object to destroy itself.
using UnityEngine;
using System.Collections.Generic;
// Original adopted from Quill18's SimplePool Example. Storing here as an example.
// Example of using with a spawn manager in Gist
// https://gist.github.com/Streamweaver/1567f1c5c450d3ec2deb0efedce31ddf
// See below for a pooled particle system extension of this.
public static class ObjectPool
{

Keybase proof

I hereby claim:

  • I am streamweaver on github.
  • I am streamweaver (https://keybase.io/streamweaver) on keybase.
  • I have a public key ASB8n7p7BOxRHzadN0NlzvAZ_pKVFAUK5g-kdjaNdmeIxwo

To claim this, I am signing this object:

@Streamweaver
Streamweaver / gist:29327ae77e890753f487f276cce48620
Created July 10, 2016 16:13
Question on Efficiency of position updates in unity
// This is the working code.
// Aadvantage is simplicity and object is updated on intermediate states.
// Possible Disadvantage? I'm issuing updates to the game object transform every frame,
// but the only actual update I care about is the last one.
void Update () {
MoveShip ();
}
void MoveShip() {