Skip to content

Instantly share code, notes, and snippets.

View AGeorgy's full-sized avatar

George Ananchenko AGeorgy

View GitHub Profile
@yasirkula
yasirkula / GradientGraphic.cs
Last active August 7, 2025 03:28
Create 4-color gradient UI graphics in Unity
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Sprites;
using UnityEngine.UI;
#if UNITY_2017_4 || UNITY_2018_2_OR_NEWER
using UnityEngine.U2D;
#endif
using Sprites = UnityEngine.Sprites;
#if UNITY_EDITOR
@sttz
sttz / ScrollToCeneter.cs
Last active June 24, 2025 05:10
Method to center an element in a ScrollRect using Unity's new UI system
using UnityEngine;
using UnityEngine.UI;
public static class UIExtensions {
// Shared array used to receive result of RectTransform.GetWorldCorners
static Vector3[] corners = new Vector3[4];
/// <summary>
/// Transform the bounds of the current rect transform to the space of another transform.
/// </summary>
@ELGReeND
ELGReeND / TCP_Client.cs
Last active July 4, 2018 08:04
Unity TCP Client, Async, Thread, Working, Ready for creation net game logic
using System;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using UnityEngine;
using Newtonsoft.Json;
using DisruptorUnity3d;
public class TCP_Client : MonoBehaviour
{
@JohannesMP
JohannesMP / 2DLineRectIntersection.md
Last active November 20, 2024 07:09
[C#, Unity3D] An optimized solver for intersection between a Line Segment and a Rect in 2D space with spacial partitioning.

Overview

For a 2D Unity Project, I needed a really efficient way to get the intersection points between a line segment (as defined by two Vector2) and an axis-aligned Rect in 2D space, where the intersection points are returned as a parametric fraction of the length of the original line segment:

Note how when the line intersects the rect, the green line represents the portion inside the rect, and the parametric representation of the point of intersection along the line is displayed

In my use case the vast majority of lines are either completely inside or completely outside the rect, and so I needed an approach that was very efficient in cases where there is guaranteed no intersection and avoids unecessary raycasts when possible.

@JohannesMP
JohannesMP / LICENSE
Last active October 5, 2025 19:01
[Unity3D] A Reliable, user-friendly way to reference SceneAssets by script.
/*******************************************************************************
* Don't Be a Jerk: The Open Source Software License.
* Adapted from: https://github.com/evantahler/Dont-be-a-Jerk
*******************************************************************************
* _I_ am the software author - JohannesMP on Github.
* _You_ are the user of this software. You might be a _we_, and that's OK!
*
* This is free, open source software. I will never charge you to use,
* license, or obtain this software. Doing so would make me a jerk.
*
@JohannesMP
JohannesMP / UIBlur.shader
Last active July 24, 2025 07:01
UI.Image Blur Shader with layering and masking support
Shader "Custom/UIBlur"
{
Properties
{
[Toggle(IS_BLUR_ALPHA_MASKED)] _IsAlphaMasked("Image Alpha Masks Blur", Float) = 1
[Toggle(IS_SPRITE_VISIBLE)] _IsSpriteVisible("Show Image", Float) = 1
// Internally enforced by MAX_RADIUS
_Radius("Blur Radius", Range(0, 64)) = 1
@LotteMakesStuff
LotteMakesStuff / AutohookAttribute.cs
Last active September 29, 2025 17:12
[Autohook] property drawer for unity - Add this [Autohook] attribute to a property to and the inspector will automagically hook up a valid reference for you if it can find a component attached to the same game object that matches the field you put it on. You can watch a demo of this in action here https://youtu.be/faVt09NGzws <3
// NOTE DONT put in an editor folder!
using UnityEngine;
public class AutohookAttribute : PropertyAttribute
{
}
@yasirkula
yasirkula / SlicedFilledImage.cs
Last active November 13, 2025 12:40
Combining UI Image's Sliced+Filled features together in Unity
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
#if UNITY_2017_4 || UNITY_2018_2_OR_NEWER
using UnityEngine.U2D;
#endif
using Sprites = UnityEngine.Sprites;
#if UNITY_EDITOR
@unitycoder
unitycoder / DriftingWaves.shader
Last active June 4, 2025 11:52
Drifting Waves Shader
// idea from https://twitter.com/akivaw/status/1226681850564956160
// blog post https://unitycoder.com/blog/2020/03/01/waves-shader/
Shader "UnityLibrary/Mesh/DriftingWaves"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_FoamTex ("Foam", 2D) = "white" {}