Skip to content

Instantly share code, notes, and snippets.

@neoRiley
neoRiley / AspectRatioButton.cs
Last active June 10, 2024 17:38
Extends VisualElement and provides the ability to maintain an aspect ratio as well as add a Label who's font size is scaled with the AspectRatioPanel
using System;
using System.Collections.Generic;
using UniRx;
using UnityEngine;
using UnityEngine.UIElements;
namespace N30R1L37
{
[UnityEngine.Scripting.Preserve]
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace Storage.Benchmark.Glo;
[DebuggerDisplay("Length = {Length}")]
[SuppressMessage("ReSharper", "InvertIf")]
internal struct Glossary<TValue>
where TValue : struct
@andrew-raphael-lukasik
andrew-raphael-lukasik / .UIDocumentLocalization.cs.md
Last active July 10, 2024 00:57
Text localization script for UIDocument (UI Toolkit @ Unity)

pattern to follow

// NOTE: this class assumes that you designate StringTable keys in label fields (as seen in Label, Button, etc) // and start them all with '#' char (so other labels will be left be)

@aal89
aal89 / pba.cs
Created July 30, 2019 22:35
Print byte array in c#
public void PrintByteArray(byte[] bytes)
{
var sb = new StringBuilder("new byte[] { ");
foreach (var b in bytes)
{
sb.Append(b + ", ");
}
sb.Append("}");
Console.WriteLine(sb.ToString());
}
@vildninja
vildninja / RemoveMissingScriptsRecursively.cs
Created March 25, 2019 10:06
Remove missing MonoBehaviour script components in Unity 2019.1 including visiting prefafab assets.
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEditor;
public static class FindMissingScriptsRecursively
{
[MenuItem("Auto/Remove Missing Scripts Recursively Visit Prefabs")]
private static void FindAndRemoveMissingInSelected()
{
// EditorUtility.CollectDeepHierarchy does not include inactive children
@Biodam
Biodam / NonDrawingGraphic.cs
Created October 8, 2018 20:32
Unity NonDrawingGraphic to detect raycast in UI without extra draw call
using UnityEngine;
using UnityEngine.UI;
/// A concrete subclass of the Unity UI `Graphic` class that just skips drawing.
/// Useful for providing a raycast target without actually drawing anything.
public class NonDrawingGraphic : Graphic
{
public override void SetMaterialDirty() { return; }
public override void SetVerticesDirty() { return; }
@williamahartman
williamahartman / FrameRate.java
Created January 15, 2015 03:17
Display framerate in a LibGDX graphics window. Call update() and render() in your main render method.
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.utils.TimeUtils;
/**
* A nicer class for showing framerate that doesn't spam the console
* like Logger.log()