Skip to content

Instantly share code, notes, and snippets.

@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 / 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
{
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 / 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;
@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 / 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 / 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 / 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 / PerlinNoiseMap.cs
Last active September 29, 2020 19:58
Example of Weighted Random point distribution within a value range of Perlin Noise Maps in Unity.
using UnityEngine;
namespace FMPUtils.Randomness
{
[System.Serializable]
public class PerlinNoiseMap
{
[SerializeField] private Vector2Int originOffset;
[SerializeField] private Vector2Int mapSize;
[SerializeField] private float cellSampleSizeMultiplier;
@FleshMobProductions
FleshMobProductions / WeightedRandomPrefabSupply.cs
Last active July 5, 2022 16:05
Weighted Randomness class for Unity
using UnityEngine;
namespace FMPUtils.Randomness
{
public class WeightedRandomPrefabSupply : MonoBehaviour
{
[System.Serializable]
public class WeightedGameObjectElement : WeightedElement<GameObject>
{
}