Skip to content

Instantly share code, notes, and snippets.

@FleshMobProductions
FleshMobProductions / AnimationStateNameSelection.cs
Last active February 29, 2024 16:02
Unity PropertyDrawer for selecting animation state names of AnimationControllers in the inspector
// Place file in your main project, outside of an Editor folder
using UnityEngine;
namespace FMPUtils.Types
{
[System.Serializable]
public class AnimationStateNameSelection
{
public Animator animator;
public string animationName;
@FleshMobProductions
FleshMobProductions / SelectionBackwardsForwardsNavigationMenuItem.cs
Last active April 16, 2024 02:08
Editor scripts to navigate between selections in Unity back (Ctrl + Alt + Z) and forward (Ctrl + Alt + Y). MenuItems can be found under "Edit/Selection - Navigate Back" and "Edit/Selection - Navigate Forward" and an EditorWindow can be found under "Window/Navigate Selection History". Place the scripts inside an "Editor" folder so they are exclud…
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace FMPUtils.Editor
{
[InitializeOnLoad]
public static class SelectionBackwardsForwardsNavigationMenuItem
{
public static event System.Action historyOrSelectionChanged;
@FleshMobProductions
FleshMobProductions / SceneReferenceHighlighterWindow.cs
Last active January 10, 2023 21:48
Highlight all scene objects that reference a selected object (needs to be of type UnityEngine.Object or a subclass of it)
using System;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.SceneManagement;
namespace FMPUtils.Editor
{
public class SceneReferenceHighlighterWindow : EditorWindow
@FleshMobProductions
FleshMobProductions / TransformLossyScaleEditor.cs
Last active December 24, 2022 11:40
Custom Unity Editor for Transforms to be able to set global scale of an object directly in the inspector (needs to be placed inside an "Editor" folder, replaces the default Transform inspector)
using UnityEngine;
using UnityEditor;
// When editing multiple projects, the LossyScale proeprty will display only the value of the first/main
// selected transform, which does not apply to all other selected transforms. So be careful when changing the LossyScale,
// as the scale values from this first transform are taken as base.
[CanEditMultipleObjects]
[CustomEditor(typeof(Transform))]
public class TransformLossyScaleEditor : Editor
{
@FleshMobProductions
FleshMobProductions / AudioPreviewer.cs
Last active May 2, 2024 14:17
Play an AudioClip asset in Unity by double clicking on it without external applications being opened
using System;
using System.Reflection;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;
// Source and Credit: FREE Audio Preview Tool For Unity Tutorial (by Warped Imagination) 2022-12-05
// https://www.youtube.com/watch?v=Gd8M1Ychis8
public static class AudioPreviewer
{
@FleshMobProductions
FleshMobProductions / FbxBlenderOpeningProcessor.cs
Last active May 2, 2024 14:41
Double click a FBX file inside Unity and open it inside Blender properly (Windows only. User needs to edit blenderPath to point to their installation)
// Place inside an "Editor" folder
#if PLATFORM_STANDALONE_WIN
using System;
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;
public static class FbxBlenderOpeningProcessor
{
@FleshMobProductions
FleshMobProductions / ShowIfKeywordBaseDrawer.cs
Created August 19, 2022 18:21
Unity MaterialPropertyDrawers to support showing or hiding specific properties in the inspector depending on defined keywords in the material (place scripts inside "Editor" folder)
using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
// TODO: check if we can select multiple
// https://answers.unity.com/questions/865321/custom-materialpropertydrawer-with-argument.html
// Pass one or more keywords in the constructor, I'm not sure how values will get separated though or if they will
/// <summary>
/// Usage: [ShowIfKeywordEnabled(_KEYWORD)]
@FleshMobProductions
FleshMobProductions / UnityObjectInstance.cs
Last active March 7, 2024 07:57
2 approaches to cache single instances of Unity objects in a globally accessible class
using System;
using System.Collections.Generic;
using UnityEngine;
using UObject = UnityEngine.Object;
namespace FMPUtils
{
// Usage: UnityObjectInstance<Player>.Instance
public static class UnityObjectInstance<T> where T : UObject
{
@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);
@FleshMobProductions
FleshMobProductions / SpringMotion.cs
Last active January 23, 2024 21:10
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,