Skip to content

Instantly share code, notes, and snippets.

@marcospgp
marcospgp / SafeTask.cs
Last active January 13, 2024 22:58
Cancel async tasks in Unity upon exiting play mode
using System;
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;
namespace UnityUtilities
{
/// <summary>
/// A replacement for `Task.Run()` that cancels tasks when entering or
/// exiting play mode in the Unity editor (which doesn't happen by default).
@sfider
sfider / CreateGameObjectHierarchyPositionFix.cs
Last active April 16, 2022 13:23
Unity fix for positioning newly created objects in hierarchy below selected object, not at the end of the hierarchy
/*
* Copyright 2022 Marcin Swiderski
*
* The MIT Licence (MIT)
*
* 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
@sebbbi
sebbbi / fast_spheres.txt
Created February 18, 2018 19:31
Fast way to render lots of spheres
Setup:
1. Index buffer containing N quads (each 2 triangles), where N is the max amount of spheres. Repeating pattern of {0,1,2,1,3,2} + K*4.
2. No vertex buffer.
Render N*2 triangles, where N is the number of spheres you have.
Vertex shader:
1. Sphere index = N/4 (N = SV_VertexId)
2. Quad coord: Q = float2(N%2, (N%4)/2) * 2.0 - 1.0
3. Transform sphere center -> pos
@douduck08
douduck08 / README.md
Last active February 29, 2024 09:03
The general GetValue extension of SerializedProperty in Unity Editor.

Unity's SerializedProperty not support custom type value setting. This extension use Reflection to get target instance of SerializedProperty in Custom Editor, made value setting of general type is posible.

@mstevenson
mstevenson / ConfigurableJointExtensions.cs
Last active April 30, 2024 08:05
Unity extension methods for computing a ConfigurableJoint.TargetRotation value from a given local or world rotation.
using UnityEngine;
public static class ConfigurableJointExtensions {
/// <summary>
/// Sets a joint's targetRotation to match a given local rotation.
/// The joint transform's local rotation must be cached on Start and passed into this method.
/// </summary>
public static void SetTargetRotationLocal (this ConfigurableJoint joint, Quaternion targetLocalRotation, Quaternion startLocalRotation)
{
if (joint.configuredInWorldSpace) {