Skip to content

Instantly share code, notes, and snippets.

@jmschrack
jmschrack / TriggerCallback.cs
Created January 23, 2017 06:09
For Unity3D, converts Trigger methods into Delegates.
using UnityEngine;
using System.Collections;
public class TriggerCallback : MonoBehaviour {
public delegate void Enter(Collider other);
public Enter enter;
public delegate void Exit(Collider other);
public Exit exit;
public delegate void Stay(Collider other);
public Stay stay;
@jmschrack
jmschrack / ColliderCallback.cs
Created January 23, 2017 06:11
For Unity3D, Wraps Collider methods as Delegates.
using UnityEngine;
public class ColliderCallback : MonoBehaviour {
public delegate void Enter(Collision other);
public Enter enter;
public delegate void Exit(Collision other);
public Exit exit;
public delegate void Stay(Collision other);
public Stay stay;
@jmschrack
jmschrack / TriggerEvent.cs
Last active January 23, 2017 07:21
For Unity3D Triggers, lets you attach UnityEvents to Trigger events
using UnityEngine;
using UnityEngine.Events;
using System.Collections;
public class TriggerEvent : MonoBehaviour {
public bool EnterOnce;
bool enterFire;
public UnityEvent EnterEvent;
public bool StayOnce;
bool stayFire;
@jmschrack
jmschrack / MainThreadBridge.cs
Created August 4, 2017 02:34
Framework for worker threads to pass commands back to the main thread in Unity
/*
MIT License
Copyright 2017 Digital Precept LLC
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOF
@jmschrack
jmschrack / TriGridImage.java
Last active August 4, 2019 04:49
Creates a grid with squares bisected into triangles. You can pass in an array of int to color certain sectors. It will save to a png
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class TriGridImage {
@jmschrack
jmschrack / ToggleSlider.cs
Created September 3, 2019 22:15
A "slider style" toggle UI component for Unity. Appears under Right Click>GameObject/UI/ToggleSlider
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using UnityEngine.EventSystems;
#if UNITY_EDITOR
using UnityEditor;
[CustomEditor(typeof(ToggleSlider))]
public class ToggleSliderEditor : Editor{
@jmschrack
jmschrack / IAsyncOperationExtensions.cs
Created December 18, 2019 20:19
Extensions that turns Unity's AsyncOperations into true C# async/await. Full credit to james7132 on the unity forum
/*
From https://forum.unity.com/threads/will-unity-ever-make-a-move-to-async-await-task.557908/#post-3699391
Full credit to james7132
*/
public static class IAsyncOperationExtensions {
public static AsyncOperationAwaiter GetAwaiter(this IAsyncOperation operation) {
return new AsyncOperationAwaiter(operation);
}
@jmschrack
jmschrack / ExtendedLerp.cs
Created May 30, 2017 19:54
Some Helper functions to enhance Unity's lerp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class ExtendedLerp {
public static Vector3 EaseOut(Vector3 start, Vector3 end, float t){
t = Mathf.Sin(t * Mathf.PI * 0.5f);
return Vector3.Lerp(start,end,t);
}
@jmschrack
jmschrack / torch-1.6.0a0+d5461e7-cp36-cp36m-linux_x86_64.whl.txt
Created May 19, 2020 22:49
PyTorch for ROCm 3.3. Compiled for gfx900 (Vega10 series) with HCC
https://mega.nz/file/jA8Tjaib#l96rAWdJ5IOvTf7jSGtCNND4tIL4AzOxmYt4mF59TCE
@jmschrack
jmschrack / AnimatorController.cs
Last active July 14, 2020 01:13
A thin helper wrapper for manually calling animations on an Animator.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// A thin wrapper for easily Playing specific animations. And checking if the animation is currently playing
/// </summary>
public class AnimatorController : MonoBehaviour
{
Animator _animator;
public Animator animator=>_animator;