Skip to content

Instantly share code, notes, and snippets.

View sinbad's full-sized avatar

Steve Streeting sinbad

View GitHub Profile
@sinbad
sinbad / NumpadEmulation.ahk
Created October 28, 2024 14:34
AutoHotkey script to emulate numpad with Right Control
#Requires AutoHotkey v2.0
; Use Right-Control to make 0-9 and -+/* symbols their numpad versions
>^1::Numpad1
>^2::Numpad2
>^3::Numpad3
>^4::Numpad4
>^5::Numpad5
>^6::Numpad6
@sinbad
sinbad / StevesEaseMath.cpp
Last active March 31, 2023 11:41
Easing functions from easings.net implemented for Unreal Engine
#include "StevesEaseMath.h"
float UStevesEaseMath::EaseAlpha(float InAlpha, EStevesEaseFunction Func)
{
constexpr float BackC1 = 1.70158f;
constexpr float BackC2 = BackC1 * 1.525f;
constexpr float BackC3 = BackC1 + 1.f;
constexpr float ElasticC4 = UE_TWO_PI / 3.f;
constexpr float ElasticC5 = UE_TWO_PI / 4.5;
@sinbad
sinbad / Steve's Rider For Unreal Code Theme.icls
Last active October 27, 2021 01:05
Rider for Unreal Code Colours
<scheme name="Steve's Custom Monokai Pro" version="142" parent_scheme="Darcula">
<metaInfo>
<property name="created">2021-06-01T12:01:43</property>
<property name="ide">Rider</property>
<property name="ideVersion">2021.1.2.0.0</property>
<property name="modified">2021-06-01T12:02:09</property>
<property name="originalScheme">Steve's Custom Monokai Pro</property>
</metaInfo>
<colors>
<option name="ADDED_LINES_COLOR" value="a9dc76" />
@sinbad
sinbad / InputModeDetector.cpp
Last active March 18, 2024 19:02
UE4 detecting which input method was last used by each player
#include "InputModeDetector.h"
#include "Input/Events.h"
FInputModeDetector::FInputModeDetector()
{
// 4 local players should be plenty usually (will expand if necessary)
LastInputModeByPlayer.Init(EInputMode::Mouse, 4);
}
bool FInputModeDetector::HandleKeyDownEvent(FSlateApplication& SlateApp, const FKeyEvent& InKeyEvent)
@sinbad
sinbad / backup_gitea.sh
Created August 9, 2020 14:58
My Gitea Backup & Restore Scripts
#!/bin/bash
# `gitea dump` doesn't currently back up LFS data as well, only git repos
# It primarily backs up the SQL DB, and also the config / logs
# We'll backup like this:
# * "gitea dump" to backup the DB and config etc
# * tar / bzip all the repos since they will be skipped
# * Not rotated because git data is immutable (normally) so has all data
# * rsync LFS data directly from /volume/docker/gitea/git/lfs
# * No need for rotation since all files are immutable
@sinbad
sinbad / UE4_RPCs.md
Last active June 9, 2020 11:41
UE4 RPCs with both C++ and Blueprint implementations

I want a server RPC function which:

  • Is callable by both C++ and Blueprints
  • Is overrideable in Blueprints as well as C++

The basic C++ declared RPC with BlueprintCallable gets me the C++ / Blueprint visibility, but NOT the BP overrideable aspect, because you're not allowed to use BlueprintNativeEvent on Server functions. I.e.

UFUNCTION(BlueprintCallable, Server, Reliable)
void DoSomethingOnServer();
@sinbad
sinbad / TooltipPanel.cs
Last active September 25, 2021 17:25
Simple Unity UI tooltip system (requires DoTween)
using DG.Tweening;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
// Attach this component to a UI object which will be the tooltip visual
// Must include some text somewhere of course, and optionally a CanvasGroup if you want fading
public class TooltipPanel : MonoBehaviour {
[Tooltip("The text object which will display the tooltip string")]
public TextMeshProUGUI tooltipText;
@sinbad
sinbad / SpriteMeshRaycastFilter.cs
Last active May 11, 2023 05:35
SpriteMeshRaycastFilter: easy Unity UI non-rectangular click detector without reading textures
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
// Restrict raycasting to a sprite mesh shape
// Could use Image.alphaHitTestMinimumThreshold to mask but that requires read/write images which can't be packed
[RequireComponent(typeof(Image))]
public class SpriteMeshRaycastFilter : MonoBehaviour, ICanvasRaycastFilter {
private RectTransform rectTransform;
@sinbad
sinbad / CombinedOverlapCollider.cs
Last active November 29, 2019 15:52
Quick hack to use a single shared array for results from multiple Unity OverlapCollider calls
// I always use the Unity collider calls which place results in a single pre-allocated array to avoid allocations.
// However it's a bit annoying that you can't make a call like `collider2D.OverlapCollider` and tell it to start
// inserting results at a non-zero index in that results array, in order to collect multiple tests in a single
// result array.
// Yes, you can (and should) use CompoundCollider2D if this is a single object you're tracking, but if it's not and
// you just want combined results from different colliders it's a ball-ache to not be able to get all results in a
// single array easily.
// This little snippet shunts results of earlier OverlapCollider calls to the end of the array temporarily,
private Dictionary<int, Action<Localisation.VariableSetter>> localisationVariableFuncs;
private void InitLocalisation() {
Localisation.Instance.DefaultVariableCallback = LocalisationVariableCallback;
localisationVariableFuncs = new Dictionary<int, Action<Localisation.VariableSetter>>{
{LocalisationConsts.Variables.ShotStyleBonusHash, setter => setter.SetValue(shotStyleBonuses)},
{LocalisationConsts.Variables.ShotPegScoreHash, setter => setter.SetValue(shotPegScore)}
};
// Iterate over all strings and pre-convert action tags to IDs so we only do this once
Localisation.Instance.ProcessMessages(InitLocalisationMessage);