Skip to content

Instantly share code, notes, and snippets.

View 123tris's full-sized avatar
😁
I love deleting code

Tristan Metz 123tris

😁
I love deleting code
View GitHub Profile
@123tris
123tris / UpdateRootMotion.cs
Created November 7, 2019 20:21
A statemachinebehaviour to toggle rootmotion when entering or exiting animation states in Unity
using UnityEngine;
public class UpdateRootMotion : StateMachineBehaviour
{
public bool onStateEnter;
public bool applyRootMotionOnEnter;
public bool onStateExit;
public bool applyRootMotionOnExit;
@123tris
123tris / $CooldownManagerExample.cs
Last active September 9, 2024 08:01
A unity script for easily delaying parts of your code
//----------- Example code -----------
float health = 5;
CooldownManager.Cooldown(2, () => health++); //Delay health increment by 2 seconds
CooldownManager.Cooldown(5, Shoot); //Invoke shoot in 5 seconds
void Shoot () { }
//If you dont want to use lambda's for functions with parameters you can overload the function like so:
CooldownManager.Cooldown(2, Damage, 5); //Calls Damage() function with damageValue 5 after 2 seconds have passed
@123tris
123tris / ReadOnly.cs
Created February 5, 2021 23:43
ReadOnly attribute for Unity
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
namespace Utility
{
public class ReadOnlyAttribute : PropertyAttribute
{
}
@123tris
123tris / RealtimeDebugger.cs
Last active May 10, 2021 17:53
A Unity debugger window that allows you to subscribe values you want to debug in realtime easily
#if UNITY_EDITOR
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
//Made for only testing purposes so use at own discretion
public class RealtimeDebugger : EditorWindow
{
static Dictionary<string, object> debugProperties = new Dictionary<string, object>();
@123tris
123tris / SceneHistoryWidget.cs
Created January 19, 2023 03:02 — forked from jringrose/SceneHistoryWidget.cs
Drop this into an Editor folder in your project to add a history widget to your scene view. Supports going backwards and forwards through your recent scene history, as well as a dropdown of all recently edited scenes. Also supports the back/forwards buttons on your mouse! Doesn't support multi-scene editing very well, though.
#if UNITY_EDITOR
/*
MIT License
Copyright (c) 2016 Jesse Ringrose
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
@123tris
123tris / CachedReference.cs
Last active July 27, 2024 18:10
A way to retrieve and cache singleton/manage type monobehaviours
using UnityEngine;
using UnityEngine.Assertions;
public static class CachedReference<T> where T : MonoBehaviour
{
private static T cachedReference;
/// <summary> Returns null when it cannot find the type </summary>
public static T FindCachedObject(bool includeInactive = true)
{
@123tris
123tris / Singleton.cs
Last active October 22, 2024 02:00
Singleton for Unity. Could possibly be improved on.
using UnityEngine;
using UnityEngine.Assertions;
public class Singleton<T> : BaseBehaviour where T : MonoBehaviour
{
public static T Instance => GetInstance();
/// <summary>GetInstance gets called by the getter Instance, however GetInstance can be used to get extra control such as turning off exceptions and allowing null or generate the instance when it can't be found </summary>
public static T GetInstance(bool throwException = true, bool generateInstance = false)
{