Skip to content

Instantly share code, notes, and snippets.

@SolidAlloy
SolidAlloy / japanese-layout.ahk
Created February 15, 2024 14:47
AutoHotKey script that skips Japanese when cycling through keyboard layouts, has a separate key for switching to Japanese, and automatically switches to hiragana. For those who have more keyboard layouts other than English and Japanese, and use Japanese rarely.
#Requires AutoHotkey v2.0
; Makes Shift+Alt skip Japanese
~+Alt::
{
sleep(150)
if (GetKeyboardLanguage(WinExist("A")) = 1041) {
Send "{Shift Down}{Alt}{Shift Up}"
}
}
@SolidAlloy
SolidAlloy / PrefabPropertyReverter.cs
Last active July 30, 2023 03:38
Unity utility class for reverting overrides of a field or component in all prefab instances.
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.SceneManagement;
using vietlabs.fr2;
// I was frustrated with the fact that RectTransform fields are often marked as overriden when prefab instances
@SolidAlloy
SolidAlloy / CutComponentMenuItem.cs
Created April 28, 2022 12:47
"Cut Component" context menu that copies the component data and removes the component from the source object in one click.
namespace CutComponent.Editor
{
using UnityEditor;
using UnityEngine;
public static class CutComponentMenuItem
{
private const string CutComponentPath = "CONTEXT/Component/Cut Component";
[MenuItem(CutComponentPath, priority = 500)]
@SolidAlloy
SolidAlloy / AssetDatabaseTests.cs
Last active March 6, 2024 03:42
AssetDatabase unit tests that show the implications of Refresh() and SaveAssets()
using System;
using System.IO;
using JetBrains.Annotations;
using NUnit.Framework;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
/// <summary>
/// Unit tests that show how AssetDatabase operates.
@SolidAlloy
SolidAlloy / SpanExtensions.cs
Created January 18, 2021 13:39
ReadOnlySpan Split
using System;
using System.Runtime.CompilerServices;
using JetBrains.Annotations;
// Reduced-down and slightly refactored version of https://gist.github.com/LordJZ/92b7decebe52178a445a0b82f63e585a
// It exposes only (T separator) overload of the Split method which was enough for my needs.
public static class SpanExtensions
{
public readonly ref struct Enumerable<T>
where T : IEquatable<T>
@SolidAlloy
SolidAlloy / RoslynDirectoryCreator.cs
Last active May 16, 2022 18:52
Workaround for when Unity complains about the missing RoslynAnalysisRunner folder.
using System.IO;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
internal static class RoslynDirectoryCreator
{
static RoslynDirectoryCreator() => Application.logMessageReceived += OnLogMessageReceived;
@SolidAlloy
SolidAlloy / Identifier.cs
Created October 21, 2020 11:17 — forked from FabienDehopre/Identifier.cs
Validate C# identifier name
using System;
using System.Linq;
using System.Text.RegularExpressions;
public static class IdentifierExtensions
{
// definition of a valid C# identifier: http://msdn.microsoft.com/en-us/library/aa664670(v=vs.71).aspx
private const string FORMATTING_CHARACTER = @"\p{Cf}";
private const string CONNECTING_CHARACTER = @"\p{Pc}";
private const string DECIMAL_DIGIT_CHARACTER = @"\p{Nd}";
@SolidAlloy
SolidAlloy / AutoKeyDictionary.cs
Last active June 18, 2020 08:01
A dictionary implementation that generates keys automatically and returns them in the Add() method.
// A dictionary implementation that generates keys automatically and returns them in the Add() method.
// This is basically a nicely presented copy of the code snippet from this post
// https://stackoverflow.com/a/39104018/9833103
namespace CustomDataStructures
{
using System;
using System.Collections;
using System.Collections.Generic;
@SolidAlloy
SolidAlloy / FBasic_AddPhysicalImpact.cs
Created June 3, 2020 15:46
More useful version of the AddPhysicalImpact script from the fBasic Asset.
using UnityEngine;
using UnityEngine.Events;
using Random = UnityEngine.Random;
namespace FIMSpace.Basics
{
/// <summary>
/// Simple class which is adding physical impact on target rigidbody for provided time
/// </summary>
public class FBasic_AddPhysicalImpact : MonoBehaviour
@SolidAlloy
SolidAlloy / BoxCastDrawer.cs
Created May 17, 2020 14:36
A class that allows to visualize Unity Physics2D.BoxCast() method.
using UnityEngine;
/// <summary>
/// A class that allows to visualize the Physics2D.BoxCast() method.
/// </summary>
/// <remarks>
/// Use Draw() to visualize an already cast box,
/// and BoxCastAndDraw() to cast a box AND visualize it at the same time.
/// </remarks>