Skip to content

Instantly share code, notes, and snippets.

@FleshMobProductions
FleshMobProductions / PiecewiseLerp.cs
Created February 24, 2021 07:52
PiecewiseLerp for cheaply interpolating between cached results of more complex interpolation functions, based on https://www.alanzucconi.com/2021/01/24/piecewise-interpolation/
// An additional implementation for piecewise interpolation described in this article:
// https://www.alanzucconi.com/2021/01/24/linear-interpolation/
// It has the limitation that it requires the delta difference between 2 adjacent values of the input array to always be constant.
// For example: inputs[2] - inputs[1] = 0.2f; inputs inputs[3] - inputs[2] = 0.2f; etc.
public static float PiecewiseLerp (float[] inputs, float[] results, float desiredInput)
{
int n = inputs.Length;
float inputMin = inputs[0];
float inputMax = inputs[n - 1];
@FleshMobProductions
FleshMobProductions / EditorHelpUtilities.cs
Last active July 29, 2023 21:19
Unity Editor script to combine a specular and a gloss map from Mixamo for use in a Standard Shader with Specular Setup
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Linq;
namespace FMPUtils.Editor
{
@FleshMobProductions
FleshMobProductions / SingletonProvider.cs
Last active March 7, 2024 07:41
An abstraction for accessing singleton instances in C# (made for the use in Unity3D)
using System;
using System.Collections.Generic;
namespace FMPUtils
{
public static class SingletonProvider
{
private static readonly Dictionary<Type, Func<object>> instanceAccessors = new Dictionary<Type, Func<object>>();
public static void Clear()
@FleshMobProductions
FleshMobProductions / ReplaceSceneObjectsWithPrefabWindow.cs
Created July 14, 2021 15:41
Replace Scene Objects With Prefab (Unity Editor Tool) - Define filter criteria for objects to select, such as what attached component types they need to have or which tag they need to have, then replace them with a prefab instance of choice
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.SceneManagement;
using System.Linq;
namespace FMPUtils.Editor
{
public class ReplaceSceneObjectsWithPrefabWindow : EditorWindow
{
@FleshMobProductions
FleshMobProductions / CircleMeshBuilder.cs
Last active March 3, 2022 07:38
2D Edgewave shader - Shader for the Unity Builtin Render Pipeline to cause surface waves on the edges for the local x and y positions of a mesh
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(MeshRenderer))]
[RequireComponent(typeof(MeshFilter))]
public class CirceMeshBuilder : MonoBehaviour
{
[SerializeField] private Material materialTemplate;
[SerializeField] private bool createMaterialCopy;
using System;
using System.Collections.Generic;
namespace FMPUtils
{
/// <summary>
/// Extension of the messenger from Wokarol (found at https://github.com/Wokarol/Messenger) using integer tags by utilizing
/// bitmasks
/// Tags can be any number between 0 and 63, the broadcaster of an event can specify something akin to a layermask
/// and all subscribers that have a tag number that is inside this mask will receive the event
@FleshMobProductions
FleshMobProductions / ProjectileImpactReceiver.cs
Last active September 15, 2023 07:05
Raycast-based projectile tracking system - to make sure that objects receive collision callbacks even if projectiles move too fast and builtin physics detection doesn't report a hit
using UnityEngine;
namespace FMPUtils.Projectile
{
/// <summary>
/// Add this component to objects that should receive projectile impacts
/// </summary>
[RequireComponent(typeof(Collider))]
public class ProjectileImpactReceiver : MonoBehaviour
{
@FleshMobProductions
FleshMobProductions / ExampleBehavior.cs
Created April 29, 2022 21:52 — forked from ProGM/ExampleBehavior.cs
A PropertyDrawer to show a popup field with a generic list of string for your Unity3d attribute
public class MyBehavior : MonoBehaviour {
// This will store the string value
[StringInList("Cat", "Dog")] public string Animal;
// This will store the index of the array value
[StringInList("John", "Jack", "Jim")] public int PersonID;
// Showing a list of loaded scenes
[StringInList(typeof(PropertyDrawersHelper), "AllSceneNames")] public string SceneName;
}
@FleshMobProductions
FleshMobProductions / SpringMotion.cs
Last active September 9, 2024 09:35
Ryan Juckett's Code for Damped Springs (https://www.ryanjuckett.com/damped-springs/) implemented in C# using UnityEngine Mathf methods
using UnityEngine;
namespace FMPUtils.Extensions
{
public static class SpringMotion
{
// Reference video:
// https://www.youtube.com/watch?v=bFOAipGJGA0
// Instant "Game Feel" Tutorial - Secrets of Springs Explained (by Toyful Games)
// The channel LlamAcademy also made an adaption of the concept for Unity,
@FleshMobProductions
FleshMobProductions / ObjectSpawner3DGrid.cs
Created June 17, 2022 20:52
Script for spawning a number of prefabs in a grid formation in Unity. Place it on an GameObject, right click on the component in the inspector and select "Spawn Elements" to run the spawn method
using UnityEngine;
namespace FMPUtils
{
public class ObjectSpawner3DGrid : MonoBehaviour
{
[SerializeField] GameObject spawnPrefab;
[SerializeField] Transform spawnParent;
[SerializeField] Vector3 startPosition;
[SerializeField] Vector3 xUnit = new Vector3(1f, 0f, 0f);