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
@LuviKunG
LuviKunG / UnityEditorMenuExtension.cs
Last active August 7, 2025 09:36
Unity Editor Menu Tweaks for easy access to persistent folder and project assets folder.
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace LuviKunG
{
/// <summary>
/// Unity Editor Menu Extension.
/// </summary>
public static class UnityEditorMenuExtension
@yasirkula
yasirkula / ScrollViewFocusFunctions.cs
Created October 23, 2021 10:09
Focus/center Scroll View to the specified point/item in Unity
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public static class ScrollViewFocusFunctions
{
public static Vector2 CalculateFocusedScrollPosition( this ScrollRect scrollView, Vector2 focusPoint )
{
Vector2 contentSize = scrollView.content.rect.size;
Vector2 viewportSize = ( (RectTransform) scrollView.content.parent ).rect.size;
@MaZyGer
MaZyGer / EditorModeOnly
Last active October 11, 2025 03:09
The default EditorOnly of Unity Engine will only remove objects from standalone player and not in the editor. EditorModeOnly will remove also objects if you start playmode in the editor. Its really nice for things such as UI List tests, to remove the list in play mode. You can remove or change the namespace if you want. Drop it in an Editor fold…
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;
namespace Maz.Unity.EditorExtensions
{
[InitializeOnLoad]
public class EditorModeOnly
{
@guness
guness / CombinedLiveData.java
Last active May 15, 2023 14:10
LiveData merger that takes two live data inputs and a merger function. Merges two results using merger function, and returning result allowing null inputs and outputs. Input and out types are parametric. However only supports two live data inputs for now.
import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MediatorLiveData;
import androidx.lifecycle.Observer;
import java.util.function.BiFunction;
public class CombinedLiveData<T, K, S> extends MediatorLiveData<S> {
@SeanMcTex
SeanMcTex / PinToSafeArea.cs
Last active August 9, 2024 07:11
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>
@a3geek
a3geek / PoissonDiskSampling.cs
Last active September 2, 2025 09:45
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
{
@FlaShG
FlaShG / CanvasPositioningExtensions.cs
Last active August 6, 2025 00:43
A small Unity helper class to convert viewport, screen or world positions to canvas space.
using UnityEngine;
/// <summary>
/// Small helper class to convert viewport, screen or world positions to canvas space.
/// Only works with screen space canvases.
/// </summary>
/// <example>
/// <code>
/// objectOnCanvasRectTransform.anchoredPosition = specificCanvas.WorldToCanvasPoint(worldspaceTransform.position);
/// </code>
@staltz
staltz / introrx.md
Last active October 21, 2025 16:32
The introduction to Reactive Programming you've been missing
@cesarferreira
cesarferreira / AsyncTaskActivity.java
Last active September 25, 2024 03:30
Advanced Android AsyncTask Callback example
package com.cesarferreira.asynctaskcallback;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override