Skip to content

Instantly share code, notes, and snippets.

@FNGgames
FNGgames / DOTweenLight2DExtension.cs
Created December 17, 2023 20:19
DOTween Extensions
namespace SpiralCircus.DOTween
{
using DG.Tweening;
using SpiralCircus.Mathematics;
using UnityEngine.Rendering.Universal;
public static class DOTweenLight2DExtension
{
public static Tween DOIntensity(this Light2D light, float endValue, float duration)
=> DOTween.To(() => light.intensity, t => light.intensity = t, endValue, duration);
using UnityEngine;
using RSG;
public class ExamplePromiseWithTimeout : MonoBehaviour
{
private void Start()
{
// The example promise never resolves so this will timeout after 5 seconds has passed
// NOTE: This timer only works if the Promise.Update(deltaTime) method is being called
// (make sure you have the PromiseManager script running somewhere)
@FNGgames
FNGgames / CBoxGroup.cs
Last active June 5, 2023 11:20
Odin Color Box and Color Foldout Groups
#if UNITY_2020_2_OR_NEWER && ODIN_INSPECTOR
using System;
using System.Diagnostics;
using Sirenix.OdinInspector;
[AttributeUsage(AttributeTargets.All)]
[Conditional("UNITY_EDITOR")]
public class CBoxGroup : PropertyGroupAttribute
{
public float r, g, b, a;
@FNGgames
FNGgames / BitField128.cs
Last active April 14, 2021 16:55
BitFields
using System;
// A structure for performing bitwise operations collections of flags that are larger than the bit depth of an integer.
// The structure is backed by an array of unsigned 32 bit integers which represent "words" in the larger bit array.
// All standard bitwise operators are implemented, as well as methods that mutate the struct directly.
// The array of uints is implemented as a `fixed-size buffer` to force allocation of the uints inside this structure.
// The struct is therefore marked as `unsafe`
// The struct implements IEquatable to improve performance in hash tables and dictionaries.
// Method params are marked with the `in` keyword where appropriate to minimise copying of the supplied arguments.
public unsafe struct BitField128 : IEquatable<BitField128>
@FNGgames
FNGgames / IApplicationService.cs
Last active October 12, 2023 01:30
Entitias Scene Initialization Example
public interface IApplicationService : IService
{
HashSet<string> GetValidScenes();
void Load(string sceneName, Action<string, float> onProgress, Action<string> onComplete);
void Unload(string sceneName, Action<string, float> onProgress, Action<string> onComplete);
void Quit();
}
@FNGgames
FNGgames / Approximations.cs
Created April 30, 2020 11:59
Fast approximations
using System;
using System.Runtime.InteropServices;
public static class Approximations
{
// Sine approximation using polynominals.
// Has a low precision.
public static float LowSin(float x)
{
//always wrap input angle to -PI..PI
@FNGgames
FNGgames / Easing.cs
Last active August 11, 2020 10:16
Simple Easing
public static class Easing
{
// GENERAL
public static float Ease(float t, EaseType easeType) => EasingFunctions[easeType](t);
// LINEAR
public static float Linear(float t) => t;
// IN (as t^x)
public static float EaseInQuad(float t) => t * t;
using Spine.Unity;
using UnityEngine;
[RequireComponent(typeof(Renderer), typeof(SkeletonAnimation))]
public class SpineFrustrumCullSkeletonAnimation : MonoBehaviour
{
private SkeletonAnimation _anim;
private Renderer _renderer;
void Start()
@FNGgames
FNGgames / CircleHandle2D.cs
Created October 11, 2019 11:23
Custom Handles Example
// free move 2d handle with a circle texture
using UnityEditor;
using UnityEngine;
namespace CableSystem.Editor
{
public class CircleHandle2D : CustomHandle
{
private float _distance;
private bool _hovered, _selected;
@FNGgames
FNGgames / BaseCollisionSystem.cs
Last active March 7, 2019 11:19
Entitias Collisions
using Entitas;
using System.Collections.Generic;
public abstract class CollisionSystem : ReactiveSystem<InputEntity>
{
protected Contexts _contexts;
public CollisionSystem(Contexts contexts) : base(contexts.input)
{
_contexts = contexts;