Skip to content

Instantly share code, notes, and snippets.

View GibsS's full-sized avatar

Emerick Gibson GibsS

View GitHub Profile
@GibsS
GibsS / RoundedRectGraphic.cs
Last active October 9, 2023 21:13
A Unity Canvas UI Graphic for a rectangle with rounded edges
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
[ExecuteInEditMode]
public class RoundRectGraphic : Graphic {
[Range(0, 200)]
public int radius;
public bool hasTop;
@GibsS
GibsS / PanAndZoom.cs
Last active March 4, 2020 21:48
A modular and easily customisable Unity MonoBehaviour for handling swipe and pinch motions on mobile.
using UnityEngine;
using System;
using System.Collections.Generic;
using UnityEngine.EventSystems;
/// <summary> A modular and easily customisable Unity MonoBehaviour for handling swipe and pinch motions on mobile. </summary>
public class PanAndZoom : MonoBehaviour {
/// <summary> Called as soon as the player touches the screen. The argument is the screen position. </summary>
public event Action<Vector2> onStartTouch;
@GibsS
GibsS / CantorPairUtility.cs
Created May 30, 2018 22:22
Simple C# class to calculate Cantor's pairing function
using System;
public static class CantorPairUtility {
public static int CantorPair(int x, int y) {
return (((x + y) * (x + y + 1)) / 2) + y;
}
public static void ReverseCantorPair(int cantor, out int x, out int y) {
var t = (int) Math.Floor((-1 + Math.Sqrt(1 + 8 * cantor)) / 2);
@GibsS
GibsS / IsPointerOverUI.cs
Created July 20, 2023 07:07
A Unity helper class to check if the player's pointer is over the UI. Useful to avoid doing world actions if the pointer is over a bit of UI. Works on desktop and mobile.
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public static class IsPointerOverUI {
public static bool Check() {
if (EventSystem.current == null) return false;
PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current);