Skip to content

Instantly share code, notes, and snippets.

@JohnnyTurbo
JohnnyTurbo / CollisionLayers.cs
Last active September 2, 2024 02:26
Code used in ECS Single Unit Selection tutorial video on the Turbo Makes Games YouTube Channel - https://youtu.be/x8pVhWCewjU
using System;
namespace TMG.UnitSelection
{
[Flags]
public enum CollisionLayers
{
Selection = 1 << 0,
Ground = 1 << 1,
Units = 1 << 2
@Lachee
Lachee / EOLConversion.cs
Last active August 26, 2021 12:17
Utility Script to create EOL Conversions.
// Author: Lachee
// License: Public Domain - Do what you want with it
// Note: Script to convert line endings in unity so you dont get those annoying warnings.
// Simply put this script in a folder called Editor, then go Tools -> EOL Conversion -> Windows/Unix
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEditor;
@Invertex
Invertex / CustomHoldingInteraction.cs
Last active January 17, 2025 02:57
Unity New Input System custom Hold "Interaction" where the .performed callback is constantly triggered while input is held.
using UnityEngine;
using UnityEngine.InputSystem;
//!!>> This script should NOT be placed in an "Editor" folder. Ideally placed in a "Plugins" folder.
namespace Invertex.UnityInputExtensions.Interactions
{
//https://gist.github.com/Invertex
/// <summary>
/// Custom Hold interaction for New Input System.
/// With this, the .performed callback will be called everytime the Input System updates.
@made-indrayana
made-indrayana / FMODOutputUtils.cs
Last active August 6, 2021 14:25
I created this script to tackle the biggest problem when combining FMOD and Oculus VR Framework --- FMOD's audio only outputs to the currently used system audio device and not mirror its output to the VR headset, unlike when using SteamVR.
// FMOD Output Setter - Editor script
// Author: Made Indrayana
// MIT License
// Create a window in Unity to be able to explicitly select FMOD's audio output and auto enable it on every Play Mode.
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using FMODUnity;
using System.Linq;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.ResourceManagement.ResourceLocations;
using UnityEngine.ResourceManagement.ResourceProviders;
public sealed class AddressablesDownloader
{
@OscarAbraham
OscarAbraham / PlainDataInstancer.cs
Last active March 18, 2024 15:58
PlainDataInstancer ScriptableObject for Unity, so you can create deep clones of data stored in SO assets at runtime without the overhead of ScriptableObject copies.
using System.Collections.Generic;
using UnityEngine;
// TData should be a plain class or struct with the [System.Serializable] attribute.
// TData can implement ISerializationCallbackReceiver if needed for more advanced uses.
public class PlainDataInstancer<TData> : ScriptableObject
{
private static bool s_DataTypeValidated;
[SerializeField] private TData m_PrototypeData;
@totallyRonja
totallyRonja / MaterialGradientDrawer.cs
Last active March 31, 2025 13:38
A Material Property Drawer for the [Gradient] attribute which lets you edit gradients and adds them to the shader as textures. More information here: https://twitter.com/totallyRonja/status/1368704187580682240
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
public class MaterialGradientDrawer : MaterialPropertyDrawer {
private int resolution;
@staggartcreations
staggartcreations / Rope.cs
Last active March 6, 2024 12:58
HingeJoint-based rope building component
using System;
using UnityEngine;
using UnityEngine.Serialization;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class RopeGenerator : MonoBehaviour
{
public Rigidbody attachementBody;
@MeowKim
MeowKim / addressable_asset.md
Last active February 21, 2025 11:33
Guide for Unity Addressable Asset System.

📝 About

Guide for Unity Addressable Asset System.
Check out this sample code repo.

This guide supports languages below.

Created: 2020-07-03
Last updated: 2020-08-26 minor typo correction

@FreyaHolmer
FreyaHolmer / FlyCamera.cs
Last active January 9, 2025 06:10
A camera controller for easily flying around a scene in Unity smoothly. WASD for lateral movement, Space & Ctrl for vertical movement, Shift to move faster. Add this script to an existing camera, or an empty game object, hit play, and you're ready to go~
using UnityEngine;
[RequireComponent( typeof(Camera) )]
public class FlyCamera : MonoBehaviour {
public float acceleration = 50; // how fast you accelerate
public float accSprintMultiplier = 4; // how much faster you go when "sprinting"
public float lookSensitivity = 1; // mouse look sensitivity
public float dampingCoefficient = 5; // how quickly you break to a halt after you stop your input
public bool focusOnEnable = true; // whether or not to focus and lock cursor immediately on enable