Skip to content

Instantly share code, notes, and snippets.

View enpiech's full-sized avatar

Huy Phan enpiech

  • Ho Chi Minh City, Vietnam
View GitHub Profile
@enpiech
enpiech / SimulatingUnityNull.cs
Created June 12, 2023 18:21 — forked from atcarter714/SimulatingUnityNull.cs
Clearing up the confusion about how null-ness of Unity Objects works with a very simple simulation of it!
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Here we simulate a managed object using native memory resources which has the same
// behavior as a Unity Object with "null-ness" and checks. It demonstrates why if(obj)
// is usually how you should be doing your checks ...
internal class Program
{
private static void Main( string[] args )
@enpiech
enpiech / MonoBehaviourSingleton.cs
Created April 2, 2023 12:42 — forked from rickyah/MonoBehaviourSingleton.cs
MonoBehaviour Singleton
using System;
using UnityEngine;
/// <summary>
/// This is a generic Singleton implementation for Monobehaviours.
/// Create a derived class where the type T is the script you want to "Singletonize"
/// Upon loading it will call DontDestroyOnLoad on the gameobject where this script is contained
/// so it persists upon scene changes.
/// </summary>
/// <remarks>
@enpiech
enpiech / PoissonDiskSampling.cs
Created December 16, 2022 04:31 — forked from a3geek/PoissonDiskSampling.cs
Fast Poisson Disk Sampling for Unity.
using System.Collections.Generic;
using UnityEngine;
namespace Gists
{
// The algorithm is from the "Fast Poisson Disk Sampling in Arbitrary Dimensions" paper by Robert Bridson.
// https://www.cs.ubc.ca/~rbridson/docs/bridson-siggraph07-poissondisk.pdf
public static class FastPoissonDiskSampling
{
!#()+,-.0123456789:;>?@aAàÀảẢãÃáÁạẠăĂằẰẳẲẵẴắẮặẶâÂầẦẩẨẫẪấẤậẬbBcCdDđĐeEèÈẻẺẽẼéÉẹẸêÊềỀểỂễỄếẾệỆ fFgGhHiIìÌỉỈĩĨíÍịỊjJkKlLmMnNoOòÒỏỎõÕóÓọỌôÔồỒổỔỗỖốỐộỘơƠờỜởỞỡỠớỚợỢpPqQrRsStTu UùÙủỦũŨúÚụỤưƯừỪửỬữỮứỨựỰvVwWxXyYỳỲỷỶỹỸýÝỵỴzZ—‘’“”…
@enpiech
enpiech / PinToSafeArea.cs
Created August 12, 2022 03:15 — forked from SeanMcTex/PinToSafeArea.cs
Restrict Unity UI to an iPhone X or other Mobile Device's Safe Area
using UnityEngine;
/// <summary>
/// Resizes a UI element with a RectTransform to respect the safe areas of the current device.
/// This is particularly useful on an iPhone X, where we have to avoid the notch and the screen
/// corners.
///
/// The easiest way to use it is to create a root Canvas object, attach this script to a game object called "SafeAreaContainer"
/// that is the child of the root canvas, and then layout the UI elements within the SafeAreaContainer, which
/// will adjust size appropriately for the current device./// </summary>
@enpiech
enpiech / sourceTree_device_not_configured.txt
Created October 26, 2021 07:47 — forked from RockinPaul/sourceTree_device_not_configured.txt
SourceTree: Device not configured (on MacOS)
In console:
git config credential.helper
You will see: osxkeychain
git config credential.helper sourcetree
Then if you perform git config credential.helper again
You will see: sourcetree
@enpiech
enpiech / introrx.md
Created March 5, 2020 06:38 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing