Skip to content

Instantly share code, notes, and snippets.

View nilpunch's full-sized avatar

Daniil Pankevich nilpunch

View GitHub Profile
@nilpunch
nilpunch / Angle.cs
Last active May 1, 2024 17:59
Angle and 2D Rotation for Unity
using System;
using System.Runtime.CompilerServices;
using UnityEngine;
public readonly struct Angle : IEquatable<Angle>
{
private const float PIRad = Mathf.PI;
private const float TwoPIRad = PIRad * 2f;
private const float HalfPIRad = PIRad * 0.5f;
@nilpunch
nilpunch / BlurImage.shader
Last active July 24, 2023 09:44
Blur for UI elements. Compatible with Built in RP, HDRP, URP and SRP.
Shader "UI/BlurImage"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
[Space(50)]
_BlurX ("X Blur", Range(0.0, 0.5)) = 0.001
_BlurY ("Y Blur", Range(0.0, 0.5)) = 0.001
@nilpunch
nilpunch / KdTree.cs
Last active May 31, 2022 09:41 — forked from ditzel/KdTree.cs
Somewhat refactored k-d tree.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public interface IKdTreePosition
{
Vector3 Position { get; }
}
@nilpunch
nilpunch / AttackState.cs
Last active June 29, 2023 15:00
Simplest possible object-oriented FSM
public class AttackState : IBehaviorState
{
private readonly ICharacter _character;
public AttackState(ICharacter character)
{
_character = character;
}
public IBehaviorState Execute(long time)
@nilpunch
nilpunch / BillboardSprite.shader
Last active May 31, 2022 07:30
Billboard sprite shader.
Shader "Custom/Sprite Billboard"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
[Header(Aligning)]
_ScaleX ("Scale X", Float) = 1.0