Skip to content

Instantly share code, notes, and snippets.

View gustavopsantos's full-sized avatar
🦖

Gustavo Santos gustavopsantos

🦖
View GitHub Profile
@gustavopsantos
gustavopsantos / Circle.shader
Created February 12, 2024 16:57
Unity shader that draws a circle with outline
Shader "Unlit/Circle"
{
Properties
{
_Radius ("Radius", Float) = 1.0
_Thickness ("Thickness", Float) = 0.1
_InnerColor ("InnerColor", Color) = (1,1,1,0.5)
_OuterColor ("OuterColor", Color) = (1,1,1,1)
}
SubShader
@gustavopsantos
gustavopsantos / MusicalNoteFrequency.cs
Created January 31, 2024 12:56
Musical note frequency calculator
public static float Calc(float referenceFrequency, float noteOffset) // For instance: Calc(440, 12) = 880 | 440Hz = A4 | 880 = A5
{
return (float) (Math.Pow(2, noteOffset / 12) * referenceFrequency);
}
@gustavopsantos
gustavopsantos / GetApplicationDataPath.cs
Created September 12, 2023 12:40
thread safe equivalent for UnityEngine.Application.dataPath
using System.IO;
public static class GetApplicationDataPath
{
public static string Get()
{
return Path.Combine(Directory.GetCurrentDirectory(), "Assets").Replace('\\', '/');
}
}
public struct Frequency
{
private readonly long _millihertz;
public double Hertz => _millihertz / 1000d;
public TimeSpan Interval => TimeSpan.FromSeconds(1d / Hertz);
public Frequency(long millihertz)
{
@gustavopsantos
gustavopsantos / block-unity-cache-server.ps1
Last active July 3, 2023 23:32
Block unity cache server
New-NetFirewallRule -DisplayName "Unity Cache Server" -Direction Outbound -RemotePort 10080 -Protocol TCP -Action Block
// From Unity wiki: http://wiki.unity3d.com/index.php/Show_Built_In_Resources
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class BuiltInResourcesWindow : EditorWindow
{
[MenuItem("Window/Built-in styles and icons")]
@gustavopsantos
gustavopsantos / CallbackAssertion.cs
Created February 11, 2023 13:29
CallbackAssertion for FluentAssertions
public class CallbackAssertion
{
private int _calls;
private readonly Action _call;
public CallbackAssertion()
{
_call = () => _calls++;
}
@gustavopsantos
gustavopsantos / InjectedMethodInfo.cs
Created February 7, 2023 13:08
InjectedMethodInfo
internal sealed class InjectedMethodInfo
{
public readonly MethodInfo MethodInfo;
public readonly ParameterInfo[] Parameters;
public readonly Action<object, object[]> Call;
public InjectedMethodInfo(MethodInfo methodInfo)
{
MethodInfo = methodInfo;
Parameters = methodInfo.GetParameters();
@gustavopsantos
gustavopsantos / InjectedPropertyInfo.cs
Created February 7, 2023 13:07
InjectedPropertyInfo
internal sealed class InjectedPropertyInfo
{
public readonly Type PropertyType;
public readonly Action<object, object> Setter;
public InjectedPropertyInfo(PropertyInfo propertyInfo)
{
PropertyType = propertyInfo.PropertyType;
Setter = GenerateSetter(propertyInfo);
}
using System;
using System.Collections.Generic;
using UnityEngine;
public static class GetBoundsAtScreenSpace
{
private static readonly List<Vector3> _localSpaceVerticesBuffer = new List<Vector3>();
public static Bounds Get(MeshFilter meshFilter, Camera camera)
{