Skip to content

Instantly share code, notes, and snippets.

View sebtoun's full-sized avatar

Sebtoun sebtoun

  • Montpellier, FRANCE
View GitHub Profile
@sebtoun
sebtoun / ClampedCurveAttribute.cs
Created October 13, 2021 19:04
Unity AnimationCurve decorator to clamp the curve like RangeAttribute is for float.
using UnityEngine;
public class ClampedCurveAttribute : PropertyAttribute
{
public readonly float MinX;
public readonly float MaxX;
public readonly float MinY;
public readonly float MaxY;
public ClampedCurveAttribute( float minX, float maxX, float minY, float maxY )
@sebtoun
sebtoun / PeriodicTrigger.cs
Created February 24, 2019 20:45
Periodically trigger an event
using System;
public class PeriodicTrigger
{
public event Action TriggerEvent;
private float _period;
private float _remaining;
public PeriodicTrigger( float period )
@sebtoun
sebtoun / JsonSerialisableScriptableObject.cs
Last active February 27, 2024 17:25
Unity's ScriptableObjects that easily serialize to JSON
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using UnityEngine;
public class JsonSerialisableScriptableObject<T> : ScriptableObject where T : JsonSerialisableScriptableObject<T>
{
@sebtoun
sebtoun / SimpleStateMachine.cs
Created July 20, 2018 15:51
Simple State machine for unity
using System;
using System.Collections;
using System.Collections.Generic;
#if USE_GAMELOGIC_EXTENSIONS
using Gamelogic.Extensions;
#endif
using UnityEngine;
/// <summary>
/// A lightweight state machine that support either update or coroutine pattern for states update.
@sebtoun
sebtoun / CoroutineEvent.cs
Created April 12, 2018 16:33
C# events like object for Unity's coroutine
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CoroutineEvent<T1, T2>
{
public delegate IEnumerator CoroutineDelegate( T1 parameter1, T2 parameter2 );
private readonly List<CoroutineDelegate> _eventHandlers = new List<CoroutineDelegate>();
private int _runningCoroutinesCount;
@sebtoun
sebtoun / CoroutineExtensions.cs
Last active April 12, 2018 08:14
Unity's coroutines extensions
using System;
using System.Collections;
using UnityEngine;
public static class CoroutineExtensions
{
public static Coroutine Then( this Coroutine self, Action action )
{
return DefaultCoroutineHost.Instance.StartCoroutine( ChainWithAction( self, action ) );
}
using UnityEngine;
using System;
//Original version of the ConditionalHideAttribute created by Brecht Lecluyse (www.brechtos.com)
//Modified by: -
[ AttributeUsage( AttributeTargets.Field ) ]
public class ConditionalHideAttribute : PropertyAttribute
{
public readonly string ConditionalSourceField;
@sebtoun
sebtoun / StretchWithVelocity.cs
Last active April 14, 2022 16:51
Stretch With Velocity Animation for Unity
using UnityEngine;
public class StretchWithVelocity : MonoBehaviour
{
public float MaxVelocity = 10;
public float MaxSpeedStretch = 0.5f;
public bool CompensatePosition = true;
public float MinVelocity = 0.1f;
public float Smoothing = 0.1f;
@sebtoun
sebtoun / ShakeBehaviour.cs
Last active August 4, 2018 08:29
Shake Behaviour for Unity
#define USE_GAMELOGIC_EXTENSION
#if USE_GAMELOGIC_EXTENSION
using Gamelogic.Extensions;
#endif
using UnityEngine;
#if USE_GAMELOGIC_EXTENSION
public class ShakeBehaviour : GLMonoBehaviour
@sebtoun
sebtoun / CameraFade.cs
Last active March 19, 2018 20:08
Camera Fade (depends on GameLogic Extension Singleton<> class) for Unity
using System;
using Gamelogic.Extensions;
using UnityEngine;
public class CameraFade : Singleton<CameraFade>
{
private void Awake()
{
if ( Instance.FadeTexture != null ) return;
Instance.FadeTexture = new Texture2D( 1, 1 );