Skip to content

Instantly share code, notes, and snippets.

View Ryxali's full-sized avatar

Niklas Lindblad Ryxali

  • Skövde, Sweden
View GitHub Profile
@Ryxali
Ryxali / Stopwatch.cs
Last active March 11, 2022 15:42
Tracking time in Unity
/// <summary>
/// Keeps track of elapsed time, and is able to pause, resume & seek.
/// It's bound to Time.time, so time scaling will affect this.
/// </summary>
public struct Stopwatch
{
/// <summary>
/// How much time has passed for this stopwatch
/// </summary>
public float Elapsed => Time.time - epoch - (pausedEpoch > 0f ? (Time.time - pausedEpoch) : 0f);
@Ryxali
Ryxali / UnityConfigFieldSample.cs
Created March 17, 2021 12:35
Theorizing a way to expose values serialized on unity objects to internal classes without memory fragmentation at runtime and minimizing dependencies
/// <summary>
/// For consumers of config fields
/// </summary>
/// <typeparam name="T"></typeparam>
public struct ConfigValue<T> {
public T Value
#if UNITY_EDITOR
=> field.Value;
#else
@Ryxali
Ryxali / ScriptableInst.cs
Created December 9, 2020 15:11
Novel separation of shared and non-shared state with ScriptableObjects
public abstract class ScriptableInst<T> where T : ScriptableFactory<T>
{
public T SharedData { get; internal set; }
public ScriptableInst()
{
}
public ScriptableInst(T sharedData)
{
@Ryxali
Ryxali / AnimatorControllerTool.cs
Last active May 2, 2022 09:11
Enforcing a specific transition configuration for all transitions in a RuntimeAnimationController
using UnityEngine;
using UnityEditor;
using System.Text.RegularExpressions;
using System.IO;
// Drop this in some Editor folder
public static class AnimatorControllerTool {
[MenuItem("CONTEXT/RuntimeAnimatorController/Enforce Transition Settings")]
public static void FixTransitions(MenuCommand command)