Skip to content

Instantly share code, notes, and snippets.

@der-hugo
der-hugo / Example.cs
Created November 15, 2023 09:27
Unity Inspector dropdown for a single layer (as contrary to the LayerMask)
using System;
using UnityEngine;
public class Example : MonoBehaviour
{
[SingleLayer] public int layer;
[ContextMenu(nameof(Test))]
private void Test()
{
@der-hugo
der-hugo / AnimatorRenameDialogue.cs
Last active March 31, 2022 20:32
Allows safe renaming of objects nested under / animated by an Animator without breaking the AnimationClips
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
/// <summary>
/// Dialogue that allows to rename objects in the Hierarchy of an <see cref="Animator"/> without breaking the AnimationClip bindings
/// </summary>
@der-hugo
der-hugo / AutoSaver.cs
Created March 21, 2022 08:59
Enables auto-saving in Unity
/// <summary>
/// Editor tools for auto-saving
/// </summary>
public static class AutoSaving
{
private const string k_MenuName = "Examples/Auto-Save/";
private static class IntervalAutoSaving
{
/// <summary>
@der-hugo
der-hugo / AnimatorTriggerResetter
Created March 18, 2022 10:06
Reset all triggers of an Aniamtor -> attach this to the Basic Layer in order to automatically apply it to all states
using UnityEngine;
public class AnimatorTriggerResetter : StateMachineBehaviour
{
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
foreach(var p in animator.parameters)
{
if (p.type == AnimatorControllerParameterType.Trigger)
{
@der-hugo
der-hugo / EnumMap.cs
Last active June 29, 2022 07:31
A modified version of SerializedDictionary (https://github.com/azixMcAze/Unity-SerializableDictionary) that has one KeyValuePair for each given enum value
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace DerHugo
{
#if UNITY_EDITOR
/// <summary>
/// Non generic base class for <see cref="EnumMap{TKey,TValue}"/> for drawers
@der-hugo
der-hugo / ObservedList.cs
Last active September 6, 2022 11:13
An observable list for Unity
public abstract class ObservedList { }
[Serializable]
public class ObservedList<T> : ObservedList, IList<T>
{
public delegate void ChangedDelegate(int index, T oldValue, T newValue);
// In a bit of a dirty hack the editor scripts is looking for this field
// with exactly this name "_list"
[SerializeField] private List<T> _list = new List<T>();
@der-hugo
der-hugo / Triangle2D.cs
Created March 10, 2021 11:04
Are two 2D triangles intersecting in Unity? Refactored version of https://www.habrador.com/tutorials/math/6-triangle-triangle-intersection
using System;
using UnityEngine;
/// <summary>
/// To store triangle data to get cleaner code
/// </summary>
[Serializable]
public struct Triangle2D
{
@der-hugo
der-hugo / LogExportButton.cs
Last active October 13, 2021 19:20
Unity Debug.Log exporter
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Text;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
@der-hugo
der-hugo / InstallSheepitAsAService.sh
Created June 27, 2019 14:25
Run Sheepit-Client as a Linux Service
#!/bin/bash
###############################################################
# This Script creates a service and a dedicated user #
# for running sheepit-client (www.sheepit.com) on a headless #
# Linux-Server #
# #
# Author of this script is: jerome.poenisch@gmail.com #
###############################################################
###############################################################
@der-hugo
der-hugo / update
Created November 10, 2017 10:21
Script for automated Ubuntu apt updates
#!/bin/bash
#########################
## returns:
# 0 - success
# 1 - success : Requires reboot
# 2 - updated failed
# 3 - upgrade failed
# 4 - dist-upgrade failed
# 5 - autoremove failed